-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathvm_shutdown.go
40 lines (37 loc) · 1.01 KB
/
vm_shutdown.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package ovirtclient
import (
"fmt"
"time"
)
func (o *oVirtClient) ShutdownVM(id VMID, force bool, retries ...RetryStrategy) (err error) {
retries = defaultRetries(retries, defaultWriteTimeouts(o))
err = retry(
fmt.Sprintf("shutting down VM %s", id),
o.logger,
retries,
func() error {
_, err := o.conn.SystemService().VmsService().VmService(string(id)).Shutdown().Force(force).Send()
return err
})
return
}
func (m *mockClient) ShutdownVM(id VMID, force bool, _ ...RetryStrategy) error {
m.lock.Lock()
defer m.lock.Unlock()
if item, ok := m.vms[id]; ok {
if (item.status == VMStatusSavingState || item.status == VMStatusRestoringState) && !force {
return newError(EConflict, "VM is currently backing up or restoring.")
}
if item.status != VMStatusDown {
item.status = VMStatusPoweringDown
go func() {
time.Sleep(2 * time.Second)
m.lock.Lock()
defer m.lock.Unlock()
item.status = VMStatusDown
}()
}
return nil
}
return newError(ENotFound, "vm with ID %s not found", id)
}