-
Notifications
You must be signed in to change notification settings - Fork 43
/
entry.go
144 lines (124 loc) · 3.99 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
package gre
import (
"encoding/xml"
"github.com/PaloAltoNetworks/pango/util"
)
// Entry is a normalized, version independent representation of a peer.
type Entry struct {
Name string
Interface string
LocalAddressType string
LocalAddressValue string
PeerAddress string
TunnelInterface string
Ttl int
CopyTos bool
EnableKeepAlive bool
KeepAliveInterval int
KeepAliveRetry int
KeepAliveHoldTimer int
Disabled bool
}
// Copy copies the information from source Entry `s` to this object. As the
// Name field relates to the XPATH of this object, this field is not copied.
func (o *Entry) Copy(s Entry) {
o.Interface = s.Interface
o.LocalAddressType = s.LocalAddressType
o.LocalAddressValue = s.LocalAddressValue
o.PeerAddress = s.PeerAddress
o.TunnelInterface = s.TunnelInterface
o.Ttl = s.Ttl
o.CopyTos = s.CopyTos
o.EnableKeepAlive = s.EnableKeepAlive
o.KeepAliveInterval = s.KeepAliveInterval
o.KeepAliveRetry = s.KeepAliveRetry
o.KeepAliveHoldTimer = s.KeepAliveHoldTimer
o.Disabled = s.Disabled
}
/** Structs / functions for this namespace. **/
type normalizer interface {
Normalize() Entry
}
type container_v1 struct {
Answer entry_v1 `xml:"result>entry"`
}
func (o *container_v1) Normalize() Entry {
ans := Entry{
Name: o.Answer.Name,
Interface: o.Answer.Local.Interface,
PeerAddress: o.Answer.Peer.PeerAddress,
TunnelInterface: o.Answer.TunnelInterface,
Ttl: o.Answer.Ttl,
CopyTos: util.AsBool(o.Answer.CopyTos),
Disabled: util.AsBool(o.Answer.Disabled),
}
if o.Answer.Local.Ip != "" {
ans.LocalAddressType = LocalAddressTypeIp
ans.LocalAddressValue = o.Answer.Local.Ip
} else if o.Answer.Local.FloatingIp != "" {
ans.LocalAddressType = LocalAddressTypeFloatingIp
ans.LocalAddressValue = o.Answer.Local.FloatingIp
}
if o.Answer.KeepAlive != nil {
ans.EnableKeepAlive = util.AsBool(o.Answer.KeepAlive.EnableKeepAlive)
ans.KeepAliveInterval = o.Answer.KeepAlive.KeepAliveInterval
ans.KeepAliveRetry = o.Answer.KeepAlive.KeepAliveRetry
ans.KeepAliveHoldTimer = o.Answer.KeepAlive.KeepAliveHoldTimer
}
return ans
}
type entry_v1 struct {
XMLName xml.Name `xml:"entry"`
Name string `xml:"name,attr"`
Local localAddress `xml:"local-address"`
Peer peerAddress `xml:"peer-address"`
TunnelInterface string `xml:"tunnel-interface"`
Ttl int `xml:"ttl,omitempty"`
CopyTos string `xml:"copy-tos"`
KeepAlive *ka `xml:"keep-alive"`
Disabled string `xml:"disabled"`
}
type localAddress struct {
Interface string `xml:"interface"`
Ip string `xml:"ip,omitempty"`
FloatingIp string `xml:"floating-ip,omitempty"`
}
type peerAddress struct {
PeerAddress string `xml:"ip"`
}
type ka struct {
EnableKeepAlive string `xml:"enable"`
KeepAliveInterval int `xml:"interval,omitempty"`
KeepAliveRetry int `xml:"retry,omitempty"`
KeepAliveHoldTimer int `xml:"hold-timer,omitempty"`
}
func specify_v1(e Entry) interface{} {
ans := entry_v1{
Name: e.Name,
Local: localAddress{
Interface: e.Interface,
},
Peer: peerAddress{
PeerAddress: e.PeerAddress,
},
TunnelInterface: e.TunnelInterface,
Ttl: e.Ttl,
CopyTos: util.YesNo(e.CopyTos),
Disabled: util.YesNo(e.Disabled),
}
switch e.LocalAddressType {
case LocalAddressTypeIp:
ans.Local.Ip = e.LocalAddressValue
case LocalAddressTypeFloatingIp:
ans.Local.FloatingIp = e.LocalAddressValue
}
if e.EnableKeepAlive || e.KeepAliveInterval != 0 || e.KeepAliveRetry != 0 || e.KeepAliveHoldTimer != 0 {
ans.KeepAlive = &ka{
EnableKeepAlive: util.YesNo(e.EnableKeepAlive),
KeepAliveInterval: e.KeepAliveInterval,
KeepAliveRetry: e.KeepAliveRetry,
KeepAliveHoldTimer: e.KeepAliveHoldTimer,
}
}
return ans
}