-
Notifications
You must be signed in to change notification settings - Fork 1
/
snapomatic.cg
executable file
·134 lines (120 loc) · 3.74 KB
/
snapomatic.cg
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
#! /usr/bin/python3
import sys
pythonversion=sys.version_info
if pythonversion[0] != 3 or pythonversion[1] < 6:
print("This script requires Python 3.6 or higher")
sys.exit(1)
import os
import getopt
sys.path.append(sys.path[0] + "/NTAPlib")
from cloneVolumes import cloneVolumes
from getCGs import getCGs
import userio
snapomaticversion='dev'
validoptions={'clone' : {'target':'multistr', \
'name':'str', \
'snapshot':'str', \
'split':'bool', \
'debug':'bool', \
'restdebug':'bool'}, \
'show' : {'target':'multistr', \
'cg':'bool', \
'debug':'bool', \
'restdebug':'bool'}}
requiredoptions={'clone':['target','name'], \
'show':['target']}
usage="Version " + snapomaticversion + "\n" + \
"cg show\n" + \
" --target\n" + \
" (syntax: svm cg(s))\n\n" + \
"cg clone\n" + \
" --target\n" + \
" (svm )\n\n" + \
" --name\n" + \
" (name for the clone)\n\n" + \
" --snapshot\n" + \
" (OPTIONAL: name of the parent snapshot)\n\n" + \
" --split\n" + \
" (OPTIONAL: split the clone from parent)\n\n" + \
" [--debug]\n" + \
" (show debug output)\n\n" + \
" [--restdebug]\n" + \
" (show REST API calls and responses)\n\n"
myopts=userio.validateoptions(sys.argv,validoptions,usage=usage,required=requiredoptions)
try:
snapshot=myopts.snapshot
except:
snapshot=False
try:
split=myopts.split
except:
split=False
try:
name=myopts.name
except:
pass
debug=0
if myopts.debug:
debug=debug+1
if myopts.restdebug:
debug=debug+2
try:
cg=myopts.cg
except:
cg=False
svm=myopts.target[0]
if len(myopts.target) == 1:
cgs='*'
else:
cgs=myopts.target[1:]
if myopts.mode == 'clone':
if not len(myopts.target) == 2:
userio.fail(usage)
else:
cgs=myopts.target[1]
if myopts.mode == 'show':
knowncgs=getCGs(svm,name=cgs,debug=debug)
if not knowncgs.go():
userio.message(knowncgs.reason)
sys.exit(1)
else:
grid=[['CG','Parent','Children','Volume','Size (GB)','Aggregate']]
cglist=list(knowncgs.cgs.keys())
cglist.sort()
for cg in cglist:
try:
parentfield=knowncgs.cgs[cg]['parent']
except:
parentfield='-'
try:
childrenfield=join(','),knowncgs.cgs[cg]['children']
except:
childrenfield='-'
volumelist=knowncgs.cgs[cg]['volumes']
volumelist.sort()
for volume in volumelist:
grid.append([cg,
parentfield,
childrenfield,
volume,
str(knowncgs.volumes[volume]['size']/1048576),
knowncgs.volumes[volume]['aggrs'],
])
userio.grid(grid)
elif myopts.mode == 'clone':
if snapshot:
clone=cloneVolumes(svm,(volume,name,snapshot),split=split,debug=debug)
else:
clone=cloneVolumes(svm,(volume,name),split=split,debug=debug)
if not clone.go():
userio.message(clone.reason)
sys.exit(1)
else:
message="Cloned "
if split and name not in clone.unsplit:
message = message + "and split "
message=message + name + " from " + volume
if snapshot:
message=message + ":" + snapshot
userio.message(message)
sys.exit(0)