def get(self, snapshot_id): snap = get_blueprints_manager().get_snapshot(snapshot_id) if snap.status == models.Snapshot.FAILED: raise manager_exceptions.SnapshotActionError( 'Failed snapshot cannot be downloaded') snapshot_path = os.path.join(_get_snapshot_path(snapshot_id), '{0}.zip'.format(snapshot_id)) snapshot_uri = '{0}/{1}/{2}/{2}.zip'.format( config.instance().file_server_resources_uri, config.instance().file_server_snapshots_folder, snapshot_id) return make_streaming_response(snapshot_id, snapshot_uri, os.path.getsize(snapshot_path), 'zip')
def get(self, snapshot_id): snap = get_storage_manager().get(models.Snapshot, snapshot_id) if snap.status == SnapshotState.FAILED: raise manager_exceptions.SnapshotActionError( 'Failed snapshot cannot be downloaded') snapshot_path = os.path.join(_get_snapshot_path(snapshot_id), '{0}.zip'.format(snapshot_id)) snapshot_uri = '{0}/{1}/{2}/{2}.zip'.format( FILE_SERVER_RESOURCES_FOLDER, FILE_SERVER_SNAPSHOTS_FOLDER, snapshot_id) return rest_utils.make_streaming_response( snapshot_id, snapshot_uri, os.path.getsize(snapshot_path), 'zip')
def restore_snapshot(self, snapshot_id, recreate_deployments_envs, force): # Throws error if no snapshot found snap = self.get_snapshot(snapshot_id) if snap.status == models.Snapshot.FAILED: raise manager_exceptions.SnapshotActionError( 'Failed snapshot cannot be restored' ) _, execution = self._execute_system_workflow( wf_id='restore_snapshot', task_mapping='cloudify_system_workflows.snapshot.restore', execution_parameters={ 'snapshot_id': snapshot_id, 'recreate_deployments_envs': recreate_deployments_envs, 'config': self._get_conf_for_snapshots_wf(), 'force': force } ) return execution
def delete(self, snapshot_id): sm = get_storage_manager() snapshot = sm.get(models.Snapshot, snapshot_id) ongoing_snapshot_execs = sm.list( models.Execution, get_all_results=True, filters={ 'workflow_id': ['create_snapshot', 'restore_snapshot'], 'status': ExecutionState.ACTIVE_STATES, }) for execution in ongoing_snapshot_execs: if execution.parameters.get('snapshot_id') == snapshot_id: raise manager_exceptions.SnapshotActionError( f'Cannot delete snapshot `{snapshot_id}` which has an ' f'active `{execution.workflow_id}` execution') sm.delete(snapshot) path = _get_snapshot_path(snapshot_id) shutil.rmtree(path, ignore_errors=True) return snapshot, 200