def main(): # Setup variables global DEBUG_LEVEL global VERBOSE_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 if VERBOSE_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) if flashBlade == None: sys.exit('Exiting: You must provide FlashBlade details') if token == None: sys.exit('Exiting: You must provide FlashBlade token') if filesys == 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 if suffix == 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)) if VERBOSE_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)
def create_snapshot(module, blade): """Create Snapshot""" if not module.check_mode: source = [] source.append(module.params['name']) try: blade.file_system_snapshots.create_file_system_snapshots( sources=source, suffix=SnapshotSuffix(module.params['suffix'])) changed = True except Exception: changed = False module.exit_json(changed=changed)
def snap_create(name, suffix=None): """ Create a filesystem snapshot on a Pure Storage FlashBlade. Will return False if filesystem selected to snap does not exist. .. versionadded:: 2019.2.0 name : string name of filesystem to snapshot suffix : string if specificed forces snapshot name suffix. If not specified defaults to timestamp. CLI Example: .. code-block:: bash salt '*' purefb.snap_create foo salt '*' purefb.snap_create foo suffix=bar """ blade = _get_blade() if suffix is None: suffix = "snap-" + str( (datetime.utcnow() - datetime(1970, 1, 1, 0, 0, 0, 0)).total_seconds() ) suffix = suffix.replace(".", "") if _get_fs(name, blade) is not None: try: source = [] source.append(name) blade.file_system_snapshots.create_file_system_snapshots( sources=source, suffix=SnapshotSuffix(suffix) ) return True except rest.ApiException: return False else: return False
def main(): # Setup variables global DEBUG_FLAG exit_code = 0 # Check for command line parameters options = parsecl() API_TOKEN = options.API_TOKEN flashBlade = options.flashBlade fs = options.fs suffix = options.suffix DEBUG_FLAG = options.DEBUG_FLAG VERBOSE_FLAG = options.VERBOSE_FLAG if DEBUG_FLAG: print('API Token:', API_TOKEN) print('FlashBlade:', flashBlade) print('File System:', fs) print('Suffix:', suffix) print('Debug Flag:', DEBUG_FLAG) print('Verbose Flag:', VERBOSE_FLAG) if flashBlade == None: sys.exit('Exiting: You must provide FlashBlade details') if API_TOKEN == None: sys.exit('Exiting: You must provide FlashBlade API Token details') if fs == None: sys.exit('Exiting: You must provide FlashBlade file system') print(BANNER) print(HEADER + ' - ' + flashBlade) print(strftime('%d/%m/%Y %H:%M:%S %Z', gmtime())) print(BANNER) # create PurityFb object for a certain array fb = PurityFb(flashBlade) # this is required for versions before Purity//FB 2.1.3 because they only supports self-signed # certificates. in later versions, this may be unnecessary if you have imported a certificate. fb.disable_verify_ssl() try: res= fb.login(API_TOKEN) except rest.ApiException as e: print("Exception when logging in to the array: %s\n" % e) if res: try: if suffix: # create a snapshot with suffix for flashblade file system res = fb.file_system_snapshots.create_file_system_snapshots(sources=[fs], suffix=SnapshotSuffix(suffix)) else: # create a snapshot for the file system res = fb.file_system_snapshots.create_file_system_snapshots(sources=[fs]) if VERBOSE_FLAG: print(res) print('Snapshot created for', fs, 'suffix', res.items[0].suffix) except rest.ApiException as e: print("Exception when creating file system snapshots: %s\n" % e) fb.logout() print(BANNER) print(strftime('%d/%m/%Y %H:%M:%S %Z', gmtime())) print(BANNER) sys.exit(exit_code)