-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathvm_stop.go
46 lines (43 loc) · 1.12 KB
/
vm_stop.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
41
42
43
44
45
46
package ovirtclient
import (
"fmt"
"net"
"time"
)
func (o *oVirtClient) StopVM(id VMID, force bool, retries ...RetryStrategy) (err error) {
retries = defaultRetries(retries, defaultWriteTimeouts(o))
err = retry(
fmt.Sprintf("stopping VM %s", id),
o.logger,
retries,
func() error {
_, err := o.conn.SystemService().VmsService().VmService(string(id)).Stop().Force(force).Send()
return err
})
return
}
func (m *mockClient) StopVM(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.")
}
m.vmIPs[id] = map[string][]net.IP{}
if item.status != VMStatusDown {
item.status = VMStatusPoweringDown
go func() {
time.Sleep(2 * time.Second)
m.lock.Lock()
defer m.lock.Unlock()
if item.status != VMStatusPoweringDown {
return
}
item.status = VMStatusDown
item.hostID = nil
}()
}
return nil
}
return newError(ENotFound, "vm with ID %s not found", id)
}