forked from walkamongus/go-bigip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cm.go
88 lines (76 loc) · 2.13 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
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"`
}
// 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"`
}
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())
}