-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathcluster_sdn_ipams.go
More file actions
94 lines (86 loc) · 2.62 KB
/
Copy pathcluster_sdn_ipams.go
File metadata and controls
94 lines (86 loc) · 2.62 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
85
86
87
88
89
90
91
92
93
94
package proxmox
import (
"context"
"errors"
"fmt"
"net/url"
)
// SDNIPAMs lists configured IPAM backends. typ filters by plugin type
// ("netbox", "phpipam", "pve"); pass "" for all.
//
// GET /cluster/sdn/ipams
func (cl *Cluster) SDNIPAMs(ctx context.Context, typ string) (ipams []*SDNIPAM, err error) {
path := "/cluster/sdn/ipams"
if typ != "" {
q := url.Values{}
q.Set("type", typ)
path = path + "?" + q.Encode()
}
if err = cl.client.Get(ctx, path, &ipams); err != nil {
return nil, err
}
for _, i := range ipams {
i.client = cl.client
}
return
}
// SDNIPAM returns a handle for a single IPAM backend. No API call is made.
//
// GET /cluster/sdn/ipams/{ipam}
func (cl *Cluster) SDNIPAM(name string) *SDNIPAM {
return &SDNIPAM{client: cl.client, IPAM: name}
}
// NewSDNIPAM creates a new IPAM backend. opts.IPAM and opts.Type are required.
//
// POST /cluster/sdn/ipams
func (cl *Cluster) NewSDNIPAM(ctx context.Context, opts *SDNIPAMOptions) error {
if opts == nil || opts.IPAM == "" {
return errors.New("sdn ipam name is required")
}
if opts.Type == "" {
return errors.New("sdn ipam type is required")
}
return cl.client.Post(ctx, "/cluster/sdn/ipams", opts, nil)
}
// Read populates the receiver with the current configuration.
//
// GET /cluster/sdn/ipams/{ipam}
func (i *SDNIPAM) Read(ctx context.Context) error {
if i.IPAM == "" {
return errors.New("sdn ipam name is required")
}
return i.client.Get(ctx, fmt.Sprintf("/cluster/sdn/ipams/%s", i.IPAM), i)
}
// Update mutates an existing IPAM backend configuration.
//
// PUT /cluster/sdn/ipams/{ipam}
func (i *SDNIPAM) Update(ctx context.Context, opts *SDNIPAMOptions) error {
if i.IPAM == "" {
return errors.New("sdn ipam name is required")
}
if opts == nil {
opts = &SDNIPAMOptions{}
}
return i.client.Put(ctx, fmt.Sprintf("/cluster/sdn/ipams/%s", i.IPAM), opts, nil)
}
// Delete removes the IPAM backend.
//
// DELETE /cluster/sdn/ipams/{ipam}
func (i *SDNIPAM) Delete(ctx context.Context) error {
if i.IPAM == "" {
return errors.New("sdn ipam name is required")
}
return i.client.Delete(ctx, fmt.Sprintf("/cluster/sdn/ipams/%s", i.IPAM), nil)
}
// Status returns the list of IP entries from this IPAM. The shape of each
// entry is plugin-specific so it's returned as a free-form slice of maps; use
// the typed IPAM struct (cluster/sdn types) for known fields.
//
// GET /cluster/sdn/ipams/{ipam}/status
func (i *SDNIPAM) Status(ctx context.Context) (entries []map[string]any, err error) {
if i.IPAM == "" {
return nil, errors.New("sdn ipam name is required")
}
err = i.client.Get(ctx, fmt.Sprintf("/cluster/sdn/ipams/%s/status", i.IPAM), &entries)
return
}