forked from scottdware/go-bigip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cm.go
125 lines (113 loc) · 4.5 KB
/
cm.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
package bigip
import (
"errors"
"fmt"
"os"
"strings"
)
// Devices contains a list of every device on the BIG-IP system.
type Devices struct {
Devices []Device `json:"items"`
}
// UnicastAddress represent a device unicast address
type UnicastAddress struct {
EffectiveIP string `json:"effectiveIp,omitempty"`
EffectivePort int `json:"effectivePort,omitempty"`
IP string `json:"ip,omitempty"`
Port int `json:"port,omitempty"`
}
// Device contains information about each individual device.
type Device struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
FailoverState string `json:"failoverState,omitempty"`
Hostname string `json:"hostname,omitempty"`
ManagementIp string `json:"managementIp,omitempty"`
SelfDevice string `json:"selfDevice,omitempty"`
ActiveModules []string `json:"activeModules,omitempty"`
AppService string `json:"appService,omitempty"`
BaseMac string `json:"baseMac,omitempty"`
Build string `json:"build,omitempty"`
Cert string `json:"cert,omitempty"`
ChassisId string `json:"chassisId,omitempty"`
ChassisType string `json:"chassisType,omitempty"`
Comment string `json:"comment,omitempty"`
ConfigSyncIP string `json:"configSyncIp,omitempty"`
Contact string `json:"contact,omitempty"`
Description string `json:"description,omitempty"`
Edition string `json:"edition,omitempty"`
HACapacity int `json:"haCapacity,omitempty"`
InactiveModules []string `json:"inactiveModules,omitempty"`
Key string `json:"key,omitempty"`
Location string `json:"location,omitempty"`
MarketingName string `json:"marketingName,omitempty"`
MirrorIP string `json:"json:mirrorIp,omitempty"`
MirrorSecondaryIP string `json:"mirrorSecondaryIp,omitempty"`
MulticastInterface string `json:"multicastInterface,omitempty"`
MulticastIP string `json:"multicastIp,omitempty"`
MulticastPort int `json:"multicastPort,omitempty"`
OptionalModules []string `json:"optionalModules,omitempty"`
TMPartition string `json:"tmPartition,omitempty"`
PlatformID string `json:"platformId,omitempty"`
Product string `json:"product,omitempty"`
TimeLimitedModules []string `json:"timeLimitedModules,omitempty"`
Timezone string `json:"timeZone,omitempty"`
UnicastAddress []UnicastAddress `json:"unicastAddress,omitempty"`
Version string `json:"version"`
}
type ConfigSync struct {
Command string `json:"command,omitempty"`
UtilCmdArgs string `json:"utilCmdArgs,omitempty"`
}
const (
uriCm = "cm"
uriDevice = "device"
uriAutodeploy = "autodeploy"
uriSoftwareImageUploads = "software-image-uploads"
)
// Devices returns a list of devices.
func (b *BigIP) Devices() (*Devices, error) {
var devices Devices
err, _ := b.getForEntity(&devices, uriCm, uriDevice)
if err != nil {
return nil, err
}
return &devices, nil
}
// GetCurrentDevice returns a current device.
func (b *BigIP) GetCurrentDevice() (*Device, error) {
devices, err := b.Devices()
if err != nil {
return nil, err
}
for _, d := range devices.Devices {
// f5 api is returning bool value as string
if d.SelfDevice == "true" {
return &d, nil
}
}
return nil, errors.New("could not find this device")
}
// ConfigSyncToGroup runs command config-sync to-group <attr>
func (b *BigIP) ConfigSyncToGroup(name string) error {
args := "config-sync to-group " + name
config := &ConfigSync{
Command: "run",
UtilCmdArgs: args,
}
return b.post(config, uriCm)
}
// Upload a software image
func (b *BigIP) UploadSoftwareImage(f *os.File) (*Upload, error) {
if !strings.HasSuffix(f.Name(), ".iso") {
err := fmt.Errorf("File must have .iso extension")
return nil, err
}
info, err := f.Stat()
if err != nil {
return nil, err
}
return b.Upload(f, info.Size(), uriCm, uriAutodeploy, uriSoftwareImageUploads, info.Name())
}