/
backup_and_restore.go
367 lines (294 loc) · 18.3 KB
/
backup_and_restore.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
package isegosdk
import (
"fmt"
"github.com/go-resty/resty/v2"
)
type BackupAndRestoreService service
type ResponseBackupAndRestoreConfigBackup struct {
Response *ResponseBackupAndRestoreConfigBackupResponse `json:"response,omitempty"` //
Version string `json:"version,omitempty"` //
}
type ResponseBackupAndRestoreConfigBackupResponse struct {
ID string `json:"id,omitempty"` // Id which can be used to track the status of backup / restore of config DB.
Message string `json:"message,omitempty"` //
Link *ResponseBackupAndRestoreConfigBackupResponseLink `json:"link,omitempty"` //
}
type ResponseBackupAndRestoreConfigBackupResponseLink struct {
Rel string `json:"rel,omitempty"` //
Href string `json:"href,omitempty"` //
Type string `json:"type,omitempty"` //
}
type ResponseBackupAndRestoreCancelBackup struct {
Response *ResponseBackupAndRestoreCancelBackupResponse `json:"response,omitempty"` //
Version string `json:"version,omitempty"` //
}
type ResponseBackupAndRestoreCancelBackupResponse struct {
Action string `json:"action,omitempty"` //
Details string `json:"details,omitempty"` // Details of the job
Error string `json:"error,omitempty"` // Error message. False in case of no error
HostName string `json:"hostName,omitempty"` // Hostname where the job has executed
InitiatedFrom string `json:"initiatedFrom,omitempty"` //
JustComplete string `json:"justComplete,omitempty"` // Whether the job completed now. Possible values - Yes, No
Message string `json:"message,omitempty"` // detail message in case of exception
Name string `json:"name,omitempty"` // Backup name given at the time of scheduling the job.
PercentComplete string `json:"percentComplete,omitempty"` // shows the percent completion of the job. Possible value range 1 - 100
Repository string `json:"repository,omitempty"` // configured repository selected for the backup / restore job
Scheduled string `json:"scheduled,omitempty"` // last action performed with respect to backup job. Possible values- BACKUP , CANCEL
StartDate string `json:"startDate,omitempty"` // Start date of the backup job
Status string `json:"status,omitempty"` //
Type string `json:"type,omitempty"` //
}
type ResponseBackupAndRestoreGetLastConfigBackupStatus struct {
Response *ResponseBackupAndRestoreGetLastConfigBackupStatusResponse `json:"response,omitempty"` //
Version string `json:"version,omitempty"` //
}
type ResponseBackupAndRestoreGetLastConfigBackupStatusResponse struct {
Action string `json:"action,omitempty"` //
Details string `json:"details,omitempty"` // Details of the job
Error string `json:"error,omitempty"` // Error message. False in case of no error
HostName string `json:"hostName,omitempty"` // Hostname where the job has executed
InitiatedFrom string `json:"initiatedFrom,omitempty"` //
JustComplete string `json:"justComplete,omitempty"` // Whether the job completed now. Possible values - Yes, No
Message string `json:"message,omitempty"` // detail message in case of exception
Name string `json:"name,omitempty"` // Backup name given at the time of scheduling the job.
PercentComplete string `json:"percentComplete,omitempty"` // shows the percent completion of the job. Possible value range 1 - 100
Repository string `json:"repository,omitempty"` // configured repository selected for the backup / restore job
Scheduled string `json:"scheduled,omitempty"` // last action performed with respect to backup job. Possible values- BACKUP , CANCEL
StartDate string `json:"startDate,omitempty"` // Start date of the backup job
Status string `json:"status,omitempty"` //
Type string `json:"type,omitempty"` //
}
type ResponseBackupAndRestoreRestoreConfigBackup struct {
Response *ResponseBackupAndRestoreRestoreConfigBackupResponse `json:"response,omitempty"` //
Version string `json:"version,omitempty"` //
}
type ResponseBackupAndRestoreRestoreConfigBackupResponse struct {
ID string `json:"id,omitempty"` // Id which can be used to track the status of backup / restore of config DB.
Message string `json:"message,omitempty"` //
Link *ResponseBackupAndRestoreRestoreConfigBackupResponseLink `json:"link,omitempty"` //
}
type ResponseBackupAndRestoreRestoreConfigBackupResponseLink struct {
Rel string `json:"rel,omitempty"` //
Href string `json:"href,omitempty"` //
Type string `json:"type,omitempty"` //
}
type ResponseBackupAndRestoreUpdateScheduledConfigBackup struct {
Response *ResponseBackupAndRestoreUpdateScheduledConfigBackupResponse `json:"response,omitempty"` //
Version string `json:"version,omitempty"` //
}
type ResponseBackupAndRestoreUpdateScheduledConfigBackupResponse struct {
Message string `json:"message,omitempty"` // Response message on successful scheduling the backup job.
Link *ResponseBackupAndRestoreUpdateScheduledConfigBackupResponseLink `json:"link,omitempty"` //
}
type ResponseBackupAndRestoreUpdateScheduledConfigBackupResponseLink struct {
Rel string `json:"rel,omitempty"` //
Href string `json:"href,omitempty"` //
Type string `json:"type,omitempty"` //
}
type ResponseBackupAndRestoreCreateScheduledConfigBackup struct {
Response *ResponseBackupAndRestoreCreateScheduledConfigBackupResponse `json:"response,omitempty"` //
Version string `json:"version,omitempty"` //
}
type ResponseBackupAndRestoreCreateScheduledConfigBackupResponse struct {
Message string `json:"message,omitempty"` // Response message on successful scheduling the backup job.
Link *ResponseBackupAndRestoreCreateScheduledConfigBackupResponseLink `json:"link,omitempty"` //
}
type ResponseBackupAndRestoreCreateScheduledConfigBackupResponseLink struct {
Rel string `json:"rel,omitempty"` //
Href string `json:"href,omitempty"` //
Type string `json:"type,omitempty"` //
}
type RequestBackupAndRestoreConfigBackup struct {
BackupEncryptionKey string `json:"backupEncryptionKey,omitempty"` // The encyption key for the backed up file. Encryption key must satisfy the following criteria - Contains at least one uppercase letter [A-Z], Contains at least one lowercase letter [a-z], Contains at least one digit [0-9], Contain only [A-Z][a-z][0-9]_#, Has at least 8 characters, Has not more than 15 characters, Must not contain 'CcIiSsCco', Must not begin with
BackupName string `json:"backupName,omitempty"` // The backup file will get saved with this name.
RepositoryName string `json:"repositoryName,omitempty"` // Name of the configured repository where the generated backup file will get copied.
}
type RequestBackupAndRestoreRestoreConfigBackup struct {
BackupEncryptionKey string `json:"backupEncryptionKey,omitempty"` // The encryption key which was provided at the time of taking backup.
RepositoryName string `json:"repositoryName,omitempty"` // Name of the configred repository where the backup file exists.
RestoreFile string `json:"restoreFile,omitempty"` // Name of the backup file to be restored on ISE node.
RestoreIncludeAdeos string `json:"restoreIncludeAdeos,omitempty"` // Determines whether the ADE-OS configure is restored. Possible values true, false
}
type RequestBackupAndRestoreUpdateScheduledConfigBackup struct {
BackupDescription string `json:"backupDescription,omitempty"` // Description of the backup.
BackupEncryptionKey string `json:"backupEncryptionKey,omitempty"` // The encyption key for the backed up file. Encryption key must satisfy the following criteria - Contains at least one uppercase letter [A-Z], Contains at least one lowercase letter [a-z], Contains at least one digit [0-9], Contain only [A-Z][a-z][0-9]_#, Has at least 8 characters, Has not more than 15 characters, Must not contain 'CcIiSsCco', Must not begin with
BackupName string `json:"backupName,omitempty"` // The backup file will get saved with this name.
EndDate string `json:"endDate,omitempty"` // End date of the scheduled backup job. Allowed format MM/DD/YYYY. End date is not required in case of ONE_TIME frequency.
Frequency string `json:"frequency,omitempty"` //
MonthDay string `json:"monthDay,omitempty"` // Day of month you want backup to be performed on when scheduled frequency is MONTHLY. Allowed values - from 1 to 28.
RepositoryName string `json:"repositoryName,omitempty"` // Name of the configured repository where the generated backup file will get copied.
StartDate string `json:"startDate,omitempty"` // Start date for scheduling the backup job. Allowed format MM/DD/YYYY.
Status string `json:"status,omitempty"` //
Time string `json:"time,omitempty"` // Time at which backup job get scheduled. example- 12:00 AM
WeekDay string `json:"weekDay,omitempty"` //
}
type RequestBackupAndRestoreCreateScheduledConfigBackup struct {
BackupDescription string `json:"backupDescription,omitempty"` // Description of the backup.
BackupEncryptionKey string `json:"backupEncryptionKey,omitempty"` // The encyption key for the backed up file. Encryption key must satisfy the following criteria - Contains at least one uppercase letter [A-Z], Contains at least one lowercase letter [a-z], Contains at least one digit [0-9], Contain only [A-Z][a-z][0-9]_#, Has at least 8 characters, Has not more than 15 characters, Must not contain 'CcIiSsCco', Must not begin with
BackupName string `json:"backupName,omitempty"` // The backup file will get saved with this name.
EndDate string `json:"endDate,omitempty"` // End date of the scheduled backup job. Allowed format MM/DD/YYYY. End date is not required in case of ONE_TIME frequency.
Frequency string `json:"frequency,omitempty"` //
MonthDay string `json:"monthDay,omitempty"` // Day of month you want backup to be performed on when scheduled frequency is MONTHLY. Allowed values - from 1 to 28.
RepositoryName string `json:"repositoryName,omitempty"` // Name of the configured repository where the generated backup file will get copied.
StartDate string `json:"startDate,omitempty"` // Start date for scheduling the backup job. Allowed format MM/DD/YYYY.
Status string `json:"status,omitempty"` //
Time string `json:"time,omitempty"` // Time at which backup job get scheduled. example- 12:00 AM
WeekDay string `json:"weekDay,omitempty"` //
}
//GetLastConfigBackupStatus Gives the last backup status
/* Gives the last backup status
*/
func (s *BackupAndRestoreService) GetLastConfigBackupStatus() (*ResponseBackupAndRestoreGetLastConfigBackupStatus, *resty.Response, error) {
setHost(s.client, "_ui")
path := "/api/v1/backup-restore/config/last-backup-status"
setCSRFToken(s.client)
response, err := s.client.R().
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json").
SetResult(&ResponseBackupAndRestoreGetLastConfigBackupStatus{}).
SetError(&Error).
Get(path)
if err != nil {
return nil, nil, err
}
if response.IsError() {
return nil, response, fmt.Errorf("error with operation GetLastConfigBackupStatus")
}
getCSFRToken(response.Header())
result := response.Result().(*ResponseBackupAndRestoreGetLastConfigBackupStatus)
return result, response, err
}
//ConfigBackup Take the config DB backup now by providing the name of the backup,repository name and encryption key. The API returns the task ID. Use the Task Service status API to get the status of the backup job
/* Triggers on demand configuration backup on the ISE node. The API returns the task ID. Use the Task Service status API to get the status of the backup job.
*/
func (s *BackupAndRestoreService) ConfigBackup(requestBackupAndRestoreConfigBackup *RequestBackupAndRestoreConfigBackup) (*ResponseBackupAndRestoreConfigBackup, *resty.Response, error) {
setHost(s.client, "_ui")
path := "/api/v1/backup-restore/config/backup"
setCSRFToken(s.client)
response, err := s.client.R().
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json").
SetBody(requestBackupAndRestoreConfigBackup).
SetResult(&ResponseBackupAndRestoreConfigBackup{}).
SetError(&Error).
Post(path)
if err != nil {
if err.Error() == emptyStringToJSONError {
return &ResponseBackupAndRestoreConfigBackup{}, response, nil
}
return nil, nil, err
}
getCSFRToken(response.Header())
if response.IsError() {
return nil, response, fmt.Errorf("error with operation ConfigBackup")
}
result := response.Result().(*ResponseBackupAndRestoreConfigBackup)
return result, response, err
}
//CancelBackup Cancel the running backup
/* Cancels the backup job running on the node.
*/
func (s *BackupAndRestoreService) CancelBackup() (*ResponseBackupAndRestoreCancelBackup, *resty.Response, error) {
setHost(s.client, "_ui")
path := "/api/v1/backup-restore/config/cancel-backup"
setCSRFToken(s.client)
response, err := s.client.R().
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json").
SetResult(&ResponseBackupAndRestoreCancelBackup{}).
SetError(&Error).
Post(path)
if err != nil {
if err.Error() == emptyStringToJSONError {
return &ResponseBackupAndRestoreCancelBackup{}, response, nil
}
return nil, nil, err
}
getCSFRToken(response.Header())
if response.IsError() {
return nil, response, fmt.Errorf("error with operation CancelBackup")
}
result := response.Result().(*ResponseBackupAndRestoreCancelBackup)
return result, response, err
}
//RestoreConfigBackup Restore a config DB backup by giving the name of the backup file, repository name and encryption key. The API returns the task ID. Use the Task Service status API to get the status of the restore job
/* Triggers a configuration DB restore job on the ISE node. The API returns the task ID. Use the Task Service status API to get the status of the backup job
*/
func (s *BackupAndRestoreService) RestoreConfigBackup(requestBackupAndRestoreRestoreConfigBackup *RequestBackupAndRestoreRestoreConfigBackup) (*ResponseBackupAndRestoreRestoreConfigBackup, *resty.Response, error) {
setHost(s.client, "_ui")
path := "/api/v1/backup-restore/config/restore"
setCSRFToken(s.client)
response, err := s.client.R().
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json").
SetBody(requestBackupAndRestoreRestoreConfigBackup).
SetResult(&ResponseBackupAndRestoreRestoreConfigBackup{}).
SetError(&Error).
Post(path)
if err != nil {
if err.Error() == emptyStringToJSONError {
return &ResponseBackupAndRestoreRestoreConfigBackup{}, response, nil
}
return nil, nil, err
}
getCSFRToken(response.Header())
if response.IsError() {
return nil, response, fmt.Errorf("error with operation RestoreConfigBackup")
}
result := response.Result().(*ResponseBackupAndRestoreRestoreConfigBackup)
return result, response, err
}
//CreateScheduledConfigBackup Schedules the configuration backup on the ISE node as per the input parameters.
/* Schedules the configuration backup on the ISE node as per the input parameters. This API helps in creating the schedule for the first time.
*/
func (s *BackupAndRestoreService) CreateScheduledConfigBackup(requestBackupAndRestoreCreateScheduledConfigBackup *RequestBackupAndRestoreCreateScheduledConfigBackup) (*ResponseBackupAndRestoreCreateScheduledConfigBackup, *resty.Response, error) {
setHost(s.client, "_ui")
path := "/api/v1/backup-restore/config/schedule-config-backup"
setCSRFToken(s.client)
response, err := s.client.R().
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json").
SetBody(requestBackupAndRestoreCreateScheduledConfigBackup).
SetResult(&ResponseBackupAndRestoreCreateScheduledConfigBackup{}).
SetError(&Error).
Post(path)
if err != nil {
if err.Error() == emptyStringToJSONError {
return &ResponseBackupAndRestoreCreateScheduledConfigBackup{}, response, nil
}
return nil, nil, err
}
getCSFRToken(response.Header())
if response.IsError() {
return nil, response, fmt.Errorf("error with operation CreateScheduledConfigBackup")
}
result := response.Result().(*ResponseBackupAndRestoreCreateScheduledConfigBackup)
return result, response, err
}
//UpdateScheduledConfigBackup Update scheduled configuration backup
/* Update the Schedule of the configuration backup on the ISE node as per the input parameters. This API only helps in editing the schedule.
*/
func (s *BackupAndRestoreService) UpdateScheduledConfigBackup(requestBackupAndRestoreUpdateScheduledConfigBackup *RequestBackupAndRestoreUpdateScheduledConfigBackup) (*ResponseBackupAndRestoreUpdateScheduledConfigBackup, *resty.Response, error) {
setHost(s.client, "_ui")
path := "/api/v1/backup-restore/config/schedule-config-backup"
setCSRFToken(s.client)
response, err := s.client.R().
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json").
SetBody(requestBackupAndRestoreUpdateScheduledConfigBackup).
SetResult(&ResponseBackupAndRestoreUpdateScheduledConfigBackup{}).
SetError(&Error).
Put(path)
if err != nil {
if err.Error() == emptyStringToJSONError {
return &ResponseBackupAndRestoreUpdateScheduledConfigBackup{}, response, nil
}
return nil, nil, err
}
if response.IsError() {
return nil, response, fmt.Errorf("error with operation UpdateScheduledConfigBackup")
}
getCSFRToken(response.Header())
result := response.Result().(*ResponseBackupAndRestoreUpdateScheduledConfigBackup)
return result, response, err
}