def staging_store_path(): """Return the local path to the staging store. :raises: GlanceException if staging store is not configured to be a file:// URI """ if CONF.enabled_backends: separator, staging_dir = store_utils.get_dir_separator() else: staging_dir = CONF.node_staging_uri expected_prefix = 'file://' if not staging_dir.startswith(expected_prefix): raise exception.GlanceException('Unexpected scheme in staging store; ' 'unable to scan for residue') return staging_dir[len(expected_prefix):]
def get_flow(**kwargs): """Return task flow :param task_id: Task ID :param task_type: Type of the task :param task_repo: Task repo :param image_repo: Image repository used :param image_id: ID of the Image to be processed :param uri: uri for the image file """ task_id = kwargs.get('task_id') task_type = kwargs.get('task_type') task_repo = kwargs.get('task_repo') image_repo = kwargs.get('image_repo') image_id = kwargs.get('image_id') import_method = kwargs.get('import_req')['method']['name'] uri = kwargs.get('import_req')['method'].get('uri') backend = kwargs.get('backend') separator = '' if not CONF.enabled_backends and not CONF.node_staging_uri.endswith('/'): separator = '/' if not uri and import_method == 'glance-direct': if CONF.enabled_backends: separator, staging_dir = store_utils.get_dir_separator() uri = separator.join((staging_dir, str(image_id))) else: uri = separator.join((CONF.node_staging_uri, str(image_id))) flow = lf.Flow(task_type, retry=retry.AlwaysRevert()) if import_method == 'web-download': downloadToStaging = internal_plugins.get_import_plugin(**kwargs) flow.add(downloadToStaging) if CONF.enabled_backends: separator, staging_dir = store_utils.get_dir_separator() file_uri = separator.join((staging_dir, str(image_id))) else: file_uri = separator.join((CONF.node_staging_uri, str(image_id))) else: file_uri = uri flow.add(_VerifyStaging(task_id, task_type, task_repo, file_uri)) for plugin in import_plugins.get_import_plugins(**kwargs): flow.add(plugin) import_to_store = _ImportToStore(task_id, task_type, image_repo, file_uri, image_id, backend) flow.add(import_to_store) delete_task = lf.Flow(task_type).add(_DeleteFromFS(task_id, task_type)) flow.add(delete_task) save_task = _SaveImage(task_id, task_type, image_repo, image_id) flow.add(save_task) complete_task = _CompleteTask(task_id, task_type, task_repo, image_id) flow.add(complete_task) image = image_repo.get(image_id) from_state = image.status image.status = 'importing' image_repo.save(image, from_state=from_state) return flow
def get_flow(**kwargs): """Return task flow :param task_id: Task ID :param task_type: Type of the task :param task_repo: Task repo :param image_repo: Image repository used :param image_id: ID of the Image to be processed :param uri: uri for the image file """ task_id = kwargs.get('task_id') task_type = kwargs.get('task_type') task_repo = kwargs.get('task_repo') image_repo = kwargs.get('image_repo') admin_repo = kwargs.get('admin_repo') image_id = kwargs.get('image_id') import_method = kwargs.get('import_req')['method']['name'] uri = kwargs.get('import_req')['method'].get('uri') stores = kwargs.get('backend', [None]) all_stores_must_succeed = kwargs.get('import_req').get( 'all_stores_must_succeed', True) separator = '' if not CONF.enabled_backends and not CONF.node_staging_uri.endswith('/'): separator = '/' # Instantiate an action wrapper with the admin repo if we got one, # otherwise with the regular repo. action_wrapper = ImportActionWrapper(admin_repo or image_repo, image_id, task_id) kwargs['action_wrapper'] = action_wrapper if not uri and import_method in ['glance-direct', 'copy-image']: if CONF.enabled_backends: separator, staging_dir = store_utils.get_dir_separator() uri = separator.join((staging_dir, str(image_id))) else: uri = separator.join((CONF.node_staging_uri, str(image_id))) flow = lf.Flow(task_type, retry=retry.AlwaysRevert()) flow.add(_ImageLock(task_id, task_type, action_wrapper)) if import_method in ['web-download', 'copy-image']: internal_plugin = internal_plugins.get_import_plugin(**kwargs) flow.add(internal_plugin) if CONF.enabled_backends: separator, staging_dir = store_utils.get_dir_separator() file_uri = separator.join((staging_dir, str(image_id))) else: file_uri = separator.join((CONF.node_staging_uri, str(image_id))) else: file_uri = uri flow.add(_VerifyStaging(task_id, task_type, task_repo, file_uri)) # Note(jokke): The plugins were designed to act on the image data or # metadata during the import process before the image goes active. It # does not make sense to try to execute them during 'copy-image'. if import_method != 'copy-image': for plugin in import_plugins.get_import_plugins(**kwargs): flow.add(plugin) else: LOG.debug("Skipping plugins on 'copy-image' job.") for idx, store in enumerate(stores, 1): set_active = (not all_stores_must_succeed) or (idx == len(stores)) if import_method == 'copy-image': set_active = False task_name = task_type + "-" + (store or "") import_task = lf.Flow(task_name) import_to_store = _ImportToStore(task_id, task_name, task_repo, action_wrapper, file_uri, store, all_stores_must_succeed, set_active) import_task.add(import_to_store) flow.add(import_task) delete_task = lf.Flow(task_type).add(_DeleteFromFS(task_id, task_type)) flow.add(delete_task) verify_task = _VerifyImageState(task_id, task_type, action_wrapper, import_method) flow.add(verify_task) complete_task = _CompleteTask(task_id, task_type, task_repo, action_wrapper) flow.add(complete_task) with action_wrapper as action: if import_method != 'copy-image': action.set_image_attribute(status='importing') action.add_importing_stores(stores) action.remove_failed_stores(stores) action.pop_extra_property('os_glance_stage_host') return flow
def get_flow(**kwargs): """Return task flow :param task_id: Task ID :param task_type: Type of the task :param task_repo: Task repo :param image_repo: Image repository used :param image_id: ID of the Image to be processed :param uri: uri for the image file """ task_id = kwargs.get('task_id') task_type = kwargs.get('task_type') task_repo = kwargs.get('task_repo') image_repo = kwargs.get('image_repo') image_id = kwargs.get('image_id') import_method = kwargs.get('import_req')['method']['name'] uri = kwargs.get('import_req')['method'].get('uri') stores = kwargs.get('backend', [None]) all_stores_must_succeed = kwargs.get('import_req').get( 'all_stores_must_succeed', True) separator = '' if not CONF.enabled_backends and not CONF.node_staging_uri.endswith('/'): separator = '/' if not uri and import_method in ['glance-direct', 'copy-image']: if CONF.enabled_backends: separator, staging_dir = store_utils.get_dir_separator() uri = separator.join((staging_dir, str(image_id))) else: uri = separator.join((CONF.node_staging_uri, str(image_id))) flow = lf.Flow(task_type, retry=retry.AlwaysRevert()) if import_method in ['web-download', 'copy-image']: internal_plugin = internal_plugins.get_import_plugin(**kwargs) flow.add(internal_plugin) if CONF.enabled_backends: separator, staging_dir = store_utils.get_dir_separator() file_uri = separator.join((staging_dir, str(image_id))) else: file_uri = separator.join((CONF.node_staging_uri, str(image_id))) else: file_uri = uri flow.add(_VerifyStaging(task_id, task_type, task_repo, file_uri)) for plugin in import_plugins.get_import_plugins(**kwargs): flow.add(plugin) for idx, store in enumerate(stores, 1): set_active = (not all_stores_must_succeed) or (idx == len(stores)) if import_method == 'copy-image': set_active = False task_name = task_type + "-" + (store or "") import_task = lf.Flow(task_name) import_to_store = _ImportToStore(task_id, task_name, image_repo, file_uri, image_id, store, all_stores_must_succeed, set_active) import_task.add(import_to_store) flow.add(import_task) delete_task = lf.Flow(task_type).add(_DeleteFromFS(task_id, task_type)) flow.add(delete_task) save_task = _SaveImage(task_id, task_type, image_repo, image_id, import_method) flow.add(save_task) complete_task = _CompleteTask(task_id, task_type, task_repo, image_id) flow.add(complete_task) image = image_repo.get(image_id) from_state = image.status if import_method != 'copy-image': image.status = 'importing' image.extra_properties[ 'os_glance_importing_to_stores'] = ','.join((store for store in stores if store is not None)) image.extra_properties['os_glance_failed_import'] = '' image_repo.save(image, from_state=from_state) return flow