-
Notifications
You must be signed in to change notification settings - Fork 20
/
disk_list_by_alias.go
46 lines (43 loc) · 1.1 KB
/
disk_list_by_alias.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"
)
func (o *oVirtClient) ListDisksByAlias(alias string, retries ...RetryStrategy) (result []Disk, err error) {
retries = defaultRetries(retries, defaultReadTimeouts(o))
result = []Disk{}
err = retry(
fmt.Sprintf("listing disk by alias %s", alias),
o.logger,
retries,
func() error {
searchString := fmt.Sprintf("name=%s", alias)
response, e := o.conn.SystemService().DisksService().List().Search(searchString).Send()
if e != nil {
return e
}
sdkObjects, ok := response.Disks()
if !ok {
return nil
}
result = make([]Disk, len(sdkObjects.Slice()))
for i, sdkObject := range sdkObjects.Slice() {
result[i], e = convertSDKDisk(sdkObject, o)
if e != nil {
return wrap(e, EBug, "failed to convert disk during listing item #%d", i)
}
}
return nil
})
return
}
func (m *mockClient) ListDisksByAlias(alias string, _ ...RetryStrategy) ([]Disk, error) {
m.lock.Lock()
defer m.lock.Unlock()
result := make([]Disk, 0)
for _, d := range m.disks {
if d.alias == alias {
result = append(result, d)
}
}
return result, nil
}