-
Notifications
You must be signed in to change notification settings - Fork 43
/
fw.go
76 lines (63 loc) · 1.86 KB
/
fw.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
package ospf
import (
"fmt"
"github.com/PaloAltoNetworks/pango/namespace"
"github.com/PaloAltoNetworks/pango/util"
)
// Firewall is the client.Network.BgpConfig namespace.
type Firewall struct {
ns *namespace.Standard
}
// Get performs GET to retrieve configuration for the given object.
func (c *Firewall) Get(vr string) (Config, error) {
ans := c.container()
err := c.ns.Object(util.Get, c.pather(vr), "", ans)
return first(ans, err)
}
// Show performs SHOW to retrieve configuration for the given object.
func (c *Firewall) Show(vr string) (Config, error) {
ans := c.container()
err := c.ns.Object(util.Show, c.pather(vr), "", ans)
return first(ans, err)
}
// Set performs SET to configure the specified objects.
func (c *Firewall) Set(vr string, e Config) error {
return c.ns.Set(c.pather(vr), specifier(e))
}
// Edit performs EDIT to configure the specified object.
func (c *Firewall) Edit(vr string, e Config) error {
return c.ns.Edit(c.pather(vr), e)
}
// Delete performs DELETE to remove the config.
func (c *Firewall) Delete(vr string) error {
return c.ns.Delete(c.pather(vr), nil, nil)
}
// FromPanosConfig retrieves the object stored in the retrieved config.
func (c *Firewall) FromPanosConfig(vr string) (Config, error) {
ans := c.container()
err := c.ns.FromPanosConfig(c.pather(vr), "", ans)
return first(ans, err)
}
func (c *Firewall) pather(vr string) namespace.Pather {
return func(v []string) ([]string, error) {
return c.xpath(vr)
}
}
func (c *Firewall) xpath(vr string) ([]string, error) {
if vr == "" {
return nil, fmt.Errorf("vr must be specified")
}
return []string{
"config",
"devices",
util.AsEntryXpath([]string{"localhost.localdomain"}),
"network",
"virtual-router",
util.AsEntryXpath([]string{vr}),
"protocol",
"ospf",
}, nil
}
func (c *Firewall) container() normalizer {
return container(c.ns.Client.Versioning())
}