forked from oVirt/go-ovirt-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisk_attachment_remove.go
45 lines (38 loc) · 1.1 KB
/
disk_attachment_remove.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
package ovirtclient
import (
"fmt"
)
func (o *oVirtClient) RemoveDiskAttachment(vmID VMID, diskAttachmentID DiskAttachmentID, retries ...RetryStrategy) error {
retries = defaultRetries(retries, defaultWriteTimeouts(o))
return retry(
fmt.Sprintf("removing disk attachment %s on VM %s", diskAttachmentID, vmID),
o.logger,
retries,
func() error {
_, err := o.conn.
SystemService().
VmsService().
VmService(string(vmID)).
DiskAttachmentsService().
AttachmentService(string(diskAttachmentID)).
Remove().
Send()
return err
},
)
}
func (m *mockClient) RemoveDiskAttachment(vmID VMID, diskAttachmentID DiskAttachmentID, _ ...RetryStrategy) error {
m.lock.Lock()
defer m.lock.Unlock()
vm, ok := m.vmDiskAttachmentsByVM[vmID]
if !ok {
return newError(ENotFound, "VM %s doesn't exist", vmID)
}
diskAttachment, ok := vm[diskAttachmentID]
if !ok {
return newError(ENotFound, "Disk attachment %s not found on VM %s", diskAttachmentID, vmID)
}
delete(m.vmDiskAttachmentsByDisk, diskAttachment.DiskID())
delete(m.vmDiskAttachmentsByVM[vmID], diskAttachmentID)
return nil
}