-
Notifications
You must be signed in to change notification settings - Fork 42
/
pano.go
121 lines (102 loc) · 3.53 KB
/
pano.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
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
package ipv6
import (
"fmt"
"github.com/PaloAltoNetworks/pango/namespace"
"github.com/PaloAltoNetworks/pango/util"
)
// Panorama is the client.Network.Ipv6StaticRoute namespace.
type Panorama struct {
ns *namespace.Standard
}
// GetList performs GET to retrieve a list of all objects.
func (c *Panorama) GetList(tmpl, ts, vr string) ([]string, error) {
ans := c.container()
return c.ns.Listing(util.Get, c.pather(tmpl, ts, vr), ans)
}
// ShowList performs SHOW to retrieve a list of all objects.
func (c *Panorama) ShowList(tmpl, ts, vr string) ([]string, error) {
ans := c.container()
return c.ns.Listing(util.Show, c.pather(tmpl, ts, vr), ans)
}
// Get performs GET to retrieve information for the given object.
func (c *Panorama) Get(tmpl, ts, vr, name string) (Entry, error) {
ans := c.container()
err := c.ns.Object(util.Get, c.pather(tmpl, ts, vr), name, ans)
return first(ans, err)
}
// Show performs SHOW to retrieve information for the given object.
func (c *Panorama) Show(tmpl, ts, vr, name string) (Entry, error) {
ans := c.container()
err := c.ns.Object(util.Show, c.pather(tmpl, ts, vr), name, ans)
return first(ans, err)
}
// GetAll performs GET to retrieve all objects configured.
func (c *Panorama) GetAll(tmpl, ts, vr string) ([]Entry, error) {
ans := c.container()
err := c.ns.Objects(util.Get, c.pather(tmpl, ts, vr), ans)
return all(ans, err)
}
// ShowAll performs SHOW to retrieve information for all objects.
func (c *Panorama) ShowAll(tmpl, ts, vr string) ([]Entry, error) {
ans := c.container()
err := c.ns.Objects(util.Show, c.pather(tmpl, ts, vr), ans)
return all(ans, err)
}
// Set performs SET to configure the specified objects.
func (c *Panorama) Set(tmpl, ts, vr string, e ...Entry) error {
return c.ns.Set(c.pather(tmpl, ts, vr), specifier(e...))
}
// Edit performs EDIT to configure the specified object.
func (c *Panorama) Edit(tmpl, ts, vr string, e Entry) error {
return c.ns.Edit(c.pather(tmpl, ts, vr), e)
}
// Delete performs DELETE to remove the specified objects.
//
// Objects can be either a string or an Entry object.
func (c *Panorama) Delete(tmpl, ts, vr string, e ...interface{}) error {
names, nErr := toNames(e)
return c.ns.Delete(c.pather(tmpl, ts, vr), names, nErr)
}
// FromPanosConfig retrieves the object stored in the retrieved config.
func (c *Panorama) FromPanosConfig(tmpl, ts, vr, name string) (Entry, error) {
ans := c.container()
err := c.ns.FromPanosConfig(c.pather(tmpl, ts, vr), name, ans)
return first(ans, err)
}
// AllFromPanosConfig retrieves all objects stored in the retrieved config.
func (c *Panorama) AllFromPanosConfig(tmpl, ts, vr string) ([]Entry, error) {
ans := c.container()
err := c.ns.AllFromPanosConfig(c.pather(tmpl, ts, vr), ans)
return all(ans, err)
}
func (c *Panorama) pather(tmpl, ts, vr string) namespace.Pather {
return func(v []string) ([]string, error) {
return c.xpath(tmpl, ts, vr, v)
}
}
func (c *Panorama) xpath(tmpl, ts, vr string, vals []string) ([]string, error) {
if tmpl == "" && ts == "" {
return nil, fmt.Errorf("tmpl or ts must be specified")
}
if vr == "" {
return nil, fmt.Errorf("vr must be specified")
}
ans := make([]string, 0, 15)
ans = append(ans, util.TemplateXpathPrefix(tmpl, ts)...)
ans = append(ans,
"config",
"devices",
util.AsEntryXpath([]string{"localhost.localdomain"}),
"network",
"virtual-router",
util.AsEntryXpath([]string{vr}),
"routing-table",
"ipv6",
"static-route",
util.AsEntryXpath(vals),
)
return ans, nil
}
func (c *Panorama) container() normalizer {
return container(c.ns.Client.Versioning())
}