-
Notifications
You must be signed in to change notification settings - Fork 7
/
storage_backup_schedule.go
267 lines (223 loc) · 10.3 KB
/
storage_backup_schedule.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
package gsclient
import (
"context"
"errors"
"net/http"
"path"
)
// StorageBackupScheduleOperator provides an interface for operations on backup schedules.
type StorageBackupScheduleOperator interface {
GetStorageBackupScheduleList(ctx context.Context, id string) ([]StorageBackupSchedule, error)
GetStorageBackupSchedule(ctx context.Context, storageID, scheduleID string) (StorageBackupSchedule, error)
CreateStorageBackupSchedule(ctx context.Context, id string, body StorageBackupScheduleCreateRequest)
UpdateStorageBackupSchedule(ctx context.Context, storageID, scheduleID string, body StorageBackupScheduleUpdateRequest) error
DeleteStorageBackupSchedule(ctx context.Context, storageID, scheduleID string) error
}
// StorageBackupScheduleList contains a list of storage backup schedules.
type StorageBackupScheduleList struct {
List map[string]StorageBackupScheduleProperties `json:"schedule_storage_backups"`
}
// StorageBackupSchedule represents a single storage backup schedule.
type StorageBackupSchedule struct {
Properties StorageBackupScheduleProperties `json:"schedule_storage_backup"`
}
// StorageBackupScheduleProperties contains properties of a storage backup schedule.
type StorageBackupScheduleProperties 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 backups to keep before overwriting the last created backup.
// value >= 1.
KeepBackups int `json:"keep_backups"`
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
Name string `json:"name"`
// The date and time that the storage backup 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 backups (backups taken by this storage backup schedule)
Relations StorageBackupScheduleRelations `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 making taking backups
StorageUUID string `json:"storage_uuid"`
// Status of the schedule.
Active bool `json:"active"`
// The UUID of the location where your backup is stored.
BackupLocationUUID string `json:"backup_location_uuid"`
// The human-readable name of backup location. It supports the full UTF-8 character set, with a maximum of 64 characters.
BackupLocationName string `json:"backup_location_name"`
}
// StorageBackupScheduleRelations contains a list of relations between a storage backup schedule and storage backups.
type StorageBackupScheduleRelations struct {
// Array of all related backups (backups taken by this storage backup schedule).
StorageBackups []StorageBackupScheduleRelation `json:"storages_backups"`
}
// StorageBackupScheduleRelation represents a relation between a storage backup schedule and a storage backup.
type StorageBackupScheduleRelation 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 character set, 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"`
}
// StorageBackupScheduleCreateRequest represents a request for creating a storage backup schedule.
type StorageBackupScheduleCreateRequest struct {
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
Name string `json:"name"`
// The interval at which the schedule will run (in minutes).
// Allowed value >= 60.
RunInterval int `json:"run_interval"`
// The amount of backups to keep before overwriting the last created backup.
// value >= 1.
KeepBackups int `json:"keep_backups"`
// The date and time that the storage backup schedule will be run.
NextRuntime GSTime `json:"next_runtime"`
// Status of the schedule.
Active bool `json:"active"`
// The UUID of the location where your backup is stored.
BackupLocationUUID string `json:"backup_location_uuid,omitempty"`
}
// StorageBackupScheduleCreateResponse represents a response for creating a storage backup schedule.
type StorageBackupScheduleCreateResponse struct {
// UUID of the request.
RequestUUID string `json:"request_uuid"`
// UUID of the storage backup schedule being created.
ObjectUUID string `json:"object_uuid"`
}
// StorageBackupScheduleUpdateRequest represents a request for updating a storage backup schedule.
type StorageBackupScheduleUpdateRequest struct {
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
// Optional.
Name string `json:"name,omitempty"`
// The interval at which the schedule will run (in minutes). Optional.
// Allowed value >= 60
RunInterval int `json:"run_interval,omitempty"`
// The amount of backups to keep before overwriting the last created backup. Optional.
// value >= 1
KeepBackups int `json:"keep_backups,omitempty"`
// The date and time that the storage backup schedule will be run. Optional.
NextRuntime *GSTime `json:"next_runtime,omitempty"`
// Status of the schedule. Optional.
Active *bool `json:"active,omitempty"`
}
// StorageBackupLocationList contains a list of available location to store your backup.
type StorageBackupLocationList struct {
List map[string]StorageBackupLocationProperties `json:"backup_locations"`
}
//StorageBackupLocation represents a backup location.
type StorageBackupLocation struct {
Properties StorageBackupLocationProperties
}
// StorageBackupLocationProperties represents a backup location's properties.
type StorageBackupLocationProperties struct {
// UUID of the location.
ObjectUUID string `json:"object_uuid"`
// Name of the location.
Name string `json:"name"`
}
// GetStorageBackupScheduleList returns a list of available storage backup schedules based on a given storage's id.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/getStorageBackupSchedules
func (c *Client) GetStorageBackupScheduleList(ctx context.Context, id string) ([]StorageBackupSchedule, error) {
if !isValidUUID(id) {
return nil, errors.New("'id' is invalid")
}
r := gsRequest{
uri: path.Join(apiStorageBase, id, "backup_schedules"),
method: http.MethodGet,
skipCheckingRequest: true,
}
var response StorageBackupScheduleList
var schedules []StorageBackupSchedule
err := r.execute(ctx, *c, &response)
for _, properties := range response.List {
schedules = append(schedules, StorageBackupSchedule{Properties: properties})
}
return schedules, err
}
// GetStorageBackupSchedule returns a specific storage backup schedule based on a given storage's id and a backup schedule's id.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/getStorageBackupSchedules
func (c *Client) GetStorageBackupSchedule(ctx context.Context, storageID, scheduleID string) (StorageBackupSchedule, error) {
if !isValidUUID(storageID) || !isValidUUID(scheduleID) {
return StorageBackupSchedule{}, errors.New("'storageID' or 'scheduleID' is invalid")
}
r := gsRequest{
uri: path.Join(apiStorageBase, storageID, "backup_schedules", scheduleID),
method: http.MethodGet,
skipCheckingRequest: true,
}
var response StorageBackupSchedule
err := r.execute(ctx, *c, &response)
return response, err
}
// CreateStorageBackupSchedule creates a storage backup schedule based on a given storage UUID.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/getStorageBackupSchedule
func (c *Client) CreateStorageBackupSchedule(ctx context.Context, id string, body StorageBackupScheduleCreateRequest) (
StorageBackupScheduleCreateResponse, error) {
if !isValidUUID(id) {
return StorageBackupScheduleCreateResponse{}, errors.New("'id' is invalid")
}
r := gsRequest{
uri: path.Join(apiStorageBase, id, "backup_schedules"),
method: http.MethodPost,
body: body,
}
var response StorageBackupScheduleCreateResponse
err := r.execute(ctx, *c, &response)
return response, err
}
// UpdateStorageBackupSchedule updates a specific storage backup schedule based on a given storage's id and a backup schedule's id.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/updateStorageBackupSchedule
func (c *Client) UpdateStorageBackupSchedule(ctx context.Context, storageID, scheduleID string,
body StorageBackupScheduleUpdateRequest) error {
if !isValidUUID(storageID) || !isValidUUID(scheduleID) {
return errors.New("'storageID' or 'scheduleID' is invalid")
}
r := gsRequest{
uri: path.Join(apiStorageBase, storageID, "backup_schedules", scheduleID),
method: http.MethodPatch,
body: body,
}
return r.execute(ctx, *c, nil)
}
// DeleteStorageBackupSchedule removes a specific storage backup scheduler based on a given storage's id and a backup schedule's id.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/deleteStorageBackupSchedule
func (c *Client) DeleteStorageBackupSchedule(ctx context.Context, storageID, scheduleID string) error {
if !isValidUUID(storageID) || !isValidUUID(scheduleID) {
return errors.New("'storageID' or 'scheduleID' is invalid")
}
r := gsRequest{
uri: path.Join(apiStorageBase, storageID, "backup_schedules", scheduleID),
method: http.MethodDelete,
}
return r.execute(ctx, *c, nil)
}
// GetStorageBackupLocationList returns a list of available locations to store your backup.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/GetBackupLocations
func (c *Client) GetStorageBackupLocationList(ctx context.Context) ([]StorageBackupLocation, error) {
r := gsRequest{
uri: apiBackupLocationBase,
method: http.MethodGet,
skipCheckingRequest: true,
}
var response StorageBackupLocationList
var locationList []StorageBackupLocation
err := r.execute(ctx, *c, &response)
for _, locationProperties := range response.List {
locationList = append(locationList, StorageBackupLocation{
Properties: locationProperties,
})
}
return locationList, err
}