-
Notifications
You must be signed in to change notification settings - Fork 20
/
storagedomain_get_disk.go
54 lines (51 loc) · 1.35 KB
/
storagedomain_get_disk.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
package ovirtclient
import (
"fmt"
)
func (o *oVirtClient) GetDiskFromStorageDomain(id StorageDomainID, diskID DiskID, retries ...RetryStrategy) (result Disk, err error) {
retries = defaultRetries(retries, defaultReadTimeouts(o))
err = retry(
fmt.Sprintf("getting disk %s from storage domain %s", diskID, id),
o.logger,
retries,
func() error {
response, err := o.conn.SystemService().StorageDomainsService().
StorageDomainService(string(id)).DisksService().DiskService(string(diskID)).Get().Send()
if err != nil {
return err
}
sdkObject, ok := response.Disk()
if !ok {
return newError(
ENotFound,
"disk %s not found on storage domain ID %s",
diskID,
id,
)
}
result, err = convertSDKDisk(sdkObject, o)
if err != nil {
return wrap(
err,
EBug,
"failed to convert disk %s",
diskID,
)
}
return nil
})
return result, err
}
func (m *mockClient) GetDiskFromStorageDomain(id StorageDomainID, diskID DiskID, _ ...RetryStrategy) (Disk, error) {
m.lock.Lock()
defer m.lock.Unlock()
if disk, ok := m.disks[diskID]; ok {
for _, domain := range disk.storageDomainIDs {
if domain == id {
return disk, nil
}
}
return nil, newError(ENotFound, "disk %s doesnt exist in storage domain %s", diskID, id)
}
return nil, newError(ENotFound, "disk %s doesnt exists", diskID)
}