-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathcluster_sdn_route_maps.go
More file actions
131 lines (122 loc) · 3.98 KB
/
Copy pathcluster_sdn_route_maps.go
File metadata and controls
131 lines (122 loc) · 3.98 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package proxmox
import (
"context"
"errors"
"fmt"
"net/url"
"strconv"
)
// SDNRouteMaps lists configured SDN route-maps. running=true returns the
// running config rather than pending.
//
// GET /cluster/sdn/route-maps
func (cl *Cluster) SDNRouteMaps(ctx context.Context, running bool) (maps []*SDNRouteMapID, err error) {
path := "/cluster/sdn/route-maps"
if running {
path += "?running=1"
}
err = cl.client.Get(ctx, path, &maps)
return
}
// SDNRouteMapEntries lists every route-map entry across all route-maps.
// pending/running toggle the returned configuration view.
//
// GET /cluster/sdn/route-maps/entries
func (cl *Cluster) SDNRouteMapEntries(ctx context.Context, pending, running bool) (entries []*SDNRouteMapEntry, err error) {
path := "/cluster/sdn/route-maps/entries"
q := url.Values{}
if pending {
q.Set("pending", "1")
}
if running {
q.Set("running", "1")
}
if len(q) > 0 {
path = path + "?" + q.Encode()
}
if err = cl.client.Get(ctx, path, &entries); err != nil {
return nil, err
}
for _, e := range entries {
e.client = cl.client
}
return
}
// SDNRouteMapEntriesFor lists the entries belonging to a single named
// route-map.
//
// GET /cluster/sdn/route-maps/entries/{route-map-id}
func (cl *Cluster) SDNRouteMapEntriesFor(ctx context.Context, routeMapID string, pending, running bool) (entries []*SDNRouteMapEntry, err error) {
if routeMapID == "" {
return nil, errors.New("route-map id is required")
}
path := fmt.Sprintf("/cluster/sdn/route-maps/entries/%s", routeMapID)
q := url.Values{}
if pending {
q.Set("pending", "1")
}
if running {
q.Set("running", "1")
}
if len(q) > 0 {
path = path + "?" + q.Encode()
}
if err = cl.client.Get(ctx, path, &entries); err != nil {
return nil, err
}
for _, e := range entries {
e.client = cl.client
e.RouteMapID = routeMapID
}
return
}
// SDNRouteMapEntry returns a handle for one entry in a route-map keyed by
// (route-map-id, order). No API call is made.
//
// GET /cluster/sdn/route-maps/entries/{route-map-id}/entry/{order}
func (cl *Cluster) SDNRouteMapEntry(routeMapID string, order uint16) *SDNRouteMapEntry {
return &SDNRouteMapEntry{client: cl.client, RouteMapID: routeMapID, Order: order}
}
// NewSDNRouteMapEntry creates a new entry in a route-map. opts.RouteMapID,
// opts.Order, and opts.Action are required.
//
// POST /cluster/sdn/route-maps/entries
func (cl *Cluster) NewSDNRouteMapEntry(ctx context.Context, opts *SDNRouteMapEntryOptions) error {
if opts == nil || opts.RouteMapID == "" {
return errors.New("route-map id is required")
}
if opts.Action == "" {
return errors.New("route-map entry action is required")
}
return cl.client.Post(ctx, "/cluster/sdn/route-maps/entries", opts, nil)
}
// Read populates the receiver with the route-map entry configuration.
//
// GET /cluster/sdn/route-maps/entries/{route-map-id}/entry/{order}
func (e *SDNRouteMapEntry) Read(ctx context.Context) error {
if e.RouteMapID == "" {
return errors.New("route-map id is required")
}
return e.client.Get(ctx, fmt.Sprintf("/cluster/sdn/route-maps/entries/%s/entry/%s", e.RouteMapID, strconv.FormatUint(uint64(e.Order), 10)), e)
}
// Update mutates the route-map entry.
//
// PUT /cluster/sdn/route-maps/entries/{route-map-id}/entry/{order}
func (e *SDNRouteMapEntry) Update(ctx context.Context, opts *SDNRouteMapEntryOptions) error {
if e.RouteMapID == "" {
return errors.New("route-map id is required")
}
if opts == nil {
opts = &SDNRouteMapEntryOptions{}
}
return e.client.Put(ctx, fmt.Sprintf("/cluster/sdn/route-maps/entries/%s/entry/%s", e.RouteMapID, strconv.FormatUint(uint64(e.Order), 10)), opts, nil)
}
// Delete removes the route-map entry.
//
// DELETE /cluster/sdn/route-maps/entries/{route-map-id}/entry/{order}
func (e *SDNRouteMapEntry) Delete(ctx context.Context) error {
if e.RouteMapID == "" {
return errors.New("route-map id is required")
}
return e.client.Delete(ctx, fmt.Sprintf("/cluster/sdn/route-maps/entries/%s/entry/%s", e.RouteMapID, strconv.FormatUint(uint64(e.Order), 10)), nil)
}