class Deployments(resources.Deployments): @swagger.operation( responseClass='List[{0}]'.format(responses_v2.Deployment.__name__), nickname="list", notes='Returns a list existing deployments for the optionally provided' ' filter parameters: {0}'.format(models.Deployment.fields), parameters=create_filter_params_list_description( models.Deployment.fields, 'deployments')) @exceptions_handled @marshal_with(responses_v2.Deployment) @create_filters(models.Deployment.fields) @paginate @sortable def get(self, _include=None, filters=None, pagination=None, sort=None, **kwargs): """ List deployments """ deployments = get_blueprints_manager().deployments_list( include=_include, filters=filters, pagination=pagination, sort=sort) return deployments
class DeploymentUpdates(SecuredResource): @swagger.operation( responseClass='List[{0}]'.format( models.DeploymentUpdate.__name__), nickname="listDeploymentUpdates", notes='Returns a list of deployment updates', parameters=create_filter_params_list_description( models.DeploymentUpdate.response_fields, 'deployment updates' ) ) @rest_decorators.exceptions_handled @authorize('deployment_update_list') @rest_decorators.marshal_with(models.DeploymentUpdate) @rest_decorators.create_filters(models.DeploymentUpdate) @rest_decorators.paginate @rest_decorators.sortable(models.DeploymentUpdate) def get(self, _include=None, filters=None, pagination=None, sort=None, **kwargs): """ List deployment modification stages """ deployment_updates = \ get_deployment_updates_manager().list_deployment_updates( include=_include, filters=filters, pagination=pagination, sort=sort, **kwargs) return deployment_updates
class DeploymentModifications(resources_v1.DeploymentModifications): @swagger.operation( responseClass='List[{0}]'.format( models.DeploymentModification.__name__), nickname="listDeploymentModifications", notes='Returns a list of deployment modifications for the optionally ' 'provided filter parameters: {0}' .format(models.DeploymentModification), parameters=create_filter_params_list_description( models.DeploymentModification.response_fields, 'deployment modifications' ) ) @rest_decorators.exceptions_handled @rest_decorators.marshal_with(models.DeploymentModification) @rest_decorators.create_filters(models.DeploymentModification) @rest_decorators.paginate @rest_decorators.sortable(models.DeploymentModification) def get(self, _include=None, filters=None, pagination=None, sort=None, **kwargs): """ List deployment modifications """ return get_storage_manager().list( models.DeploymentModification, include=_include, filters=filters, pagination=pagination, sort=sort )
class Vnf_pkgs(SecuredResource): @swagger.operation( responseClass='List[{0}]'.format(models.Vim.__name__), nickname="list", notes="Returns a list of vnf_pkgs.", parameters=create_filter_params_list_description( models.Vim.response_fields, 'blueprints' ) ) @rest_decorators.exceptions_handled @rest_decorators.marshal_with(models.Vnf_pkg) @rest_decorators.create_filters(models.Vnf_pkg) @rest_decorators.paginate @rest_decorators.sortable(models.Vnf_pkg) @rest_decorators.all_tenants def get(self, _include=None, filters=None, pagination=None, sort=None, all_tenants=None, **kwargs): """ List vnf_pkgs """ current_app.logger.info('get vnf_pkgs list') return get_storage_manager().list( models.Vnf_pkg, include=_include, filters=filters, pagination=pagination, sort=sort, all_tenants=all_tenants )
class Deployments(resources_v1.Deployments): @swagger.operation( responseClass='List[{0}]'.format(models.Deployment.__name__), nickname="list", notes='Returns a list existing deployments for the optionally provided' ' filter parameters: ' '{0}'.format(models.Deployment), parameters=create_filter_params_list_description( models.Deployment.response_fields, 'deployments' ) ) @rest_decorators.exceptions_handled @rest_decorators.marshal_with(models.Deployment) @rest_decorators.create_filters(models.Deployment) @rest_decorators.paginate @rest_decorators.sortable(models.Deployment) @rest_decorators.all_tenants def get(self, _include=None, filters=None, pagination=None, sort=None, all_tenants=None, **kwargs): """ List deployments """ return get_storage_manager().list( models.Deployment, include=_include, filters=filters, pagination=pagination, sort=sort, all_tenants=all_tenants )
class Blueprints(resources.Blueprints): @swagger.operation( responseClass='List[{0}]'.format(responses_v2.BlueprintState.__name__), nickname="list", notes='Returns a list of submitted blueprints for the optionally ' 'provided filter parameters {0}'.format(models.BlueprintState.fields), parameters=create_filter_params_list_description( models.BlueprintState.fields, 'blueprints')) @exceptions_handled @marshal_with(responses_v2.BlueprintState) @create_filters(models.BlueprintState.fields) @paginate @sortable def get(self, _include=None, filters=None, pagination=None, sort=None, **kwargs): """ List uploaded blueprints """ return get_blueprints_manager().blueprints_list(include=_include, filters=filters, pagination=pagination, sort=sort)
class Insts(SecuredResource): @swagger.operation(responseClass='List[{0}]'.format(models.Inst.__name__), nickname="list", notes="Returns a list of insts.", parameters=create_filter_params_list_description( models.Inst.response_fields, 'blueprints')) @rest_decorators.exceptions_handled @rest_decorators.marshal_with(models.Inst) @rest_decorators.create_filters(models.Inst) @rest_decorators.paginate @rest_decorators.sortable(models.Inst) @rest_decorators.all_tenants def get(self, _include=None, filters=None, pagination=None, sort=None, all_tenants=None, **kwargs): """ List uploaded insts """ return get_storage_manager().list(models.Inst, include=_include, filters=filters, pagination=pagination, sort=sort, all_tenants=all_tenants)
class NodeInstances(resources_v1.NodeInstances): @swagger.operation( responseClass='List[{0}]'.format(models.NodeInstance.__name__), nickname="listNodeInstances", notes='Returns a node instances list for the optionally provided ' 'filter parameters: {0}' .format(models.NodeInstance), parameters=create_filter_params_list_description( models.NodeInstance.response_fields, 'node instances' ) ) @rest_decorators.exceptions_handled @rest_decorators.marshal_with(models.NodeInstance) @rest_decorators.create_filters(models.NodeInstance) @rest_decorators.paginate @rest_decorators.sortable(models.NodeInstance) @rest_decorators.all_tenants def get(self, _include=None, filters=None, pagination=None, sort=None, all_tenants=None, **kwargs): """ List node instances """ return get_storage_manager().list( models.NodeInstance, include=_include, filters=filters, pagination=pagination, sort=sort, all_tenants=all_tenants )
class PluginsUpdates(SecuredResource): @swagger.operation( responseClass='List[{0}]'.format(models.PluginsUpdate.__name__), nickname="listPluginsUpdates", notes='Returns a list of plugins updates', parameters=create_filter_params_list_description( models.PluginsUpdate.response_fields, 'plugins updates' ) ) @rest_decorators.exceptions_handled @authorize('plugins_update_list') @rest_decorators.marshal_with(models.PluginsUpdate) @rest_decorators.create_filters(models.PluginsUpdate) @rest_decorators.paginate @rest_decorators.sortable(models.PluginsUpdate) @rest_decorators.search('id') def get(self, _include=None, filters=None, pagination=None, sort=None, search=None, **_): """List plugins updates""" plugins_update = \ get_plugins_updates_manager().list_plugins_updates( include=_include, filters=filters, pagination=pagination, sort=sort, substr_filters=search ) return plugins_update
class Blueprints(resources_v1.Blueprints): @swagger.operation( responseClass='List[{0}]'.format(models.Blueprint.__name__), nickname="list", notes='Returns a list of submitted blueprints for the optionally ' 'provided filter parameters {0}'.format(models.Blueprint), parameters=create_filter_params_list_description( models.Blueprint.response_fields, 'blueprints')) @rest_decorators.exceptions_handled @authorize('blueprint_list') @rest_decorators.marshal_with(models.Blueprint) @rest_decorators.create_filters(models.Blueprint) @rest_decorators.paginate @rest_decorators.sortable(models.Blueprint) @rest_decorators.all_tenants def get(self, _include=None, filters=None, pagination=None, sort=None, all_tenants=None, **kwargs): """ List uploaded blueprints """ return get_storage_manager().list(models.Blueprint, include=_include, filters=filters, pagination=pagination, sort=sort, all_tenants=all_tenants)
class NodeInstances(resources.NodeInstances): @swagger.operation( responseClass='List[{0}]'.format(responses_v2.NodeInstance.__name__), nickname="listNodeInstances", notes='Returns a node instances list for the optionally provided ' 'filter parameters: {0}'.format(models.DeploymentNodeInstance.fields), parameters=create_filter_params_list_description( models.DeploymentNodeInstance.fields, 'node instances')) @exceptions_handled @marshal_with(responses_v2.NodeInstance) @create_filters(models.DeploymentNodeInstance.fields) @paginate @sortable def get(self, _include=None, filters=None, pagination=None, sort=None, **kwargs): """ List node instances """ node_instances = get_storage_manager().get_node_instances( include=_include, filters=filters, pagination=pagination, sort=sort) return node_instances
class Deployments(resources_v1.Deployments): @swagger.operation( responseClass='List[{0}]'.format(models.Deployment.__name__), nickname="list", notes='Returns a list existing deployments for the optionally provided' ' filter parameters: ' '{0}'.format(models.Deployment), parameters=create_filter_params_list_description( models.Deployment.response_fields, 'deployments')) @authorize('deployment_list', allow_all_tenants=True) @rest_decorators.marshal_with(models.Deployment) @rest_decorators.create_filters(models.Deployment) @rest_decorators.paginate @rest_decorators.sortable(models.Deployment) @rest_decorators.all_tenants @rest_decorators.search_multiple_parameters({ '_search': 'id', '_search_name': 'display_name' }) @rest_decorators.filter_id def get(self, _include=None, filters=None, pagination=None, sort=None, all_tenants=None, search=None, filter_id=None, **kwargs): """ List deployments """ get_all_results = rest_utils.verify_and_convert_bool( '_get_all_results', request.args.get('_get_all_results', False)) filters, _include = rest_utils.modify_deployments_list_args( filters, _include) filter_rules = get_filter_rules_from_filter_id( filter_id, models.DeploymentsFilter) result = get_storage_manager().list(models.Deployment, include=_include, filters=filters, substr_filters=search, pagination=pagination, sort=sort, all_tenants=all_tenants, get_all_results=get_all_results, filter_rules=filter_rules) if _include and 'workflows' in _include: # Because we coerce this into a list in the model, but our ORM # won't return a model instance when filtering results, we have # to coerce this here as well. This is unpleasant. for index, item in enumerate(result.items): r = item._asdict() r['workflows'] = models.Deployment._list_workflows( r['workflows'], ) result.items[index] = r return result
class Executions(resources_v1.Executions): @swagger.operation( responseClass='List[{0}]'.format(models.Execution.__name__), nickname="list", notes='Returns a list of executions for the optionally provided filter' ' parameters: {0}'.format(models.Execution), parameters=create_filter_params_list_description( models.Execution.response_fields, 'executions') + [{ 'name': '_include_system_workflows', 'description': 'Include executions of system workflows', 'required': False, 'allowMultiple': True, 'dataType': 'bool', 'defaultValue': False, 'paramType': 'query' }]) @rest_decorators.exceptions_handled @authorize('execution_list', allow_all_tenants=True) @rest_decorators.marshal_with(models.Execution) @rest_decorators.create_filters(models.Execution) @rest_decorators.paginate @rest_decorators.sortable(models.Execution) @rest_decorators.all_tenants def get(self, _include=None, filters=None, pagination=None, sort=None, all_tenants=None, **kwargs): """ List executions """ deployment_id = request.args.get('deployment_id') if deployment_id: self._check_if_deployment_exists(deployment_id, all_tenants) is_include_system_workflows = rest_utils.verify_and_convert_bool( '_include_system_workflows', request.args.get('_include_system_workflows', 'false')) return get_resource_manager().list_executions( filters=filters, pagination=pagination, sort=sort, is_include_system_workflows=is_include_system_workflows, include=_include, all_tenants=all_tenants) def _check_if_deployment_exists(self, deployment_id, all_tenants): deployments_list = get_storage_manager().list( models.Deployment, include=['id'], filters={'id': deployment_id}, all_tenants=all_tenants) if not deployments_list: raise manager_exceptions.NotFoundError( 'Requested `Deployment` with ID `{0}` was not found'.format( deployment_id))
class DeploymentUpdateId(SecuredResource): @swagger.operation(responseClass=responses_v2_1.DeploymentUpdate, nickname="DeploymentUpdate", notes='Return a single deployment update', parameters=create_filter_params_list_description( models.DeploymentUpdate.fields, 'deployment update')) @exceptions_handled @marshal_with(responses_v2_1.DeploymentUpdate) def get(self, update_id): return \ get_deployment_updates_manager().get_deployment_update(update_id)
class DeploymentUpdateId(SecuredResource): @swagger.operation(responseClass=models.DeploymentUpdate, nickname="DeploymentUpdate", notes='Return a single deployment update', parameters=create_filter_params_list_description( models.DeploymentUpdate.response_fields, 'deployment update')) @authorize('deployment_update_get') @rest_decorators.marshal_with(models.DeploymentUpdate) def get(self, update_id, _include=None): """Get a deployment update by id""" return get_deployment_updates_manager().get_deployment_update( update_id, include=_include)
class Nodes(resources_v1.Nodes): @swagger.operation( responseClass='List[{0}]'.format(models.Node.__name__), nickname="listNodes", notes='Returns a nodes list for the optionally provided filter ' 'parameters: {0}'.format(models.Node), parameters=create_filter_params_list_description( models.Node.response_fields, 'nodes')) @authorize('node_list', allow_all_tenants=True) @rest_decorators.marshal_with(models.Node) @rest_decorators.create_filters(models.Node) @rest_decorators.paginate @rest_decorators.sortable(models.Node) @rest_decorators.all_tenants @rest_decorators.search('id') def get(self, _include=None, filters=None, pagination=None, sort=None, all_tenants=None, search=None, **kwargs): """ List nodes """ get_all_results = rest_utils.verify_and_convert_bool( '_get_all_results', request.args.get('_get_all_results', False)) nodes_list = get_storage_manager().list( models.Node, include=_include, pagination=pagination, filters=filters, substr_filters=search, sort=sort, all_tenants=all_tenants, get_all_results=get_all_results) # Update the node instance count to account for group scaling policy for node in nodes_list: if not hasattr(node, 'deployment'): continue scale_by = 1 scaling_groups = node.deployment.scaling_groups.values() for group in scaling_groups: if {node.id, node.host_id} & set(group['members']): scale_by *= group['properties']['planned_instances'] node.set_actual_planned_node_instances( scale_by * node.planned_number_of_instances) node.set_actual_node_instances(len(node.node_instances)) return nodes_list
class PluginsUpdateId(SecuredResource): @swagger.operation( responseClass=models.PluginsUpdate, nickname="PluginsUpdate", notes='Return a single plugins update', parameters=create_filter_params_list_description( models.PluginsUpdate.response_fields, 'plugins update') ) @rest_decorators.exceptions_handled @authorize('plugins_update_get') @rest_decorators.marshal_with(models.PluginsUpdate) def get(self, update_id, _include=None): """Get a plugins update by id""" return get_storage_manager().get( models.PluginsUpdate, update_id, include=_include)
class Executions(resources_v1.Executions): @swagger.operation( responseClass='List[{0}]'.format(models.Execution.__name__), nickname="list", notes='Returns a list of executions for the optionally provided filter' ' parameters: {0}'.format(models.Execution), parameters=create_filter_params_list_description( models.Execution.response_fields, 'executions') + [ {'name': '_include_system_workflows', 'description': 'Include executions of system workflows', 'required': False, 'allowMultiple': True, 'dataType': 'bool', 'defaultValue': False, 'paramType': 'query'} ] ) @authorize('execution_list', allow_all_tenants=True) @rest_decorators.marshal_with(models.Execution) @rest_decorators.create_filters(models.Execution) @rest_decorators.paginate @rest_decorators.sortable(models.Execution) @rest_decorators.all_tenants def get(self, _include=None, filters=None, pagination=None, sort=None, all_tenants=None, **kwargs): """ List executions """ if '_group_id' in request.args: filters['execution_groups'] = lambda col: col.any( models.ExecutionGroup.id == request.args['_group_id'] ) is_include_system_workflows = rest_utils.verify_and_convert_bool( '_include_system_workflows', request.args.get('_include_system_workflows', False)) get_all_results = rest_utils.verify_and_convert_bool( '_get_all_results', request.args.get('_get_all_results', False) ) return get_resource_manager().list_executions( filters=filters, pagination=pagination, sort=sort, is_include_system_workflows=is_include_system_workflows, include=_include, all_tenants=all_tenants, get_all_results=get_all_results )
class Executions(resources_v1.Executions): @swagger.operation( responseClass='List[{0}]'.format(models.Execution.__name__), nickname="list", notes='Returns a list of executions for the optionally provided filter' ' parameters: {0}'.format(models.Execution), parameters=create_filter_params_list_description( models.Execution.response_fields, 'executions') + [{ 'name': '_include_system_workflows', 'description': 'Include executions of system workflows', 'required': False, 'allowMultiple': True, 'dataType': 'bool', 'defaultValue': False, 'paramType': 'query' }]) @rest_decorators.exceptions_handled @rest_decorators.marshal_with(models.Execution) @rest_decorators.create_filters(models.Execution) @rest_decorators.paginate @rest_decorators.sortable(models.Execution) def get(self, _include=None, filters=None, pagination=None, sort=None, **kwargs): """ List executions """ deployment_id = request.args.get('deployment_id') if deployment_id: get_storage_manager().get(models.Deployment, deployment_id, include=['id']) is_include_system_workflows = rest_utils.verify_and_convert_bool( '_include_system_workflows', request.args.get('_include_system_workflows', 'false')) return get_resource_manager().list_executions( filters=filters, pagination=pagination, sort=sort, is_include_system_workflows=is_include_system_workflows, include=_include)
class Blueprints(resources_v1.Blueprints): @swagger.operation( responseClass='List[{0}]'.format(models.Blueprint.__name__), nickname="list", notes='Returns a list of submitted blueprints for the optionally ' 'provided filter parameters {0}'.format(models.Blueprint), parameters=create_filter_params_list_description( models.Blueprint.response_fields, 'blueprints')) @authorize('blueprint_list', allow_all_tenants=True) @rest_decorators.marshal_with(models.Blueprint) @rest_decorators.create_filters(models.Blueprint) @rest_decorators.paginate @rest_decorators.sortable(models.Blueprint) @rest_decorators.all_tenants @rest_decorators.search('id') @rest_decorators.filter_id def get(self, _include=None, filters=None, pagination=None, sort=None, all_tenants=None, search=None, filter_id=None, **kwargs): """ List uploaded blueprints """ get_all_results = rest_utils.verify_and_convert_bool( '_get_all_results', request.args.get('_get_all_results', False)) filters, _include = rest_utils.modify_blueprints_list_args( filters, _include) filter_rules = get_filter_rules_from_filter_id(filter_id, models.BlueprintsFilter) return get_storage_manager().list(models.Blueprint, include=_include, filters=filters, substr_filters=search, pagination=pagination, sort=sort, all_tenants=all_tenants, get_all_results=get_all_results, filter_rules=filter_rules)
class NodeInstances(resources_v1.NodeInstances): @swagger.operation( responseClass='List[{0}]'.format(models.NodeInstance.__name__), nickname="listNodeInstances", notes='Returns a node instances list for the optionally provided ' 'filter parameters: {0}' .format(models.NodeInstance), parameters=create_filter_params_list_description( models.NodeInstance.response_fields, 'node instances' ) ) @rest_decorators.exceptions_handled @authorize('node_instance_list', allow_all_tenants=True) @rest_decorators.marshal_with(models.NodeInstance) @rest_decorators.create_filters(models.NodeInstance) @rest_decorators.paginate @rest_decorators.sortable(models.NodeInstance) @rest_decorators.all_tenants @rest_decorators.search('id') def get(self, _include=None, filters=None, pagination=None, sort=None, all_tenants=None, search=None, **kwargs): """ List node instances """ get_all_results = rest_utils.verify_and_convert_bool( '_get_all_results', request.args.get('_get_all_results', False) ) return get_storage_manager().list( models.NodeInstance, include=_include, filters=filters, substr_filters=search, pagination=pagination, sort=sort, all_tenants=all_tenants, get_all_results=get_all_results )
class Plugins(SecuredResource): @swagger.operation( responseClass='List[{0}]'.format(models.Plugin.__name__), nickname="listPlugins", notes='Returns a plugins list for the optionally provided ' 'filter parameters: {0}'.format(models.Plugin), parameters=create_filter_params_list_description( models.Plugin.response_fields, 'plugins' ) ) @authorize('plugin_list', allow_all_tenants=True) @rest_decorators.marshal_with(models.Plugin) @rest_decorators.create_filters(models.Plugin) @rest_decorators.paginate @rest_decorators.sortable(models.Plugin) @rest_decorators.all_tenants @rest_decorators.search('package_name') def get(self, _include=None, filters=None, pagination=None, sort=None, all_tenants=None, search=None, **kwargs): """ List uploaded plugins """ return get_storage_manager().list( models.Plugin, include=_include, filters=filters, substr_filters=search, pagination=pagination, sort=sort, all_tenants=all_tenants ) @swagger.operation( responseClass=models.Plugin, nickname='upload', notes='Submitted plugin should be an archive containing the directory ' ' which contains the plugin wheel. The supported archive type ' 'is: {archive_type}. The archive may be submitted via either' ' URL or by direct upload. Archive wheels must contain a ' 'module.json file containing required metadata for the plugin ' 'usage.' .format(archive_type='tar.gz'), parameters=[{'name': 'plugin_archive_url', 'description': 'url of a plugin archive file', 'required': False, 'allowMultiple': False, 'dataType': 'string', 'paramType': 'query'}, {'name': 'body', 'description': 'Binary form of the tar ' 'gzipped plugin directory', 'required': True, 'allowMultiple': False, 'dataType': 'binary', 'paramType': 'body'}], consumes=["application/octet-stream"] ) @authorize('plugin_upload') @rest_decorators.marshal_with(models.Plugin) def post(self, **kwargs): """ Upload a plugin """ storage_manager = get_storage_manager() is_caravan = False installed_plugins = [] get_resource_manager().assert_no_snapshot_creation_running_or_queued() try: plugins, code = UploadedCaravanManager().receive_uploaded_data( **kwargs) is_caravan = True except UploadedCaravanManager.InvalidCaravanException: plugin, code = UploadedPluginsManager().receive_uploaded_data( str(uuid4()), **kwargs ) plugins = [plugin] for plugin in plugins: try: get_resource_manager().install_plugin(plugin) installed_plugins.append(plugin) except manager_exceptions.ExecutionTimeout: tp, ex, tb = sys.exc_info() if not is_caravan: raise manager_exceptions.PluginInstallationTimeout( 'Timed out during plugin installation.' '({0}: {1})'.format(tp.__name__, ex)), None, tb except Exception: get_resource_manager().remove_plugin(plugin_id=plugin.id, force=True) tp, ex, tb = sys.exc_info() if not is_caravan: raise manager_exceptions.PluginInstallationError( 'Failed during plugin installation.' '({0}: {1})'.format(tp.__name__, ex)), None, tb if is_caravan: storage_plugins = storage_manager.list( models.Plugin, filters={'id': [p.id for p in installed_plugins]}) return ListResponse(items=storage_plugins.items, metadata=storage_plugins.metadata), code else: return plugins[0], code
class InterDeploymentDependencies(SecuredResource): @swagger.operation(responseClass=models.InterDeploymentDependencies, nickname="DeploymentDependenciesCreate", notes="Creates an inter-deployment dependency.", parameters=utils.create_filter_params_list_description( models.InterDeploymentDependencies.response_fields, 'deployment_dependency')) @authorize('inter_deployment_dependency_create') @rest_decorators.marshal_with(models.InterDeploymentDependencies) def put(self): """Creates an inter-deployment dependency. :param dependency_creator: a string representing the entity that is responsible for this dependency (e.g. an intrinsic function blueprint path, 'node_instances.some_node_instance', etc.). :param source_deployment: source deployment that depends on the target deployment. :param target_deployment: the deployment that the source deployment depends on. :param external_source: metadata, in JSON format, of the source deployment (deployment name, tenant name, and the manager host(s)), in case it resides on an external manager. None otherwise :param external_target: metadata, in JSON format, of the target deployment (deployment name, tenant name, and the manager host(s)), in case it resides on an external manager. None otherwise :return: an InterDeploymentDependency object containing the information of the dependency. """ sm = get_storage_manager() params = self._get_put_dependency_params(sm) now = utils.get_formatted_timestamp() if (EXTERNAL_SOURCE not in params) and (EXTERNAL_TARGET not in params): # assert no cyclic dependencies are created dep_greph = rest_utils.RecursiveDeploymentDependencies(sm) source_id = str(params[SOURCE_DEPLOYMENT].id) target_id = str(params[TARGET_DEPLOYMENT].id) dep_greph.create_dependencies_graph() dep_greph.assert_no_cyclic_dependencies(source_id, target_id) deployment_dependency = models.InterDeploymentDependencies( id=str(uuid.uuid4()), dependency_creator=params[DEPENDENCY_CREATOR], source_deployment=params[SOURCE_DEPLOYMENT], target_deployment=params.get(TARGET_DEPLOYMENT), external_source=params.get(EXTERNAL_SOURCE), external_target=params.get(EXTERNAL_TARGET), created_at=now) return sm.put(deployment_dependency) @staticmethod def _verify_and_get_source_and_target_deployments( sm, source_deployment_id, target_deployment_id, is_component_deletion=False, external_source=None, external_target=None): if external_source: source_deployment = None else: source_deployment = sm.get(models.Deployment, source_deployment_id, fail_silently=True) if not source_deployment: raise manager_exceptions.NotFoundError( 'Given source deployment with ID `{0}` does not ' 'exist.'.format(source_deployment_id)) target_deployment = sm.get(models.Deployment, target_deployment_id, fail_silently=True) if not (is_component_deletion or external_source or external_target or target_deployment): raise manager_exceptions.NotFoundError( 'Given target deployment with ID `{0}` does not ' 'exist.'.format(target_deployment_id)) return source_deployment, target_deployment @staticmethod def _verify_dependency_params(): return rest_utils.get_json_and_verify_params({ DEPENDENCY_CREATOR: { 'type': text_type }, SOURCE_DEPLOYMENT: { 'type': text_type }, TARGET_DEPLOYMENT: { 'type': text_type }, EXTERNAL_SOURCE: { 'optional': True, 'type': dict }, EXTERNAL_TARGET: { 'optional': True, 'type': dict }, }) @staticmethod def _get_put_dependency_params(sm): request_dict = InterDeploymentDependencies._verify_dependency_params() external_source = request_dict.get(EXTERNAL_SOURCE) external_target = request_dict.get(EXTERNAL_TARGET) source_deployment, target_deployment = InterDeploymentDependencies. \ _verify_and_get_source_and_target_deployments( sm, request_dict.get(SOURCE_DEPLOYMENT), request_dict.get(TARGET_DEPLOYMENT), external_source=external_source, external_target=external_target ) dependency_params = create_deployment_dependency( request_dict.get(DEPENDENCY_CREATOR), source_deployment, target_deployment, external_source, external_target) return dependency_params @swagger.operation(responseClass=models.InterDeploymentDependencies, nickname="DeploymentDependenciesDelete", notes="Deletes an inter-deployment dependency.", parameters=utils.create_filter_params_list_description( models.InterDeploymentDependencies.response_fields, 'deployment_dependency')) @authorize('inter_deployment_dependency_delete') @rest_decorators.marshal_with(models.InterDeploymentDependencies) def delete(self): """Deletes an inter-deployment dependency. :param dependency_creator: a string representing the entity that is responsible for this dependency (e.g. an intrinsic function blueprint path, 'node_instances.some_node_instance', etc.). :param source_deployment: source deployment that depends on the target deployment. :param target_deployment: the deployment that the source deployment depends on. :param is_component_deletion: a special flag for allowing the deletion of a Component inter-deployment dependency when the target deployment is already deleted. :param external_source: metadata, in JSON format, of the source deployment (deployment name, tenant name, and the manager host(s)), in case it resides on an external manager. None otherwise :param external_target: metadata, in JSON format, of the target deployment (deployment name, tenant name, and the manager host(s)), in case it resides on an external manager. None otherwise :return: an InterDeploymentDependency object containing the information of the dependency. """ sm = get_storage_manager() params = self._get_delete_dependency_params(sm) filters = create_deployment_dependency(params[DEPENDENCY_CREATOR], params.get(SOURCE_DEPLOYMENT), params.get(TARGET_DEPLOYMENT), params.get(EXTERNAL_SOURCE)) dependency = sm.get( models.InterDeploymentDependencies, None, filters=filters, # Locking to make sure to fail here and not during the deletion # (for the purpose of clarifying the error in case one occurs). locking=True) return sm.delete(dependency) @staticmethod def _get_delete_dependency_params(sm): request_dict = InterDeploymentDependencies._verify_dependency_params() external_source = request_dict.get(EXTERNAL_SOURCE) external_target = request_dict.get(EXTERNAL_TARGET) source_deployment, target_deployment = InterDeploymentDependencies. \ _verify_and_get_source_and_target_deployments( sm, request_dict.get(SOURCE_DEPLOYMENT), request_dict.get(TARGET_DEPLOYMENT), external_source=external_source, external_target=external_target, is_component_deletion=request_dict['is_component_deletion'] ) dependency_params = create_deployment_dependency( request_dict.get(DEPENDENCY_CREATOR), source_deployment, target_deployment, external_source, external_target) return dependency_params @swagger.operation(responseClass='List[{0}]'.format( models.InterDeploymentDependencies.__name__), nickname="listInterDeploymentDependencies", notes='Returns a list of inter-deployment dependencies', parameters=utils.create_filter_params_list_description( models.InterDeploymentDependencies.response_fields, 'inter-deployment dependency')) @authorize('inter_deployment_dependency_list') @rest_decorators.marshal_with(models.InterDeploymentDependencies) @rest_decorators.create_filters(models.InterDeploymentDependencies) @rest_decorators.paginate @rest_decorators.sortable(models.InterDeploymentDependencies) @rest_decorators.search('id') def get(self, _include=None, filters=None, pagination=None, sort=None, search=None, **_): """List inter-deployment dependencies""" inter_deployment_dependencies = \ get_storage_manager().list( models.InterDeploymentDependencies, include=_include, filters=filters, pagination=pagination, sort=sort, substr_filters=search ) return inter_deployment_dependencies
class Plugins(SecuredResource): @swagger.operation( responseClass='List[{0}]'.format(responses_v2.NodeInstance.__name__), nickname="listPlugins", notes='Returns a plugins list for the optionally provided ' 'filter parameters: {0}'.format(models.Plugin.fields), parameters=create_filter_params_list_description( models.Plugin.fields, 'plugins')) @exceptions_handled @marshal_with(responses_v2.Plugin) @create_filters(models.Plugin.fields) @paginate @sortable def get(self, _include=None, filters=None, pagination=None, sort=None, **kwargs): """ List uploaded plugins """ plugins = get_storage_manager().get_plugins(include=_include, filters=filters, pagination=pagination, sort=sort) return plugins @swagger.operation( responseClass=responses_v2.Plugin, nickname='upload', notes='Submitted plugin should be an archive containing the directory ' ' which contains the plugin wheel. The supported archive type ' 'is: {archive_type}. The archive may be submitted via either' ' URL or by direct upload. Archive wheels must contain a ' 'module.json file containing required metadata for the plugin ' 'usage.'.format(archive_type='tar.gz'), parameters=[{ 'name': 'plugin_archive_url', 'description': 'url of a plugin archive file', 'required': False, 'allowMultiple': False, 'dataType': 'string', 'paramType': 'query' }, { 'name': 'body', 'description': 'Binary form of the tar ' 'gzipped plugin directory', 'required': True, 'allowMultiple': False, 'dataType': 'binary', 'paramType': 'body' }], consumes=["application/octet-stream"]) @exceptions_handled @marshal_with(responses_v2.Plugin) def post(self, **kwargs): """ Upload a plugin """ return UploadedPluginsManager().receive_uploaded_data(str(uuid4()))
class Plugins(SecuredResource): @swagger.operation( responseClass='List[{0}]'.format(models.NodeInstance.__name__), nickname="listPlugins", notes='Returns a plugins list for the optionally provided ' 'filter parameters: {0}'.format(models.Plugin), parameters=create_filter_params_list_description( models.Plugin.response_fields, 'plugins' ) ) @rest_decorators.exceptions_handled @authorize('plugin_list') @rest_decorators.marshal_with(models.Plugin) @rest_decorators.create_filters(models.Plugin) @rest_decorators.paginate @rest_decorators.sortable(models.Plugin) @rest_decorators.all_tenants def get(self, _include=None, filters=None, pagination=None, sort=None, all_tenants=None, **kwargs): """ List uploaded plugins """ return get_storage_manager().list( models.Plugin, include=_include, filters=filters, pagination=pagination, sort=sort, all_tenants=all_tenants ) @swagger.operation( responseClass=models.Plugin, nickname='upload', notes='Submitted plugin should be an archive containing the directory ' ' which contains the plugin wheel. The supported archive type ' 'is: {archive_type}. The archive may be submitted via either' ' URL or by direct upload. Archive wheels must contain a ' 'module.json file containing required metadata for the plugin ' 'usage.' .format(archive_type='tar.gz'), parameters=[{'name': 'plugin_archive_url', 'description': 'url of a plugin archive file', 'required': False, 'allowMultiple': False, 'dataType': 'string', 'paramType': 'query'}, {'name': 'body', 'description': 'Binary form of the tar ' 'gzipped plugin directory', 'required': True, 'allowMultiple': False, 'dataType': 'binary', 'paramType': 'body'}], consumes=["application/octet-stream"] ) @rest_decorators.exceptions_handled @authorize('plugin_upload') @rest_decorators.marshal_with(models.Plugin) def post(self, **kwargs): """ Upload a plugin """ plugin, code = UploadedPluginsManager().receive_uploaded_data( str(uuid4())) try: get_resource_manager().install_plugin(plugin) except manager_exceptions.ExecutionTimeout: tp, ex, tb = sys.exc_info() raise manager_exceptions.PluginInstallationTimeout( 'Timed out during plugin installation. ({0}: {1})' .format(tp.__name__, ex)), None, tb except Exception: get_resource_manager().remove_plugin( plugin_id=plugin.id, force=True) tp, ex, tb = sys.exc_info() raise manager_exceptions.PluginInstallationError( 'Failed during plugin installation. ({0}: {1})' .format(tp.__name__, ex)), None, tb return plugin, code