From 1a267d4a39c322ede1d54f1adfa5cd43256b6b60 Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Wed, 3 Jan 2024 19:48:13 +0400 Subject: [PATCH] tart create --linux: allow scaling VM down to 1 CPU and 256 MiB (#693) * tart create --linux: allow scaling VM down to 1 CPU and 256 MiB * Revert "tart create --linux: allow scaling VM down to 1 CPU and 256 MiB" This reverts commit 7a31443eea6e9838e7132a7c962ca8e2ae477fd5. * Check minimum CPU and memory sizes in "tart set" --- Sources/tart/VMConfig.swift | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Sources/tart/VMConfig.swift b/Sources/tart/VMConfig.swift index 0ff2480..080e7fc 100644 --- a/Sources/tart/VMConfig.swift +++ b/Sources/tart/VMConfig.swift @@ -132,20 +132,30 @@ struct VMConfig: Codable { } mutating func setCPU(cpuCount: Int) throws { - if cpuCount < cpuCountMin { + if os == .darwin && cpuCount < cpuCountMin { throw LessThanMinimalResourcesError("VM should have \(cpuCountMin) CPU cores" + " at minimum (requested \(cpuCount))") } + if cpuCount < VZVirtualMachineConfiguration.minimumAllowedCPUCount { + throw LessThanMinimalResourcesError("VM should have \(VZVirtualMachineConfiguration.minimumAllowedCPUCount) CPU cores" + + " at minimum (requested \(cpuCount))") + } + self.cpuCount = cpuCount } mutating func setMemory(memorySize: UInt64) throws { - if memorySize < memorySizeMin { + if os == .darwin && memorySize < memorySizeMin { throw LessThanMinimalResourcesError("VM should have \(memorySizeMin) bytes" + " of memory at minimum (requested \(memorySize))") } + if memorySize < VZVirtualMachineConfiguration.minimumAllowedMemorySize { + throw LessThanMinimalResourcesError("VM should have \(VZVirtualMachineConfiguration.minimumAllowedMemorySize) bytes" + + " of memory at minimum (requested \(memorySize))") + } + self.memorySize = memorySize } }