-
Notifications
You must be signed in to change notification settings - Fork 1
/
snapomatic.volume
executable file
·144 lines (130 loc) · 4.22 KB
/
snapomatic.volume
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
#! /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 getVolumes import getVolumes
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" + \
"volume show\n" + \
" --target\n" + \
" (syntax: svm volume(s))\n\n" + \
" --cg\n" + \
" (restrict output to consistency group volumes)\n\n" + \
"volume clone\n" + \
" --target\n" + \
" (svm volume)\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:
volumes='*'
else:
volumes=myopts.target[1:]
if myopts.mode == 'clone':
if not len(myopts.target) == 2:
userio.fail(usage)
else:
volume=myopts.target[1]
if myopts.mode == 'show':
if cg:
volumes=getCGs(svm,volumes=volumes,debug=debug)
else:
volumes=getVolumes(svm,volumes=volumes,debug=debug)
if not volumes.go():
userio.message(volumes.reason)
sys.exit(1)
else:
if cg:
grid=[['CG','Parent','Volume','Size (GB)','Aggregate']]
cglist=list(volumes.cgs.keys())
cglist.sort()
for cg in cglist:
try:
parentfield=volumes.cgs[cg]['parent']
except:
parentfield='-'
volumelist=volumes.cgs[cg]['volumes']
volumelist.sort()
for volume in volumelist:
grid.append([cg,
parentfield,
volume,
str(volumes.volumes[volume]['size']/1048576),
volumes.volumes[volume]['aggrs'],
])
else:
grid=[['Volume','Size (GB)','Aggregate']]
volumelist=list(volumes.volumes.keys())
volumelist.sort()
for volume in volumelist:
grid.append([volume,
str(volumes.volumes[volume]['size']/1048576),
volumes.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)