diff --git a/Sources/tart/Commands/Set.swift b/Sources/tart/Commands/Set.swift index bfaceee4..33bd31af 100644 --- a/Sources/tart/Commands/Set.swift +++ b/Sources/tart/Commands/Set.swift @@ -1,5 +1,6 @@ import ArgumentParser import Foundation +import Virtualization struct Set: AsyncParsableCommand { static var configuration = CommandConfiguration(commandName: "set", abstract: "Modify VM's configuration") @@ -16,6 +17,14 @@ struct Set: AsyncParsableCommand { @Option(help: "VM display resolution in a format of x. For example, 1200x800") var display: VMDisplayConfig? + @Flag(help: ArgumentHelp("Generate a new random MAC address for the VM.")) + var randomMAC: Bool = false + + #if arch(arm64) + @Flag(help: ArgumentHelp("Generate a new random serial number for the macOS VM.")) + #endif + var randomSerial: Bool = false + @Option(help: ArgumentHelp("Resize the VMs disk to the specified size in GB (note that the disk size can only be increased to avoid losing data)", discussion: """ Disk resizing works on most cloud-ready Linux distributions out-of-the box (e.g. Ubuntu Cloud Images @@ -51,6 +60,17 @@ struct Set: AsyncParsableCommand { } } + if randomMAC { + vmConfig.macAddress = VZMACAddress.randomLocallyAdministered() + } + + #if arch(arm64) + if randomSerial { + let oldPlatform = vmConfig.platform as! Darwin + vmConfig.platform = Darwin(ecid: VZMacMachineIdentifier(), hardwareModel: oldPlatform.hardwareModel) + } + #endif + try vmConfig.save(toURL: vmDir.configURL) if diskSize != nil {