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
/
storagepool.go
115 lines (92 loc) · 2.28 KB
/
storagepool.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
package goscaleio
import (
"errors"
"fmt"
"net/http"
types "github.com/thecodeteam/goscaleio/types/v1"
)
type StoragePool struct {
StoragePool *types.StoragePool
client *Client
}
func NewStoragePool(client *Client) *StoragePool {
return &StoragePool{
StoragePool: &types.StoragePool{},
client: client,
}
}
func NewStoragePoolEx(client *Client, pool *types.StoragePool) *StoragePool {
return &StoragePool{
StoragePool: pool,
client: client,
}
}
func (pd *ProtectionDomain) CreateStoragePool(name string) (string, error) {
storagePoolParam := &types.StoragePoolParam{
Name: name,
ProtectionDomainID: pd.ProtectionDomain.ID,
}
path := fmt.Sprintf("/api/types/StoragePool/instances")
sp := types.StoragePoolResp{}
err := pd.client.getJSONWithRetry(
http.MethodPost, path, storagePoolParam, &sp)
if err != nil {
return "", err
}
return sp.ID, nil
}
func (pd *ProtectionDomain) GetStoragePool(
storagepoolhref string) ([]*types.StoragePool, error) {
var (
err error
sp = &types.StoragePool{}
sps []*types.StoragePool
)
if storagepoolhref == "" {
var link *types.Link
link, err := GetLink(pd.ProtectionDomain.Links,
"/api/ProtectionDomain/relationship/StoragePool")
if err != nil {
return nil, err
}
err = pd.client.getJSONWithRetry(
http.MethodGet, link.HREF, nil, &sps)
} else {
err = pd.client.getJSONWithRetry(
http.MethodGet, storagepoolhref, nil, sp)
}
if err != nil {
return nil, err
}
if storagepoolhref != "" {
sps = append(sps, sp)
}
return sps, nil
}
func (pd *ProtectionDomain) FindStoragePool(
id, name, href string) (*types.StoragePool, error) {
sps, err := pd.GetStoragePool(href)
if err != nil {
return nil, fmt.Errorf("Error getting protection domains %s", err)
}
for _, sp := range sps {
if sp.ID == id || sp.Name == name || href != "" {
return sp, nil
}
}
return nil, errors.New("Couldn't find storage pool")
}
func (sp *StoragePool) GetStatistics() (*types.Statistics, error) {
link, err := GetLink(sp.StoragePool.Links,
"/api/StoragePool/relationship/Statistics")
if err != nil {
return nil, err
}
stats := types.Statistics{}
err = sp.client.getJSONWithRetry(
http.MethodGet, link.HREF, nil, &stats)
if err != nil {
return nil, err
}
return &stats, nil
}