This repository has been archived by the owner on Apr 28, 2021. It is now read-only.
forked from 1and1/oneandone-cloudserver-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sharedstorages.go
189 lines (172 loc) · 5.61 KB
/
sharedstorages.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package oneandone
import (
"net/http"
)
type SharedStorage struct {
Identity
descField
Size int `json:"size"`
MinSizeAllowed int `json:"minimum_size_allowed"`
SizeUsed string `json:"size_used,omitempty"`
State string `json:"state,omitempty"`
SiteId string `json:"site_id,omitempty"`
CifsPath string `json:"cifs_path,omitempty"`
NfsPath string `json:"nfs_path,omitempty"`
CreationDate string `json:"creation_date,omitempty"`
Servers []SharedStorageServer `json:"servers,omitempty"`
Datacenter *Datacenter `json:"datacenter,omitempty"`
ApiPtr
}
type SharedStorageServer struct {
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Rights string `json:"rights,omitempty"`
}
type SharedStorageRequest struct {
DatacenterId string `json:"datacenter_id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Size *int `json:"size"`
}
type SharedStorageAccess struct {
State string `json:"state,omitempty"`
KerberosContentFile string `json:"kerberos_content_file,omitempty"`
UserDomain string `json:"user_domain,omitempty"`
SiteId string `json:"site_id,omitempty"`
NeedsPasswordReset int `json:"needs_password_reset"`
}
// GET /shared_storages
func (api *API) ListSharedStorages(args ...interface{}) ([]SharedStorage, error) {
url, err := processQueryParams(createUrl(api, sharedStoragePathSegment), args...)
if err != nil {
return nil, err
}
result := []SharedStorage{}
err = api.Client.Get(url, &result, http.StatusOK)
if err != nil {
return nil, err
}
for index, _ := range result {
result[index].api = api
}
return result, nil
}
// POST /shared_storages
func (api *API) CreateSharedStorage(request *SharedStorageRequest) (string, *SharedStorage, error) {
result := new(SharedStorage)
url := createUrl(api, sharedStoragePathSegment)
err := api.Client.Post(url, request, &result, http.StatusAccepted)
if err != nil {
return "", nil, err
}
result.api = api
return result.Id, result, nil
}
// GET /shared_storages/{id}
func (api *API) GetSharedStorage(ss_id string) (*SharedStorage, error) {
result := new(SharedStorage)
url := createUrl(api, sharedStoragePathSegment, ss_id)
err := api.Client.Get(url, &result, http.StatusOK)
if err != nil {
return nil, err
}
result.api = api
return result, nil
}
// DELETE /shared_storages/{id}
func (api *API) DeleteSharedStorage(ss_id string) (*SharedStorage, error) {
result := new(SharedStorage)
url := createUrl(api, sharedStoragePathSegment, ss_id)
err := api.Client.Delete(url, nil, &result, http.StatusAccepted)
if err != nil {
return nil, err
}
result.api = api
return result, nil
}
// PUT /shared_storages/{id}
func (api *API) UpdateSharedStorage(ss_id string, request *SharedStorageRequest) (*SharedStorage, error) {
result := new(SharedStorage)
url := createUrl(api, sharedStoragePathSegment, ss_id)
err := api.Client.Put(url, &request, &result, http.StatusAccepted)
if err != nil {
return nil, err
}
result.api = api
return result, nil
}
// GET /shared_storages/{id}/servers
func (api *API) ListSharedStorageServers(st_id string) ([]SharedStorageServer, error) {
result := []SharedStorageServer{}
url := createUrl(api, sharedStoragePathSegment, st_id, "servers")
err := api.Client.Get(url, &result, http.StatusOK)
if err != nil {
return nil, err
}
return result, nil
}
// POST /shared_storages/{id}/servers
func (api *API) AddSharedStorageServers(st_id string, servers []SharedStorageServer) (*SharedStorage, error) {
result := new(SharedStorage)
req := struct {
Servers []SharedStorageServer `json:"servers"`
}{servers}
url := createUrl(api, sharedStoragePathSegment, st_id, "servers")
err := api.Client.Post(url, &req, &result, http.StatusAccepted)
if err != nil {
return nil, err
}
result.api = api
return result, nil
}
// GET /shared_storages/{id}/servers/{id}
func (api *API) GetSharedStorageServer(st_id string, ser_id string) (*SharedStorageServer, error) {
result := new(SharedStorageServer)
url := createUrl(api, sharedStoragePathSegment, st_id, "servers", ser_id)
err := api.Client.Get(url, &result, http.StatusOK)
if err != nil {
return nil, err
}
return result, nil
}
// DELETE /shared_storages/{id}/servers/{id}
func (api *API) DeleteSharedStorageServer(st_id string, ser_id string) (*SharedStorage, error) {
result := new(SharedStorage)
url := createUrl(api, sharedStoragePathSegment, st_id, "servers", ser_id)
err := api.Client.Delete(url, nil, &result, http.StatusAccepted)
if err != nil {
return nil, err
}
result.api = api
return result, nil
}
// GET /shared_storages/access
func (api *API) GetSharedStorageCredentials() ([]SharedStorageAccess, error) {
result := []SharedStorageAccess{}
url := createUrl(api, sharedStoragePathSegment, "access")
err := api.Client.Get(url, &result, http.StatusOK)
if err != nil {
return nil, err
}
return result, nil
}
// PUT /shared_storages/access
func (api *API) UpdateSharedStorageCredentials(new_pass string) ([]SharedStorageAccess, error) {
result := []SharedStorageAccess{}
req := struct {
Password string `json:"password"`
}{new_pass}
url := createUrl(api, sharedStoragePathSegment, "access")
err := api.Client.Put(url, &req, &result, http.StatusAccepted)
if err != nil {
return nil, err
}
return result, nil
}
func (ss *SharedStorage) GetState() (string, error) {
in, err := ss.api.GetSharedStorage(ss.Id)
if in == nil {
return "", err
}
return in.State, err
}