mirror of
https://github.com/ScottESanDiego/virtwold.git
synced 2025-04-14 08:25:51 +00:00
Refactor state handing to always try and start the VM, and just pretty-print output based on state
This commit is contained in:
parent
7f1162052a
commit
1b5416f2ca
15
virtwold.go
15
virtwold.go
@ -111,26 +111,23 @@ func WakeVirtualMachine(mac string) bool {
|
|||||||
log.Fatalf("failed to check domain state: %v", err)
|
log.Fatalf("failed to check domain state: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print an informative message about the state of things
|
||||||
switch state {
|
switch state {
|
||||||
case libvirt.DOMAIN_SHUTDOWN, libvirt.DOMAIN_SHUTOFF, libvirt.DOMAIN_CRASHED:
|
case libvirt.DOMAIN_SHUTDOWN, libvirt.DOMAIN_SHUTOFF, libvirt.DOMAIN_CRASHED:
|
||||||
fmt.Printf("Waking system: %s at MAC %s\n", name, mac)
|
fmt.Printf("Waking system: %s at MAC %s\n", name, mac)
|
||||||
if err := domain.Create(); err != nil {
|
|
||||||
log.Fatalf("Failed to start domain: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
case libvirt.DOMAIN_PMSUSPENDED:
|
case libvirt.DOMAIN_PMSUSPENDED:
|
||||||
fmt.Printf("Unsuspending system: %s at MAC %s\n", name, mac)
|
fmt.Printf("Unsuspending system: %s at MAC %s\n", name, mac)
|
||||||
if err := domain.Create(); err != nil {
|
|
||||||
log.Fatalf("Failed to unsuspend domain: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
case libvirt.DOMAIN_PAUSED:
|
case libvirt.DOMAIN_PAUSED:
|
||||||
fmt.Printf("Resuming system: %s at MAC %s\n", name, mac)
|
fmt.Printf("Resuming system: %s at MAC %s\n", name, mac)
|
||||||
if err := domain.Create(); err != nil {
|
|
||||||
log.Fatalf("Failed to resume domain: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try and start the VM
|
||||||
|
err = domain.Create()
|
||||||
|
if err != nil {
|
||||||
fmt.Printf("System is already running or in a state that cannot be woken from. State: %d\n", state)
|
fmt.Printf("System is already running or in a state that cannot be woken from. State: %d\n", state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user