forked from opencurve/curve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_or_cancel_snap.py
65 lines (51 loc) · 1.79 KB
/
delete_or_cancel_snap.py
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
#!/usr/bin/env python
# coding=utf-8
import curltool
DELETESNAPSHOT = 'DeleteSnapshot'
CANCELSNAPSHOT = 'CancelSnapshot'
def __check_ok():
askRes = raw_input('are you sure to delete or cancel(yes/no):')
if askRes == 'yes':
return True
elif askRes == 'no':
return False
print('Please enter yes or no')
return False
def __print_records(records):
print('%d tasks list to be clean:' % len(records))
for record in records:
print('uuid=%s, user=%s, file=%s, status=%s' % (record['UUID'], record['User'], record['File'], record['Status']))
def __del_query(args):
status = None
if args.failed:
status = 5
totalCount, records = curltool.get_snapshot_list_all(args.user, args.filename, args.uuid, status)
if totalCount != 0:
__print_records(records)
return records
def __cancel_query(args):
totalCount, records = curltool.get_snapshot_list_all(args.user, args.filename, args.uuid)
if totalCount != 0:
__print_records(records)
return records
def _delete_or_cancel_snapshot_batch(method, records):
for item in records:
curltool.delete_or_cancel_snapshot(method, item['UUID'], item['User'], item['File'])
print('%s finished' % method)
def __send_request(method, records):
if (records is None) or len(records) == 0:
return
if __check_ok() == False:
return
_delete_or_cancel_snapshot_batch(method, records)
def __empty_records_print(records):
if (records is None) or len(records) == 0:
print('no eligible snapshot')
def delete_or_cancel_snapshot(method, args):
records = []
if method == DELETESNAPSHOT:
records = __del_query(args)
else:
records = __cancel_query(args)
__empty_records_print(records)
__send_request(method, records)