This repository has been archived by the owner on Aug 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
system.go
76 lines (60 loc) · 1.53 KB
/
system.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
package goscaleio
import (
"fmt"
"net/http"
types "github.com/thecodeteam/goscaleio/types/v1"
)
type System struct {
System *types.System
client *Client
}
func NewSystem(client *Client) *System {
return &System{
System: &types.System{},
client: client,
}
}
func (c *Client) FindSystem(
instanceID, name, href string) (*System, error) {
systems, err := c.GetInstance(href)
if err != nil {
return nil, fmt.Errorf("err: problem getting instances: %s", err)
}
for _, system := range systems {
if system.ID == instanceID || system.Name == name || href != "" {
outSystem := NewSystem(c)
outSystem.System = system
return outSystem, nil
}
}
return nil, fmt.Errorf("err: systemid or systemname not found")
}
func (s *System) GetStatistics() (*types.Statistics, error) {
link, err := GetLink(s.System.Links,
"/api/System/relationship/Statistics")
if err != nil {
return nil, err
}
stats := types.Statistics{}
err = s.client.getJSONWithRetry(
http.MethodGet, link.HREF, nil, &stats)
if err != nil {
return nil, err
}
return &stats, nil
}
func (s *System) CreateSnapshotConsistencyGroup(
snapshotVolumesParam *types.SnapshotVolumesParam) (*types.SnapshotVolumesResp, error) {
link, err := GetLink(s.System.Links, "self")
if err != nil {
return nil, err
}
path := fmt.Sprintf("%v/action/snapshotVolumes", link.HREF)
snapResp := types.SnapshotVolumesResp{}
err = s.client.getJSONWithRetry(
http.MethodPost, path, snapshotVolumesParam, &snapResp)
if err != nil {
return nil, err
}
return &snapResp, nil
}