-
Notifications
You must be signed in to change notification settings - Fork 43
/
fw.go
91 lines (72 loc) · 2.21 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package telemetry
import (
"github.com/PaloAltoNetworks/pango/util"
)
// FwTelemetry is a namespace struct, included as part of pango.Firewall.
type FwTelemetry struct {
con util.XapiClient
}
// Initialize is invoked by client.Initialize().
func (c *FwTelemetry) Initialize(con util.XapiClient) {
c.con = con
}
// Show performs SHOW to retrieve telemetry sharing settings.
func (c *FwTelemetry) Show() (Settings, error) {
c.con.LogQuery("(show) telemetry settings")
return c.details(c.con.Show)
}
// Get performs GET to retrieve telemetry sharing settings.
func (c *FwTelemetry) Get() (Settings, error) {
c.con.LogQuery("(get) telemetry settings")
return c.details(c.con.Get)
}
// Set performs SET to update telemetry sharing settings.
func (c *FwTelemetry) Set(e Settings) error {
var err error
_, fn := c.versioning()
c.con.LogAction("(set) telemetry settings")
path := c.xpath()
path = path[:len(path) - 1]
_, err = c.con.Set(path, fn(e), nil, nil)
return err
}
// Edit performs EDIT to update telemetry sharing settings.
func (c *FwTelemetry) Edit(e Settings) error {
var err error
_, fn := c.versioning()
c.con.LogAction("(edit) telemetry settings")
path := c.xpath()
_, err = c.con.Edit(path, fn(e), nil, nil)
return err
}
// Delete removes all telemetry sharing from the firewall.
func (c *FwTelemetry) Delete() error {
c.con.LogAction("(delete) telemetry settings")
path := c.xpath()
_, err := c.con.Delete(path, nil, nil)
return err
}
/** Internal functions for the FwTelemetry struct **/
func (c *FwTelemetry) versioning() (normalizer, func(Settings) (interface{})) {
return &container_v1{}, specify_v1
}
func (c *FwTelemetry) details(fn util.Retriever) (Settings, error) {
path := c.xpath()
obj, _ := c.versioning()
if _, err := fn(path, nil, obj); err != nil {
return Settings{}, err
}
ans := obj.Normalize()
return ans, nil
}
func (c *FwTelemetry) xpath() []string {
return []string{
"config",
"devices",
util.AsEntryXpath([]string{"localhost.localdomain"}),
"deviceconfig",
"system",
"update-schedule",
"statistics-service",
}
}