-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathcluster_sdn_controllers.go
More file actions
84 lines (77 loc) · 2.53 KB
/
Copy pathcluster_sdn_controllers.go
File metadata and controls
84 lines (77 loc) · 2.53 KB
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
package proxmox
import (
"context"
"errors"
"fmt"
"net/url"
)
// SDNControllers lists configured SDN controllers. typ filters by plugin type
// (e.g. "bgp", "evpn"); pass "" for all.
//
// GET /cluster/sdn/controllers
func (cl *Cluster) SDNControllers(ctx context.Context, typ string) (controllers []*SDNController, err error) {
path := "/cluster/sdn/controllers"
if typ != "" {
q := url.Values{}
q.Set("type", typ)
path = path + "?" + q.Encode()
}
if err = cl.client.Get(ctx, path, &controllers); err != nil {
return nil, err
}
for _, c := range controllers {
c.client = cl.client
}
return
}
// SDNController returns a handle for a single SDN controller. No API call is
// made; use the returned handle's Read to populate it.
//
// GET /cluster/sdn/controllers/{controller}
func (cl *Cluster) SDNController(name string) *SDNController {
return &SDNController{client: cl.client, Controller: name}
}
// NewSDNController creates a new SDN controller object. opts.Controller and
// opts.Type are required.
//
// POST /cluster/sdn/controllers
func (cl *Cluster) NewSDNController(ctx context.Context, opts *SDNControllerOptions) error {
if opts == nil || opts.Controller == "" {
return errors.New("sdn controller name is required")
}
if opts.Type == "" {
return errors.New("sdn controller type is required")
}
return cl.client.Post(ctx, "/cluster/sdn/controllers", opts, nil)
}
// Read populates the receiver with the current configuration of the controller.
//
// GET /cluster/sdn/controllers/{controller}
func (c *SDNController) Read(ctx context.Context) error {
if c.Controller == "" {
return errors.New("sdn controller name is required")
}
return c.client.Get(ctx, fmt.Sprintf("/cluster/sdn/controllers/%s", c.Controller), c)
}
// Update mutates an existing controller. opts.Delete may be a comma-separated
// list of keys to reset to PVE defaults.
//
// PUT /cluster/sdn/controllers/{controller}
func (c *SDNController) Update(ctx context.Context, opts *SDNControllerOptions) error {
if c.Controller == "" {
return errors.New("sdn controller name is required")
}
if opts == nil {
opts = &SDNControllerOptions{}
}
return c.client.Put(ctx, fmt.Sprintf("/cluster/sdn/controllers/%s", c.Controller), opts, nil)
}
// Delete removes the SDN controller.
//
// DELETE /cluster/sdn/controllers/{controller}
func (c *SDNController) Delete(ctx context.Context) error {
if c.Controller == "" {
return errors.New("sdn controller name is required")
}
return c.client.Delete(ctx, fmt.Sprintf("/cluster/sdn/controllers/%s", c.Controller), nil)
}