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_FBSnap.py
More file actions
Latest commit
143 lines (109 loc) · 4.19 KB
/
Copy pathPure_Create_FBSnap.py
File metadata and controls
143 lines (109 loc) · 4.19 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
frompurity_fbimportPurityFb, FileSystem, FileSystemSnapshot, SnapshotSuffix, rest
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.0.0'
HEADER='Pure Storage Take FileSystem Snapshot ('+VERSION+')'
BANNER= ('='*132)
DEBUG_LEVEL=0
VERBOSE_FLAG=False
COOKIE=''
defcreate_session(flashBlade, token ):
fb=PurityFb(flashBlade)
# Disable SSL verification
fb.disable_verify_ssl()
fb.login(token) # login to the array with your API_TOKEN
return(fb)
defparsecl():
usage='usage: %prog [options]'
version='%prog '+VERSION
description="This python script creates a Pure Storage FlashBlade Snapshot, you need to provide FlashBlade details and file system name, the suffix is optional. This application has been developed using Pure Storage v1.8 FlashBlade RESTful Web Service interfaces. Please contact ron@purestorage.com for assistance."
parser=OptionParser(usage=usage, version=version, description=description)
parser.add_option('-s', '--server',
action='store',
type='string',
dest='flashBlade',
help='Pure FlashBlade')
parser.add_option('-t', '--token',
action='store',
type='string',
dest='token',
help='Pure FlashBlade user token')
parser.add_option('-f', '--filesys',
action='store',
type='string',
dest='filesys',
help='Pure FlashBlade file system')
parser.add_option('-S', '--suffix',
action='store',
type='string',
dest='suffix',
help='Pure FlashBlade snapshot suffix')
parser.add_option('-v', '--verbose',
action='store_true',
dest='VERBOSE_FLAG',
default=False,
help='Verbose [default: %default]')
(options, args) =parser.parse_args()
'''
print("Options:", options)
print("Args:", args)
'''
return(options)
defmain():
# Setup variables
globalDEBUG_LEVEL
globalVERBOSE_FLAG
exit_code=0
# Check for command line parameters
options=parsecl()
flashBlade=options.flashBlade
token=options.token
filesys=options.filesys
suffix=options.suffix
VERBOSE_FLAG=options.VERBOSE_FLAG
ifVERBOSE_FLAG:
print('FlashBlade:', flashBlade)
print('FlashBlade Token:', token)
print('File System:', filesys)
print('Suffix:', suffix)
print('Debug Level:', DEBUG_LEVEL)
print('Verbose Flag:', VERBOSE_FLAG)
ifflashBlade==None:
sys.exit('Exiting: You must provide FlashBlade details')
iftoken==None:
sys.exit('Exiting: You must provide FlashBlade token')
iffilesys==None:
sys.exit('Exiting: You must specify a FlashBlade File System')
print(BANNER)
print(HEADER+' - '+flashBlade)
print(strftime('%d/%m/%Y %H:%M:%S %Z', gmtime()))
print(BANNER)
# Create FlashBlade session
fb=create_session(flashBlade, token)
# Create FileSystem Snapshot
ifsuffix==None:
epoch=int(time.time())
suffix='SNAP-'+str(epoch)
created= (strftime('%d/%m/%Y %H:%M:%S %Z', gmtime()))
# Create Snaphost
res=fb.file_system_snapshots.create_file_system_snapshots(sources=[filesys], suffix=SnapshotSuffix(suffix))
ifVERBOSE_FLAG:
print(BANNER)
print("res:", res.items)
print('{0:40} {1:60} {2:20}'.format('Source', 'Suffix', 'Created'))
print('{0:40} {1:60} {2:20}'.format(filesys, suffix, created))
print(BANNER)
sys.exit(exit_code)
main()