mirror of https://github.com/cirruslabs/tart.git
tart run: provide a hint with names of other running VMs (#900)
When VM limit gets exceeded.
This commit is contained in:
parent
7046886713
commit
3da91e6518
|
|
@ -346,7 +346,35 @@ struct Run: AsyncParsableCommand {
|
|||
}
|
||||
#endif
|
||||
|
||||
try await vm!.start(recovery: recovery, resume: resume)
|
||||
do {
|
||||
try await vm!.start(recovery: recovery, resume: resume)
|
||||
} catch let error as VZError {
|
||||
if error.code == .virtualMachineLimitExceeded {
|
||||
var hint = ""
|
||||
|
||||
do {
|
||||
let runningVMs: [String] = try localStorage.list().compactMap { (name, vmDir) in
|
||||
if try !vmDir.running() {
|
||||
return nil
|
||||
}
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
if !runningVMs.isEmpty {
|
||||
let runningVMsJoined = runningVMs.joined(separator: ", ")
|
||||
|
||||
hint = " (other running VMs: \(runningVMsJoined))"
|
||||
}
|
||||
} catch {
|
||||
// we can't provide any hint
|
||||
}
|
||||
|
||||
throw RuntimeError.VirtualMachineLimitExceeded(hint)
|
||||
}
|
||||
|
||||
throw error
|
||||
}
|
||||
|
||||
if let vncImpl = vncImpl {
|
||||
let vncURL = try await vncImpl.waitForURL(netBridged: !netBridged.isEmpty)
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ enum RuntimeError : Error {
|
|||
case OCIUnsupportedDiskFormat(_ format: String)
|
||||
case SuspendFailed(_ message: String)
|
||||
case PullFailed(_ message: String)
|
||||
case VirtualMachineLimitExceeded(_ hint: String)
|
||||
}
|
||||
|
||||
protocol HasExitCode {
|
||||
|
|
@ -128,6 +129,8 @@ extension RuntimeError : CustomStringConvertible {
|
|||
return "Failed to suspend the VM: \(message)"
|
||||
case .PullFailed(let message):
|
||||
return message
|
||||
case .VirtualMachineLimitExceeded(let hint):
|
||||
return "The number of VMs exceeds the system limit\(hint)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue