mirror of
https://github.com/cirruslabs/tart.git
synced 2026-10-17 11:25:33 +02:00
Support getting the MAC address, and setting an arbitrary MAC address (#1327)
* tart get: Report MAC address * tart set: Support setting an arbitrary MAC address
This commit is contained in:
@@ -9,6 +9,7 @@ fileprivate struct VMInfo: Encodable {
|
||||
let DiskFormat: String
|
||||
let Size: HumanReadableByteCount
|
||||
let Display: String
|
||||
let MACAddress: String
|
||||
let Running: Bool
|
||||
let State: String
|
||||
}
|
||||
@@ -38,6 +39,7 @@ struct Get: AsyncParsableCommand {
|
||||
String(format: "%.3f", Float($0) / 1000 / 1000 / 1000)
|
||||
},
|
||||
Display: vmConfig.display.description,
|
||||
MACAddress: vmConfig.macAddress.string,
|
||||
Running: try vmDir.running(),
|
||||
State: try vmDir.state().rawValue
|
||||
)
|
||||
|
||||
@@ -20,6 +20,9 @@ struct Set: AsyncParsableCommand {
|
||||
@Flag(inversion: .prefixedNo, help: ArgumentHelp("Whether to automatically reconfigure the VM's display to fit the window"))
|
||||
var displayRefit: Bool? = nil
|
||||
|
||||
@Option(help: ArgumentHelp("MAC address to use."))
|
||||
var mac: String?
|
||||
|
||||
@Flag(help: ArgumentHelp("Generate a new random MAC address for the VM."))
|
||||
var randomMAC: Bool = false
|
||||
|
||||
@@ -47,6 +50,10 @@ struct Set: AsyncParsableCommand {
|
||||
throw ValidationError("--disk is not supported for VMs with a stacked disk")
|
||||
}
|
||||
|
||||
if randomMAC && mac != nil {
|
||||
throw ValidationError("--random-mac and --mac are mutually exclusive")
|
||||
}
|
||||
|
||||
var vmConfig = try VMConfig(fromURL: vmDir.configURL)
|
||||
|
||||
if let cpu = cpu {
|
||||
@@ -71,6 +78,14 @@ struct Set: AsyncParsableCommand {
|
||||
vmConfig.displayRefit = displayRefit
|
||||
}
|
||||
|
||||
if let mac = mac {
|
||||
if let macAddress = VZMACAddress.init(string: mac), macAddress.isUnicastAddress {
|
||||
vmConfig.macAddress = macAddress
|
||||
} else {
|
||||
throw ValidationError("'\(mac)' is not a valid unicast MAC address")
|
||||
}
|
||||
}
|
||||
|
||||
if randomMAC {
|
||||
vmConfig.macAddress = VZMACAddress.randomLocallyAdministered()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user