Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPure_Create_Volume.py
More file actions
Latest commit
156 lines (122 loc) · 4.44 KB
/
Copy pathPure_Create_Volume.py
File metadata and controls
156 lines (122 loc) · 4.44 KB
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
importpurestorage
importrequests
fromrequests.packages.urllib3.exceptionsimportInsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
frombase64importb64encode
importos
importsys
importjson
importgetpass
fromoptparseimportOptionParser
fromdatetimeimportdatetime, timedelta
importtime
fromtimeimportgmtime, strftime, strptime
fromoperatorimportitemgetter, attrgetter
# Global Variables
VERSION='1.1.0'
HEADER='Pure Storage Create Volume ('+VERSION+')'
BANNER= ('='*132)
DEBUG_LEVEL=0
VERBOSE_FLAG=False
COOKIE=''
defcreate_session(flashArray, user, password):
jsonData=purestorage.FlashArray(flashArray, user, password)
return(jsonData)
defparsecl():
usage='usage: %prog [options]'
version='%prog '+VERSION
description="This application has been developed using Pure Storage v1.4 RESTful Web Service interfaces. Developed and tested using Python 3.6 on Mac OS 10.12. Please contact ron@purestorage.com for assistance."
parser=OptionParser(usage=usage, version=version, description=description)
parser.add_option('-d', '--debug',
type='int',
dest='DEBUG_LEVEL',
default=0,
help='Debug level, used for HTTP debugging')
parser.add_option('-p', '--password',
action='store',
type='string',
dest='password',
help='Pure password')
parser.add_option('-s', '--server',
action='store',
type='string',
dest='flashArray',
help='Pure FlashArray')
parser.add_option('-S', '--size',
action='store',
type='string',
dest='size',
help='Volume size S,K,M,G,T,P')
parser.add_option('-u', '--user',
action='store',
type='string',
dest='user',
help='Pure user name')
parser.add_option('-v', '--verbose',
action='store_true',
dest='VERBOSE_FLAG',
default=False,
help='Verbose [default: %default]')
parser.add_option('-V', '--volume',
action='store',
dest='volume',
default=False,
help='Volume name')
(options, args) =parser.parse_args()
'''
print("Options:", options)
print("Args:", args)
'''
return(options)
defmain():
# Setup variables
globalDEBUG_LEVEL
exit_code=0
# Check for command line parameters
options=parsecl()
password=options.password
user=options.user
flashArray=options.flashArray
volsize=options.size
volume=options.volume
DEBUG_LEVEL=options.DEBUG_LEVEL
VERBOSE_FLAG=options.VERBOSE_FLAG
ifDEBUG_LEVEL!=0:
print('Password', password)
print('User', user)
print('Flash Array', flashArray)
print('Volume name', volume)
print('Volume size', volsize)
print('Debug Level:', DEBUG_LEVEL)
ifflashArray==None:
sys.exit('Exiting: You must provide FlashArray details')
ifuserandpassword==None:
sys.exit('Exiting: You must provide password if using username')
print(BANNER)
print(HEADER+' - '+flashArray)
print(strftime('%d/%m/%Y %H:%M:%S %Z', gmtime()))
print(BANNER)
# Create session
array=create_session(flashArray, user, password)
# Create Volume
jsonData=array.create_volume(volume, size=volsize)
ifVERBOSE_FLAG:
print(BANNER)
print(json.dumps(jsonData, sort_keys=False, indent=4))
name= (jsonData['name'])
size= (jsonData['size'])
cdate= (jsonData['created'])
c1=cdate[0:10]
c2=cdate[11:19]
c3=c1+' '+c2
c4=strptime(c3,'%Y-%m-%d %H:%M:%S')
created=strftime('%d/%m/%Y %H:%M:%S', c4)
print('{0:20} {1:>20} {2:20}'.format('Name', 'Size', 'Created'))
print('{0:20} {1:20} {2:20}'.format(name, size, created))
# Close API session
array.invalidate_cookie()
print(BANNER)
print(strftime('%d/%m/%Y %H:%M:%S %Z', gmtime()))
print(BANNER)
sys.exit(exit_code)
main()