def bulk_submit(cls, imports, api=None): """ Submit imports in bulk :param imports: List of dicts describing a wanted import. :param api: Api instance. :return: List of ImportBulkRecord objects. """ if not imports: raise SbgError('Imports are required') api = api or cls._API items = [] for import_ in imports: project = import_.get('project') parent = import_.get('parent') if project and parent: raise SbgError( 'Project and parent identifiers are mutually exclusive') elif project: destination = {'project': Transform.to_project(project)} elif parent: destination = {'parent': Transform.to_file(parent)} else: raise SbgError('Project or parent identifier is required.') volume = Transform.to_volume(import_.get('volume')) location = Transform.to_location(import_.get('location')) name = import_.get('name', None) overwrite = import_.get('overwrite', False) autorename = import_.get('autorename', None) preserve_folder_structure = import_.get( 'preserve_folder_structure', None) if name: destination['name'] = name import_config = { 'source': { 'volume': volume, 'location': location }, 'destination': destination, 'overwrite': overwrite, } if autorename is not None: import_config['autorename'] = autorename if preserve_folder_structure is not None: import_config['preserve_folder_structure'] = ( preserve_folder_structure) items.append(import_config) data = {'items': items} response = api.post(url=cls._URL['bulk_create'], data=data) return ImportBulkRecord.parse_records(response=response, api=api)
def bulk_submit(cls, exports, copy_only=False, api=None): """ Create exports in bulk. :param exports: List of dicts describing a wanted export. :param copy_only: If true files are kept on SevenBridges bucket. :param api: Api instance. :return: list of ExportBulkRecord objects. """ if not exports: raise SbgError('Exports are required') api = api or cls._API items = [] for export in exports: file_ = Transform.to_file(export.get('file')) volume = Transform.to_volume(export.get('volume')) location = Transform.to_location(export.get('location')) properties = export.get('properties', {}) overwrite = export.get('overwrite', False) item = { 'source': { 'file': file_ }, 'destination': { 'volume': volume, 'location': location }, 'properties': properties, 'overwrite': overwrite } items.append(item) data = {'items': items} params = {'copy_only': copy_only} response = api.post(url=cls._URL['bulk_create'], params=params, data=data) return ExportBulkRecord.parse_records(response=response, api=api)
def bulk_submit(cls, exports, copy_only=False, api=None): """ Create exports in bulk. :param exports: Exports to be submitted in bulk. :param copy_only: If true files are kept on SevenBridges bucket. :param api: Api instance. :return: list of ExportBulkRecord objects. """ if not exports: raise SbgError('Exports are required') api = api or cls._API items = [] for export in exports: file_ = Transform.to_file(export.get('file')) volume = Transform.to_volume(export.get('volume')) location = Transform.to_location(export.get('location')) properties = export.get('properties', {}) overwrite = export.get('overwrite', False) item = { 'source': { 'file': file_ }, 'destination': { 'volume': volume, 'location': location }, 'properties': properties, 'overwrite': overwrite } items.append(item) data = {'items': items} params = {'copy_only': copy_only} response = api.post( url=cls._URL['bulk_create'], params=params, data=data ) return ExportBulkRecord.parse_records(response=response, api=api)
def bulk_submit(cls, imports, api=None): """ Submit imports in bulk :param imports: Imports to be retrieved. :param api: Api instance. :return: List of ImportBulkRecord objects. """ if not imports: raise SbgError('Imports are required') api = api or cls._API items = [] for import_ in imports: volume = Transform.to_volume(import_.get('volume')) location = Transform.to_location(import_.get('location')) project = Transform.to_project(import_.get('project')) name = import_.get('name', None) overwrite = import_.get('overwrite', False) item = { 'source': { 'volume': volume, 'location': location }, 'destination': { 'project': project }, 'overwrite': overwrite } if name: item['destination']['name'] = name items.append(item) data = {'items': items} response = api.post(url=cls._URL['bulk_create'], data=data) return ImportBulkRecord.parse_records(response=response, api=api)
def bulk_submit(cls, exports, api=None): """ Create exports in bulk. :param exports: Exports to be submitted in bulk. :param api: Api instance. :return: list of ExportBulkRecord objects. """ if not exports: raise SbgError('Exports are required') api = api or cls._API items = [] for export in exports: file_ = Transform.to_file(export.get('file')) volume = Transform.to_volume(export.get('volume')) location = Transform.to_location(export.get('location')) properties = export.get('properties', {}) overwrite = export.get('overwrite', False) item = { 'source': { 'file': file_ }, 'destination': { 'volume': volume, 'location': location }, 'properties': properties, 'overwrite': overwrite } items.append(item) data = {'items': items} response = api.post(url=cls._URL['bulk_create'], data=data) return ExportBulkRecord.parse_records(response=response, api=api)