-
Notifications
You must be signed in to change notification settings - Fork 21
/
affinitygroup_get.go
65 lines (58 loc) · 1.64 KB
/
affinitygroup_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
63
64
65
package ovirtclient
import (
"fmt"
)
func (o *oVirtClient) GetAffinityGroup(clusterID ClusterID, id AffinityGroupID, retries ...RetryStrategy) (result AffinityGroup, err error) {
retries = defaultRetries(retries, defaultReadTimeouts(o))
err = retry(
fmt.Sprintf("getting affinity group %s", id),
o.logger,
retries,
func() error {
response, err := o.conn.SystemService().ClustersService().ClusterService(string(clusterID)).AffinityGroupsService().GroupService(string(id)).Get().Send()
if err != nil {
return err
}
sdkObject, ok := response.Group()
if !ok {
return newError(
ENotFound,
"no affinity group returned when getting affinity group ID %s in cluster ID %s",
id,
clusterID,
)
}
result, err = convertSDKAffinityGroup(sdkObject, o)
if err != nil {
return wrap(
err,
EBug,
"failed to convert affinity group %s",
id,
)
}
return nil
})
return result, err
}
func (m *mockClient) GetAffinityGroup(clusterID ClusterID, id AffinityGroupID, retries ...RetryStrategy) (result AffinityGroup, err error) {
retries = defaultRetries(retries, defaultWriteTimeouts(m))
err = retry(
fmt.Sprintf("getting affinity group %s from cluster %s", id, clusterID),
m.logger,
retries,
func() error {
m.lock.Lock()
defer m.lock.Unlock()
clusterAffinityGroups, ok := m.affinityGroups[clusterID]
if !ok {
return newError(ENotFound, "Cluster with ID %s not found", clusterID)
}
result, ok = clusterAffinityGroups[id]
if !ok {
return newError(ENotFound, "Affinity group with ID %s not found in cluster %s", id, clusterID)
}
return nil
})
return
}