forked from scottdware/go-bigip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sys.go
214 lines (176 loc) · 6.27 KB
/
sys.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
package bigip
import "encoding/json"
const (
uriSys = "sys"
uriFolder = "folder"
uriSyslog = "syslog"
uriSoftware = "software"
uriVolume = "volume"
uriHardware = "hardware"
uriGlobalSettings = "global-settings"
uriManagementIp = "management-ip"
//uriPlatform = "?$select=platform"
)
type Volumes struct {
Volumes []Volume `json:"items,omitempty"`
}
type Volume struct {
Name string `json:"items,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
SelfLink string `json:"selfLink,omitempty"`
Active bool `json:"active,omitempty"`
BaseBuild string `json:"basebuild,omitempty"`
Build string `json:"build,omitempty"`
Product string `json:"product,omitempty"`
Status string `json:"status,omitempty"`
Version string `json:"version,omitempty"`
}
// Volumes returns a list of Software Volumes.
func (b *BigIP) Volumes() (*Volumes, error) {
var volumes Volumes
err, _ := b.getForEntity(&volumes, uriSys, uriSoftware, uriVolume)
if err != nil {
return nil, err
}
return &volumes, nil
}
type ManagementIP struct {
Addresses []ManagementIPAddress
}
type ManagementIPAddress struct {
Name string `json:"items,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
SelfLink string `json:"selfLink,omitempty"`
}
func (b *BigIP) ManagementIPs() (*ManagementIP, error) {
var managementIP ManagementIP
err, _ := b.getForEntity(&managementIP, uriSys, uriManagementIp)
if err != nil {
return nil, err
}
return &managementIP, nil
}
type SyslogRemoteServer struct {
Name string `json:"name,omitempty"`
Host string `json:"host,omitempty"`
LocalIP string `json:"localIp,omitempty"`
RemotePort int `json:"remotePort,omitempty"`
}
type Syslog struct {
SelfLink string `json:"selfLink,omitempty"`
RemoteServers []SyslogRemoteServer `json:"remoteServers,omitempty"`
}
func (b *BigIP) Syslog() (*Syslog, error) {
var syslog Syslog
err, _ := b.getForEntity(&syslog, uriSys, uriSyslog)
if err != nil {
return nil, err
}
return &syslog, nil
}
func (b *BigIP) SetSyslog(config Syslog) error {
return b.put(config, uriSys, uriSyslog)
}
// Folders contains a list of every folder on the BIG-IP system.
type Folders struct {
Folders []Folder `json:"items"`
}
type folderDTO struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
SubPath string `json:"subPath,omitempty"`
FullPath string `json:"fullPath,omitempty"`
AppService string `json:"appService,omitempty"`
Description string `json:"description,omitempty"`
// Set to "default" to inherit or a device group name to control. You can also set it to "non-default" to pin its device group to its current setting and turn off inheritance.
DeviceGroup string `json:"deviceGroup,omitempty"`
Hidden string `json:"hidden,omitempty" bool:"true"`
NoRefCheck string `json:"noRefCheck,omitempty" bool:"true"`
// Set to "default" to inherit or a traffic group name to control. You can also set it to "non-default" to pin its traffic group to its current setting and turn off inheritance.
TrafficGroup string `json:"trafficGroup,omitempty"`
// Read-only property. Set DeviceGroup to control.
InheritedDeviceGroup string `json:"inheritedDevicegroup,omitempty" bool:"true"`
// Read-only property. Set TrafficGroup to control.
InheritedTrafficGroup string `json:"inheritedTrafficGroup,omitempty" bool:"true"`
}
type Folder struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
SubPath string `json:"subPath,omitempty"`
FullPath string `json:"fullPath,omitempty"`
AppService string `json:"appService,omitempty"`
Description string `json:"description,omitempty"`
DeviceGroup string `json:"deviceGroup,omitempty"`
Hidden *bool `json:"hidden,omitempty"`
NoRefCheck *bool `json:"noRefCheck,omitempty"`
TrafficGroup string `json:"trafficGroup,omitempty"`
// Read-only property. Set DeviceGroup to "default" or "non-default" to control.
InheritedDeviceGroup *bool `json:"inheritedDevicegroup,omitempty"`
// Read-only property. Set TrafficGroup to "default" or "non-default" to control.
InheritedTrafficGroup *bool `json:"inheritedTrafficGroup,omitempty"`
}
func (f *Folder) MarshalJSON() ([]byte, error) {
var dto folderDTO
marshal(&dto, f)
return json.Marshal(dto)
}
func (f *Folder) UnmarshalJSON(b []byte) error {
var dto folderDTO
err := json.Unmarshal(b, &dto)
if err != nil {
return err
}
return marshal(f, &dto)
}
// Folders returns a list of folders.
func (b *BigIP) Folders() (*Folders, error) {
var folders Folders
err, _ := b.getForEntity(&folders, uriSys, uriFolder)
if err != nil {
return nil, err
}
return &folders, nil
}
// CreateFolder adds a new folder to the BIG-IP system.
func (b *BigIP) CreateFolder(name string) error {
config := &Folder{
Name: name,
}
return b.post(config, uriSys, uriFolder)
}
// AddFolder adds a new folder by config to the BIG-IP system.
func (b *BigIP) AddFolder(config *Folder) error {
return b.post(config, uriSys, uriFolder)
}
// GetFolder retrieves a Folder by name. Returns nil if the folder does not exist
func (b *BigIP) GetFolder(name string) (*Folder, error) {
var folder Folder
err, ok := b.getForEntity(&folder, uriSys, uriFolder, name)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
return &folder, nil
}
// DeleteFolder removes a folder.
func (b *BigIP) DeleteFolder(name string) error {
return b.delete(uriSys, uriFolder, name)
}
// ModifyFolder allows you to change any attribute of a folder. Fields that can
// be modified are referenced in the Folder struct. This replaces the existing
// configuration, so use PatchFolder if you want to change only particular
// attributes.
func (b *BigIP) ModifyFolder(name string, config *Folder) error {
return b.put(config, uriSys, uriFolder, name)
}
// PatchFolder allows you to change any attribute of a folder. Fields that can
// be modified are referenced in the Folder struct. This changes only the
// attributes provided, so use ModifyFolder if you want to replace the existing
// configuration.
func (b *BigIP) PatchFolder(name string, config *Folder) error {
return b.patch(config, uriSys, uriFolder, name)
}