-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathcluster_sdn_dns.go
More file actions
82 lines (75 loc) · 2.11 KB
/
Copy pathcluster_sdn_dns.go
File metadata and controls
82 lines (75 loc) · 2.11 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
package proxmox
import (
"context"
"errors"
"fmt"
"net/url"
)
// SDNDNSList lists configured SDN DNS plugins. typ filters by plugin type
// (currently only "powerdns" is supported by PVE); pass "" for all.
//
// GET /cluster/sdn/dns
func (cl *Cluster) SDNDNSList(ctx context.Context, typ string) (dns []*SDNDNS, err error) {
path := "/cluster/sdn/dns"
if typ != "" {
q := url.Values{}
q.Set("type", typ)
path = path + "?" + q.Encode()
}
if err = cl.client.Get(ctx, path, &dns); err != nil {
return nil, err
}
for _, d := range dns {
d.client = cl.client
}
return
}
// SDNDNS returns a handle for a single SDN DNS plugin. No API call is made.
//
// GET /cluster/sdn/dns/{dns}
func (cl *Cluster) SDNDNS(name string) *SDNDNS {
return &SDNDNS{client: cl.client, DNS: name}
}
// NewSDNDNS creates a new SDN DNS plugin. opts.DNS, opts.Type, opts.URL and
// opts.Key are required.
//
// POST /cluster/sdn/dns
func (cl *Cluster) NewSDNDNS(ctx context.Context, opts *SDNDNSOptions) error {
if opts == nil || opts.DNS == "" {
return errors.New("sdn dns name is required")
}
if opts.Type == "" {
return errors.New("sdn dns type is required")
}
return cl.client.Post(ctx, "/cluster/sdn/dns", opts, nil)
}
// Read populates the receiver with the current configuration.
//
// GET /cluster/sdn/dns/{dns}
func (d *SDNDNS) Read(ctx context.Context) error {
if d.DNS == "" {
return errors.New("sdn dns name is required")
}
return d.client.Get(ctx, fmt.Sprintf("/cluster/sdn/dns/%s", d.DNS), d)
}
// Update mutates an existing SDN DNS plugin configuration.
//
// PUT /cluster/sdn/dns/{dns}
func (d *SDNDNS) Update(ctx context.Context, opts *SDNDNSOptions) error {
if d.DNS == "" {
return errors.New("sdn dns name is required")
}
if opts == nil {
opts = &SDNDNSOptions{}
}
return d.client.Put(ctx, fmt.Sprintf("/cluster/sdn/dns/%s", d.DNS), opts, nil)
}
// Delete removes the SDN DNS plugin.
//
// DELETE /cluster/sdn/dns/{dns}
func (d *SDNDNS) Delete(ctx context.Context) error {
if d.DNS == "" {
return errors.New("sdn dns name is required")
}
return d.client.Delete(ctx, fmt.Sprintf("/cluster/sdn/dns/%s", d.DNS), nil)
}