forked from oVirt/go-ovirt-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatacenter_list_clusters.go
55 lines (50 loc) · 1.3 KB
/
datacenter_list_clusters.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
package ovirtclient
import (
"fmt"
)
func (o *oVirtClient) ListDatacenterClusters(id DatacenterID, retries ...RetryStrategy) (result []Cluster, err error) {
retries = defaultRetries(retries, defaultReadTimeouts(o))
result = []Cluster{}
err = retry(
fmt.Sprintf("listing datacenters %s clusters", id),
o.logger,
retries,
func() error {
response, e := o.conn.
SystemService().
DataCentersService().
DataCenterService(string(id)).
ClustersService().
List().
Send()
if e != nil {
return e
}
sdkObjects, ok := response.Clusters()
if !ok {
return nil
}
result = make([]Cluster, len(sdkObjects.Slice()))
for i, sdkObject := range sdkObjects.Slice() {
result[i], e = convertSDKCluster(sdkObject, o)
if e != nil {
return wrap(e, EBug, "failed to convert cluster during listing item #%d", i)
}
}
return nil
})
return result, err
}
func (m *mockClient) ListDatacenterClusters(id DatacenterID, _ ...RetryStrategy) ([]Cluster, error) {
m.lock.Lock()
defer m.lock.Unlock()
dc, ok := m.dataCenters[id]
if !ok {
return nil, newError(ENotFound, "datacenter with ID %s not found", id)
}
clusters := make([]Cluster, len(dc.clusters))
for i, clusterID := range dc.clusters {
clusters[i] = m.clusters[clusterID]
}
return clusters, nil
}