def create_service_on_platform(ws_id, platform_id, service_data): """ Deploys the service on the referenced Platform :param ws_id: :param platform_id: :param service_data: :return: A message if the function was deployed successfully """ service_id = int(service_data['id']) session = db_session() try: workspace = session.query(Workspace).filter(Workspace.id == ws_id).first() project = session.query(Project). \ join(Service). \ filter(Project.services.any(Service.id == service_id)). \ filter(Project.workspace == workspace). \ first() # type: Project if not len(project.services) == 1: raise InvalidArgument( "Project must have exactly one service " "to push to platform. Number of services: {}".format( len(project.services))) platform = session.query(Platform).filter(Platform.id == platform_id). \ filter(Platform.workspace == workspace).first() package_path = pack_project(project) service_uuid = push_to_platform(package_path, platform) logger.info("Pushed to platform: " + str(service_uuid)) # deploy to private catalogue service = project.services[0].as_dict() publish_private_nsfs(ws_id, service["descriptor"], is_vnf=False) publish_referenced_functions(ws_id, project.id, service["descriptor"]) return {'message': 'Deployed successfully: {}'.format(str(service_uuid))} finally: session.commit()
def publish_referenced_functions(ws_id, proj_id, descriptor): vnfs = descriptor["network_functions"] session = db_session() for vnf in vnfs: function = session.query(Function).join(Project). \ filter(Project.id == proj_id). \ filter(Function.name == vnf['vnf_name']). \ filter(Function.vendor == vnf["vnf_vendor"]). \ filter(Function.version == vnf["vnf_version"]).first() publish_private_nsfs(ws_id, function.as_dict()["descriptor"], True)
def publish_referenced_functions(ws_id, proj_id, descriptor): vnfs = descriptor["network_functions"] session = db_session() for vnf in vnfs: function = session.query(Function).join(Project). \ filter(Project.id == proj_id). \ filter(Function.name == vnf['vnf_name']). \ filter(Function.vendor == vnf["vnf_vendor"]). \ filter(Function.version == vnf["vnf_version"]).first() publish_private_nsfs(ws_id, function.as_dict()["descriptor"], True)
def get(self, ws_id, parent_id, service_id): """ Publish service to private Publishes the service to the workspace wide catalogue :param ws_id: :param parent_id: :param service_id: :return: """ service = servicesimpl.get_service(ws_id, parent_id, service_id) publish_private_nsfs(ws_id, service["descriptor"], False) return prepare_response({"message": "Service {} was published to private catalogue".format(service.name)}, 201)
def get(self, ws_id, project_id, service_id): """ Publish service to private Publishes the service to the workspace wide catalogue :param ws_id: The Workspace ID :param project_id: The Project ID :param service_id: The Service ID :return: A dict with a "message" property. """ service = servicesimpl.get_service(ws_id, project_id, service_id) publish_private_nsfs(ws_id, service["descriptor"], False) return prepare_response({"message": "Service {} was published to private catalogue".format(service.name)}, 201)
def get(self, ws_id, parent_id, vnf_id): """ Publish function to private Publishes the function to the workspace wide catalogue :param ws_id: :param parent_id: :param vnf_id: :return: """ function = functionsimpl.get_function_project(ws_id, parent_id, vnf_id) publish_private_nsfs(ws_id, function["descriptor"], True) return prepare_response( {"message": "Function {} was published to private catalogue".format(function['descriptor']['name'])}, 201)
def publish_referenced_functions(ws_id, proj_id, descriptor): """ Publishes the referenced functions to the private cataloge after packaging :param ws_id: The workspace ID :param proj_id: The project ID :param descriptor: The service descriptor """ vnfs = descriptor["network_functions"] session = db_session() for vnf in vnfs: function = session.query(Function).join(Project). \ filter(Project.id == proj_id). \ filter(Function.name == vnf['vnf_name']). \ filter(Function.vendor == vnf["vnf_vendor"]). \ filter(Function.version == vnf["vnf_version"]).first() publish_private_nsfs(ws_id, function.as_dict()["descriptor"], True)
def publish_referenced_functions(ws_id, proj_id, descriptor): """ Publishes the referenced functions to the private cataloge after packaging :param ws_id: The workspace ID :param proj_id: The project ID :param descriptor: The service descriptor """ vnfs = descriptor["network_functions"] session = db_session() for vnf in vnfs: function = session.query(Function).join(Project). \ filter(Project.id == proj_id). \ filter(Function.name == vnf['vnf_name']). \ filter(Function.vendor == vnf["vnf_vendor"]). \ filter(Function.version == vnf["vnf_version"]).first() publish_private_nsfs(ws_id, function.as_dict()["descriptor"], True)
def get(self, ws_id, parent_id, vnf_id): """ Publish function to private Publishes the function to the workspace wide catalogue :param ws_id: :param parent_id: :param vnf_id: :return: """ function = functionsimpl.get_function_project(ws_id, parent_id, vnf_id) publish_private_nsfs(ws_id, function["descriptor"], True) return prepare_response( { "message": "Function {} was published to private catalogue".format( function['descriptor']['name']) }, 201)
def get(self, ws_id, parent_id, service_id): """ Publish service to private Publishes the service to the workspace wide catalogue :param ws_id: :param parent_id: :param service_id: :return: """ service = servicesimpl.get_service(ws_id, parent_id, service_id) publish_private_nsfs(ws_id, service["descriptor"], False) return prepare_response( { "message": "Service {} was published to private catalogue".format( service.name) }, 201)
def get(self, ws_id, project_id, service_id): """ Publish service to private Publishes the service to the workspace wide catalogue :param ws_id: The Workspace ID :param project_id: The Project ID :param service_id: The Service ID :return: A dict with a "message" property. """ service = servicesimpl.get_service(ws_id, project_id, service_id) publish_private_nsfs(ws_id, service["descriptor"], False) return prepare_response( { "message": "Service {} was published to private catalogue".format( service.name) }, 201)
def create_service_on_platform(ws_id, platform_id, service_data): """ Deploys the service on the referenced Platform :param ws_id: The workspace ID :param platform_id: The platform ID :param service_data: The service descriptor data :return: A message if the function was deployed successfully """ # TODO test this! service_id = int(service_data['id']) session = db_session() try: workspace = session.query(Workspace).filter( Workspace.id == ws_id).first() project = session.query(Project). \ join(Service). \ filter(Project.services.any(Service.id == service_id)). \ filter(Project.workspace == workspace). \ first() # type: Project if not len(project.services) == 1: raise InvalidArgument( "Project must have exactly one service " "to push to platform. Number of services: {}".format( len(project.services))) platform = session.query(Platform).filter(Platform.id == platform_id). \ filter(Platform.workspace == workspace).first() package_path = pack_project(project) service_uuid = push_to_platform(package_path, platform.workspace) logger.info("Pushed to platform: " + str(service_uuid)) # deploy to private catalogue service = project.services[0].as_dict() publish_private_nsfs(ws_id, service["descriptor"], is_vnf=False) publish_referenced_functions(ws_id, project.id, service["descriptor"]) return { 'message': 'Deployed successfully: {}'.format(str(service_uuid)) } finally: session.commit()