tart ip: wait for the VM to start if --wait was set (#467)

This commit is contained in:
Nikolay Edigaryev 2023-04-10 14:37:00 +04:00 committed by GitHub
parent c749bdeaf1
commit b03408f856
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 8 deletions

View File

@ -34,16 +34,20 @@ struct IP: AsyncParsableCommand {
let vmConfig = try VMConfig.init(fromURL: vmDir.configURL)
let vmMACAddress = MACAddress(fromString: vmConfig.macAddress.string)!
if try !vmDir.running() {
throw RuntimeError.NoIPAddressFound("no IP address found, is your VM running?")
guard let ip = try await IP.resolveIP(vmMACAddress, resolutionStrategy: resolver, secondsToWait: wait) else {
var message = "no IP address found"
if try !vmDir.running() {
message += ", is your VM running?"
}
if (vmConfig.os == .linux && resolver == .arp) {
message += " (not all Linux distributions are compatible with the ARP resolver)"
}
throw RuntimeError.NoIPAddressFound(message)
}
guard let ip = try await IP.resolveIP(vmMACAddress, resolutionStrategy: resolver, secondsToWait: wait) else {
if (vmConfig.os == .linux && resolver == .arp) {
throw RuntimeError.NoIPAddressFound("no IP address found, not all Linux distributions are compatible with ARP resolver")
}
throw RuntimeError.NoIPAddressFound("no IP address found")
}
print(ip)
}