forked from oVirt/go-ovirt-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisk_attachment_get.go
62 lines (56 loc) · 1.37 KB
/
disk_attachment_get.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package ovirtclient
import (
"fmt"
)
func (o *oVirtClient) GetDiskAttachment(
vmid VMID,
id DiskAttachmentID,
retries ...RetryStrategy,
) (result DiskAttachment, err error) {
retries = defaultRetries(retries, defaultReadTimeouts(o))
err = retry(
fmt.Sprintf("getting disk attachment %s on VM %s", id, vmid),
o.logger,
retries,
func() error {
response, err := o.conn.
SystemService().
VmsService().
VmService(string(vmid)).
DiskAttachmentsService().
AttachmentService(string(id)).
Get().
Send()
if err != nil {
return err
}
sdkObject, ok := response.Attachment()
if !ok {
return newFieldNotFound("disk attachment response", "attachment")
}
result, err = convertSDKDiskAttachment(sdkObject, o)
if err != nil {
return wrap(
err,
EBug,
"failed to convert disk attachment %s",
id,
)
}
return nil
})
return result, err
}
func (m *mockClient) GetDiskAttachment(vmID VMID, diskAttachmentID DiskAttachmentID, _ ...RetryStrategy) (DiskAttachment, error) {
m.lock.Lock()
defer m.lock.Unlock()
vm, ok := m.vmDiskAttachmentsByVM[vmID]
if !ok {
return nil, newError(ENotFound, "VM %s doesn't exist", vmID)
}
diskAttachment, ok := vm[diskAttachmentID]
if !ok {
return nil, newError(ENotFound, "disk attachment %s not found on VM %s", diskAttachmentID, vmID)
}
return diskAttachment, nil
}