-
Notifications
You must be signed in to change notification settings - Fork 7
/
snapshotscheduler.go
212 lines (177 loc) · 7.97 KB
/
snapshotscheduler.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package gsclient
import (
"context"
"errors"
"net/http"
"path"
)
//StorageSnapshotScheduleList JSON of a list of storage snapshot schedules
type StorageSnapshotScheduleList struct {
//Array of storage snapshot schedules
List map[string]StorageSnapshotScheduleProperties `json:"snapshot_schedules"`
}
//StorageSnapshotSchedule JSON struct of a single storage snapshot scheduler
type StorageSnapshotSchedule struct {
//Properties of a storage snapshot schedule
Properties StorageSnapshotScheduleProperties `json:"snapshot_schedule"`
}
//StorageSnapshotScheduleProperties JSON struct of properties of a single storage snapshot schedule
type StorageSnapshotScheduleProperties struct {
//Defines the date and time of the last object change.
ChangeTime GSTime `json:"change_time"`
//Defines the date and time the object was initially created.
CreateTime GSTime `json:"create_time"`
//The amount of Snapshots to keep before overwriting the last created Snapshot.
//value >= 1
KeepSnapshots int `json:"keep_snapshots"`
//List of labels.
Labels []string `json:"labels"`
//The human-readable name of the object. It supports the full UTF-8 charset, with a maximum of 64 characters.
Name string `json:"name"`
//The date and time that the snapshot schedule will be run.
NextRuntime GSTime `json:"next_runtime"`
//The UUID of an object is always unique, and refers to a specific object.
ObjectUUID string `json:"object_uuid"`
//Related snapshots (snapshots taken by this snapshot schedule)
Relations StorageSnapshotScheduleRelations `json:"relations"`
//The interval at which the schedule will run (in minutes)
//value >= 60
RunInterval int `json:"run_interval"`
//Status indicates the status of the object.
Status string `json:"status"`
//UUID of the storage that will be used for taking snapshots
StorageUUID string `json:"storage_uuid"`
}
//StorageSnapshotScheduleRelations JSON struct of a list of relations of a storage snapshot schedule
type StorageSnapshotScheduleRelations struct {
//Array of all related snapshots (snapshots taken by this snapshot schedule)
Snapshots []StorageSnapshotScheduleRelation `json:"snapshots"`
}
//StorageSnapshotScheduleRelation JSON struct of a relation of a storage snapshot schedule
type StorageSnapshotScheduleRelation struct {
//Defines the date and time the object was initially created.
CreateTime GSTime `json:"create_time"`
//The human-readable name of the object. It supports the full UTF-8 charset, with a maximum of 64 characters.
Name string `json:"name"`
//The UUID of an object is always unique, and refers to a specific object.
ObjectUUID string `json:"object_uuid"`
}
//StorageSnapshotScheduleCreateRequest JSON struct of a request for creating a storage snapshot schedule
type StorageSnapshotScheduleCreateRequest struct {
//The human-readable name of the object. It supports the full UTF-8 charset, with a maximum of 64 characters.
Name string `json:"name"`
//List of labels. Optional.
Labels []string `json:"labels,omitempty"`
//The interval at which the schedule will run (in minutes)
//Allowed value >= 60
RunInterval int `json:"run_interval"`
//The amount of Snapshots to keep before overwriting the last created Snapshot.
//Allowed value >= 1
KeepSnapshots int `json:"keep_snapshots"`
//The date and time that the snapshot schedule will be run. Optional.
NextRuntime *GSTime `json:"next_runtime,omitempty"`
}
//StorageSnapshotScheduleCreateResponse JSON struct of a response for creating a storage snapshot schedule
type StorageSnapshotScheduleCreateResponse struct {
//UUID of the request
RequestUUID string `json:"request_uuid"`
//UUID of the snapshot schedule being created
ObjectUUID string `json:"object_uuid"`
}
//StorageSnapshotScheduleUpdateRequest JSON struct of a request for updating a storage snapshot schedule
type StorageSnapshotScheduleUpdateRequest struct {
//The human-readable name of the object. It supports the full UTF-8 charset, with a maximum of 64 characters.
//Optional.
Name string `json:"name,omitempty"`
//List of labels. Optional.
Labels []string `json:"labels,omitempty"`
//The interval at which the schedule will run (in minutes). Optional.
//Allowed value >= 60
RunInterval int `json:"run_interval,omitempty"`
//The amount of Snapshots to keep before overwriting the last created Snapshot. Optional.
//Allowed value >= 1
KeepSnapshots int `json:"keep_snapshots,omitempty"`
//The date and time that the snapshot schedule will be run. Optional.
NextRuntime *GSTime `json:"next_runtime,omitempty"`
}
//GetStorageSnapshotScheduleList gets a list of available storage snapshot schedules based on a given storage's id
//
//See: https://gridscale.io/en//api-documentation/index.html#operation/getSnapshotSchedules
func (c *Client) GetStorageSnapshotScheduleList(ctx context.Context, id string) ([]StorageSnapshotSchedule, error) {
if !isValidUUID(id) {
return nil, errors.New("'id' is invalid")
}
r := request{
uri: path.Join(apiStorageBase, id, "snapshot_schedules"),
method: http.MethodGet,
skipCheckingRequest: true,
}
var response StorageSnapshotScheduleList
var schedules []StorageSnapshotSchedule
err := r.execute(ctx, *c, &response)
for _, properties := range response.List {
schedules = append(schedules, StorageSnapshotSchedule{Properties: properties})
}
return schedules, err
}
//GetStorageSnapshotSchedule gets a specific storage snapshot scheduler based on a given storage's id and scheduler's id
//
//See: https://gridscale.io/en//api-documentation/index.html#operation/getSnapshotSchedule
func (c *Client) GetStorageSnapshotSchedule(ctx context.Context, storageID, scheduleID string) (StorageSnapshotSchedule, error) {
if !isValidUUID(storageID) || !isValidUUID(scheduleID) {
return StorageSnapshotSchedule{}, errors.New("'storageID' or 'scheduleID' is invalid")
}
r := request{
uri: path.Join(apiStorageBase, storageID, "snapshot_schedules", scheduleID),
method: http.MethodGet,
skipCheckingRequest: true,
}
var response StorageSnapshotSchedule
err := r.execute(ctx, *c, &response)
return response, err
}
//CreateStorageSnapshotSchedule create a storage's snapshot scheduler
//
//See: https://gridscale.io/en//api-documentation/index.html#operation/createSnapshotSchedule
func (c *Client) CreateStorageSnapshotSchedule(ctx context.Context, id string, body StorageSnapshotScheduleCreateRequest) (
StorageSnapshotScheduleCreateResponse, error) {
if !isValidUUID(id) {
return StorageSnapshotScheduleCreateResponse{}, errors.New("'id' is invalid")
}
r := request{
uri: path.Join(apiStorageBase, id, "snapshot_schedules"),
method: http.MethodPost,
body: body,
}
var response StorageSnapshotScheduleCreateResponse
err := r.execute(ctx, *c, &response)
return response, err
}
//UpdateStorageSnapshotSchedule updates specific Storage's snapshot scheduler based on a given storage's id and scheduler's id
//
//See: https://gridscale.io/en//api-documentation/index.html#operation/updateSnapshotSchedule
func (c *Client) UpdateStorageSnapshotSchedule(ctx context.Context, storageID, scheduleID string,
body StorageSnapshotScheduleUpdateRequest) error {
if !isValidUUID(storageID) || !isValidUUID(scheduleID) {
return errors.New("'storageID' or 'scheduleID' is invalid")
}
r := request{
uri: path.Join(apiStorageBase, storageID, "snapshot_schedules", scheduleID),
method: http.MethodPatch,
body: body,
}
return r.execute(ctx, *c, nil)
}
//DeleteStorageSnapshotSchedule deletes specific Storage's snapshot scheduler based on a given storage's id and scheduler's id
//
//See: https://gridscale.io/en//api-documentation/index.html#operation/deleteSnapshotSchedule
func (c *Client) DeleteStorageSnapshotSchedule(ctx context.Context, storageID, scheduleID string) error {
if !isValidUUID(storageID) || !isValidUUID(scheduleID) {
return errors.New("'storageID' or 'scheduleID' is invalid")
}
r := request{
uri: path.Join(apiStorageBase, storageID, "snapshot_schedules", scheduleID),
method: http.MethodDelete,
}
return r.execute(ctx, *c, nil)
}