-
Notifications
You must be signed in to change notification settings - Fork 50
/
nodes_network.go
79 lines (65 loc) · 1.68 KB
/
nodes_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
package proxmox
import (
"context"
"fmt"
)
func (n *Node) NewNetwork(ctx context.Context, network *NodeNetwork) (task *Task, err error) {
err = n.client.Post(ctx, fmt.Sprintf("/nodes/%s/network", n.Name), network, network)
if nil != err {
return
}
network.client = n.client
network.Node = n.Name
network.NodeAPI = n
return n.NetworkReload(ctx)
}
func (n *Node) Network(ctx context.Context, iface string) (network *NodeNetwork, err error) {
err = n.client.Get(ctx, fmt.Sprintf("/nodes/%s/network/%s", n.Name, iface), &network)
if err != nil {
return
}
if nil != network {
network.client = n.client
network.Node = n.Name
network.NodeAPI = n
network.Iface = iface
}
return
}
func (n *Node) Networks(ctx context.Context) (networks NodeNetworks, err error) {
err = n.client.Get(ctx, fmt.Sprintf("/nodes/%s/network", n.Name), &networks)
if err != nil {
return nil, err
}
for _, v := range networks {
v.client = n.client
v.Node = n.Name
v.NodeAPI = n
}
return
}
func (n *Node) NetworkReload(ctx context.Context) (*Task, error) {
var upid UPID
err := n.client.Put(ctx, fmt.Sprintf("/nodes/%s/network", n.Name), nil, &upid)
if err != nil {
return nil, err
}
return NewTask(upid, n.client), nil
}
func (nw *NodeNetwork) Update(ctx context.Context) error {
if nw.Iface == "" {
return nil
}
return nw.client.Put(ctx, fmt.Sprintf("/nodes/%s/network/%s", nw.Node, nw.Iface), nw, nil)
}
func (nw *NodeNetwork) Delete(ctx context.Context) (task *Task, err error) {
var upid UPID
if nw.Iface == "" {
return
}
err = nw.client.Delete(ctx, fmt.Sprintf("/nodes/%s/network/%s", nw.Node, nw.Iface), &upid)
if err != nil {
return
}
return nw.NodeAPI.NetworkReload(ctx)
}