-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackupdomains.go
88 lines (73 loc) · 2.52 KB
/
backupdomains.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 gospoc
import (
"context"
"net/http"
)
const domainsBasePath = "/oc/api/domains"
// BackupDomains is an interface for interacting with
// IBM Spectrum Protect backup domains
type BackupDomains interface {
List(ctx context.Context) ([]BackupServer, *http.Response, error)
Get(ctx context.Context, serverName string) (*BackupServer, *http.Response, error)
}
// BackupDomainsOp handles communication with the backup server related methods of the
// IBM Spectrum Protect Operations Center REST API
type BackupDomainsOp struct {
client *Client
}
// BackupDomain contains the elements that make up a backup domain
type BackupDomain struct {
NumClients int `json:"NUM_CLIENTS"`
DefDestArch string `json:"DEFDESTARCH"`
ProvidesBkup int `json:"PROVIDES_BKUP"`
ServerStatus int `json:"SERVERSTATUS"`
ScheduleCount int `json:"SCHEDULE_COUNT"`
DefMC string `json:"DEF_MC"`
DefDestBkup string `json:"DEFDESTBKUP"`
DefDestSPMAN string `json:"DEFDESTSPMAN"`
Name string `json:"NAME"`
MgmtClassCount int `json:"MGMTCLASS_COUNT"`
Server string `json:"SERVER"`
ProvidesArch int `json:"PROVIDES_ARCH"`
ProvidesSPMG int `json:"PROVIDES_SPMG"`
Link string `json:"LINK"`
ID string `json:"ID"`
OptSetCount int `json:"OPTSET_COUNT"`
}
type backupDomainsRoot struct {
Domains []BackupDomains `json:"domains"`
DomainsCount int `json:"domains_count"`
}
type domainDetailRoot struct {
DomainDetail *BackupDomain `json:"domaindetail"`
}
// List all backup domains
func (s *BackupDomainsOp) List(ctx context.Context) ([]BackupServer, *http.Response, error) {
req, err := s.client.NewRequest(ctx, http.MethodGet, domainsBasePath, nil)
if err != nil {
return nil, nil, err
}
root := new(backupServersRoot)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root.Servers, resp, err
}
// Get the details of a specific backup domain
func (s *BackupDomainsOp) Get(ctx context.Context, serverName string, domainName string) (*BackupDomain, *http.Response, error) {
if serverName == "" {
return nil, nil, NewArgError("serverName", "cannot be empty")
}
path := serversBasePath + "/" + serverName + "/domains/" + domainName + "/details"
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(domainDetailRoot)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root.DomainDetail, resp, err
}