forked from oVirt/go-ovirt-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_network.go
85 lines (72 loc) · 2.11 KB
/
client_network.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package ovirtclient
import (
ovirtsdk4 "github.com/ovirt/go-ovirt"
)
//go:generate go run scripts/rest.go -i "Network" -n "network"
// NetworkClient describes the functions related to oVirt networks.
//
// See https://www.ovirt.org/documentation/administration_guide/#chap-Logical_Networks for details.
type NetworkClient interface {
// GetNetwork returns a single network based on its ID.
GetNetwork(id string, retries ...RetryStrategy) (Network, error)
// ListNetworks returns all networks on the oVirt engine.
ListNetworks(retries ...RetryStrategy) ([]Network, error)
}
// NetworkData is the core of Network, providing only the data access functions, but not the client
// functions.
type NetworkData interface {
// ID returns the auto-generated identifier for this network.
ID() string
// Name returns the user-give nname for this network.
Name() string
// DatacenterID is the identifier of the datacenter object.
DatacenterID() string
}
// Network is the interface defining the fields for networks.
type Network interface {
NetworkData
// Datacenter fetches the datacenter associated with this network. This is a network call and may be slow.
Datacenter(retries ...RetryStrategy) (Datacenter, error)
}
func convertSDKNetwork(sdkObject *ovirtsdk4.Network, client *oVirtClient) (Network, error) {
id, ok := sdkObject.Id()
if !ok {
return nil, newFieldNotFound("network", "id")
}
name, ok := sdkObject.Name()
if !ok {
return nil, newFieldNotFound("network", name)
}
dc, ok := sdkObject.DataCenter()
if !ok {
return nil, newFieldNotFound("network", "datacenter")
}
dcID, ok := dc.Id()
if !ok {
return nil, newFieldNotFound("datacenter on network", "ID")
}
return &network{
client: client,
id: id,
name: name,
dcID: dcID,
}, nil
}
type network struct {
client Client
id string
name string
dcID string
}
func (n network) ID() string {
return n.id
}
func (n network) Name() string {
return n.name
}
func (n network) DatacenterID() string {
return n.dcID
}
func (n network) Datacenter(retries ...RetryStrategy) (Datacenter, error) {
return n.client.GetDatacenter(n.dcID, retries...)
}