-
Notifications
You must be signed in to change notification settings - Fork 21
/
affinitygroup_list.go
51 lines (47 loc) · 1.26 KB
/
affinitygroup_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
package ovirtclient
import "fmt"
//nolint:dupl
func (o *oVirtClient) ListAffinityGroups(
clusterID ClusterID,
retries ...RetryStrategy,
) (result []AffinityGroup, err error) {
retries = defaultRetries(retries, defaultReadTimeouts(o))
result = []AffinityGroup{}
err = retry(
fmt.Sprintf("listing affinity groups in cluster %s", clusterID),
o.logger,
retries,
func() error {
response, e := o.conn.SystemService().ClustersService().ClusterService(string(clusterID)).AffinityGroupsService().List().Send()
if e != nil {
return e
}
sdkObjects, ok := response.Groups()
if !ok {
return nil
}
result = make([]AffinityGroup, len(sdkObjects.Slice()))
for i, sdkObject := range sdkObjects.Slice() {
result[i], e = convertSDKAffinityGroup(sdkObject, o)
if e != nil {
return wrap(e, EBug, "failed to convert affinity group during listing item #%d", i)
}
}
return nil
})
return
}
func (m *mockClient) ListAffinityGroups(
clusterID ClusterID,
_ ...RetryStrategy,
) ([]AffinityGroup, error) {
m.lock.Lock()
defer m.lock.Unlock()
result := make([]AffinityGroup, len(m.affinityGroups[clusterID]))
i := 0
for _, affinityGroup := range m.affinityGroups[clusterID] {
result[i] = affinityGroup
i++
}
return result, nil
}