/
entry.go
157 lines (135 loc) · 3.88 KB
/
entry.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package path
import (
"encoding/xml"
"github.com/PaloAltoNetworks/pango/util"
"github.com/PaloAltoNetworks/pango/version"
)
// Entry is a normalized, version independent representation of a HA
// path monitor group.
type Entry struct {
Name string
Enable bool
SrcIp string // virtual-wire, vlan
FailureCondition string
PingInterval int
PingCount int
DstIpGroups []DstIpGroup
}
type DstIpGroup struct {
Name string
Enable bool
FailureCondition string
DstIps []string // unordered
}
func (o *Entry) Copy(s Entry) {
o.Enable = s.Enable
o.SrcIp = s.SrcIp
o.FailureCondition = s.FailureCondition
o.PingInterval = s.PingInterval
o.PingCount = s.PingCount
if s.DstIpGroups == nil {
o.DstIpGroups = nil
} else {
o.DstIpGroups = make([]DstIpGroup, len(s.DstIpGroups))
for i := range s.DstIpGroups {
o.DstIpGroups[i] = s.DstIpGroups[i]
if s.DstIpGroups[i].DstIps != nil {
o.DstIpGroups[i].DstIps = make([]string,
len(s.DstIpGroups[i].DstIps))
copy(o.DstIpGroups[i].DstIps, s.DstIpGroups[i].DstIps)
}
}
}
}
/** Structs / functions for this namespace. **/
func (o Entry) Specify(v version.Number) (string, interface{}) {
_, fn := versioning(v)
return o.Name, fn(o)
}
type normalizer interface {
Normalize() []Entry
Names() []string
}
type container_v1 struct {
Answer []entry_v1 `xml:"entry"`
}
func (o *container_v1) Normalize() []Entry {
ans := make([]Entry, 0, len(o.Answer))
for i := range o.Answer {
ans = append(ans, o.Answer[i].normalize())
}
return ans
}
func (o *container_v1) Names() []string {
ans := make([]string, 0, len(o.Answer))
for i := range o.Answer {
ans = append(ans, o.Answer[i].Name)
}
return ans
}
func (o *entry_v1) normalize() Entry {
ans := Entry{
Name: o.Name,
Enable: util.AsBool(o.Enable),
SrcIp: o.SrcIp,
FailureCondition: o.FailureCondition,
PingInterval: o.PingInterval,
PingCount: o.PingCount,
}
if o.DstIpGroups != nil {
groups := make([]DstIpGroup, 0, len(o.DstIpGroups.Entries))
for _, group := range o.DstIpGroups.Entries {
groups = append(groups, DstIpGroup{
Name: group.Name,
Enable: util.AsBool(group.Enable),
FailureCondition: group.FailureCondition,
DstIps: util.MemToStr(group.DstIps),
})
}
ans.DstIpGroups = groups
}
return ans
}
type entry_v1 struct {
XMLName xml.Name `xml:"entry"`
Name string `xml:"name,attr"`
Enable string `xml:"enabled"`
SrcIp string `xml:"source-ip,omitempty"`
FailureCondition string `xml:"failure-condition,omitempty"`
PingInterval int `xml:"ping-interval,omitempty"`
PingCount int `xml:"ping-count,omitempty"`
DstIpGroups *dstIpGroup `xml:"destination-ip-group"`
}
type dstIpGroup struct {
Entries []dstIpGroupEntry `xml:"entry"`
}
type dstIpGroupEntry struct {
Name string `xml:"name,attr"`
Enable string `xml:"enabled"`
FailureCondition string `xml:"failure-condition,omitempty"`
DstIps *util.MemberType `xml:"destination-ip"`
}
func specify_v1(e Entry) interface{} {
ans := entry_v1{
Name: e.Name,
Enable: util.YesNo(e.Enable),
SrcIp: e.SrcIp,
FailureCondition: e.FailureCondition,
PingInterval: e.PingInterval,
PingCount: e.PingCount,
}
if len(e.DstIpGroups) > 0 {
ans.DstIpGroups = &dstIpGroup{}
groups := make([]dstIpGroupEntry, 0, len(e.DstIpGroups))
for _, group := range e.DstIpGroups {
groups = append(groups, dstIpGroupEntry{
Name: group.Name,
Enable: util.YesNo(group.Enable),
FailureCondition: group.FailureCondition,
DstIps: util.StrToMem(group.DstIps),
})
}
ans.DstIpGroups.Entries = groups
}
return ans
}