From 7a31443eea6e9838e7132a7c962ca8e2ae477fd5 Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Wed, 3 Jan 2024 17:01:07 +0400 Subject: [PATCH] tart create --linux: allow scaling VM down to 1 CPU and 256 MiB --- Sources/tart/VM.swift | 2 +- Sources/tart/VMConfig.swift | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Sources/tart/VM.swift b/Sources/tart/VM.swift index 149bb0c..30b95c0 100644 --- a/Sources/tart/VM.swift +++ b/Sources/tart/VM.swift @@ -223,7 +223,7 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject { try vmDir.resizeDisk(diskSizeGB) // Create config - let config = VMConfig(platform: Linux(), cpuCountMin: 4, memorySizeMin: 4096 * 1024 * 1024) + let config = VMConfig(platform: Linux(), cpuCountMin: 1, cpuCount: 4, memorySizeMin: 256 * 1024 * 1024, memorySize: 4096 * 1024 * 1024) try config.save(toURL: vmDir.configURL) return try VM(vmDir: vmDir) diff --git a/Sources/tart/VMConfig.swift b/Sources/tart/VMConfig.swift index 0ff2480..86a069f 100644 --- a/Sources/tart/VMConfig.swift +++ b/Sources/tart/VMConfig.swift @@ -58,15 +58,29 @@ struct VMConfig: Codable { cpuCountMin: Int, memorySizeMin: UInt64, macAddress: VZMACAddress = VZMACAddress.randomLocallyAdministered() + ) { + self.init(platform: platform, + cpuCountMin: cpuCountMin, cpuCount: cpuCountMin, + memorySizeMin: memorySizeMin, memorySize: memorySizeMin, + macAddress: macAddress) + } + + init( + platform: Platform, + cpuCountMin: Int, + cpuCount: Int, + memorySizeMin: UInt64, + memorySize: UInt64, + macAddress: VZMACAddress = VZMACAddress.randomLocallyAdministered() ) { self.os = platform.os() self.arch = CurrentArchitecture() self.platform = platform self.macAddress = macAddress self.cpuCountMin = cpuCountMin + self.cpuCount = cpuCount self.memorySizeMin = memorySizeMin - cpuCount = cpuCountMin - memorySize = memorySizeMin + self.memorySize = memorySize } init(fromJSON: Data) throws {