-
Notifications
You must be signed in to change notification settings - Fork 21
/
disk_attachment_list.go
56 lines (50 loc) · 1.32 KB
/
disk_attachment_list.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
package ovirtclient
import (
"fmt"
)
//nolint:dupl
func (o *oVirtClient) ListDiskAttachments(
vmid VMID,
retries ...RetryStrategy,
) (result []DiskAttachment, err error) {
retries = defaultRetries(retries, defaultReadTimeouts(o))
result = []DiskAttachment{}
err = retry(
fmt.Sprintf("listing disk attachments on VM %s", vmid),
o.logger,
retries,
func() error {
response, e := o.conn.SystemService().VmsService().VmService(string(vmid)).DiskAttachmentsService().List().Send()
if e != nil {
return e
}
sdkObjects, ok := response.Attachments()
if !ok {
return nil
}
result = make([]DiskAttachment, len(sdkObjects.Slice()))
for i, sdkObject := range sdkObjects.Slice() {
result[i], e = convertSDKDiskAttachment(sdkObject, o)
if e != nil {
return wrap(e, EBug, "failed to convert disk during listing item #%d", i)
}
}
return nil
})
return
}
func (m *mockClient) ListDiskAttachments(vmID VMID, _ ...RetryStrategy) ([]DiskAttachment, error) {
m.lock.Lock()
defer m.lock.Unlock()
diskAttachments, ok := m.vmDiskAttachmentsByVM[vmID]
if !ok {
return nil, newError(ENotFound, "VM %s doesn't exist", vmID)
}
result := make([]DiskAttachment, len(diskAttachments))
i := 0
for _, attachment := range diskAttachments {
result[i] = attachment
i++
}
return result, nil
}