From 1b92c5affa5af033c4733d1c9004d7cb3ef18f4d Mon Sep 17 00:00:00 2001 From: gifrerenom Date: Fri, 7 Jul 2023 13:06:24 +0000 Subject: [PATCH 1/2] Compute component: - Added POST service resource and endpoint --- .../nbi_plugins/debug_api/Resources.py | 26 +++++++++++- .../nbi_plugins/debug_api/Tools.py | 40 ++++++++++++++++++- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/src/compute/service/rest_server/nbi_plugins/debug_api/Resources.py b/src/compute/service/rest_server/nbi_plugins/debug_api/Resources.py index 67ef3dfb0..2d7b6bb76 100644 --- a/src/compute/service/rest_server/nbi_plugins/debug_api/Resources.py +++ b/src/compute/service/rest_server/nbi_plugins/debug_api/Resources.py @@ -12,18 +12,20 @@ # See the License for the specific language governing permissions and # limitations under the License. -from flask_restful import Resource +from flask_restful import Resource, request from common.proto.context_pb2 import Empty from context.client.ContextClient import ContextClient +from service.client.ServiceClient import ServiceClient from .Tools import ( format_grpc_to_json, grpc_connection_id, grpc_context_id, grpc_device_id, grpc_link_id, grpc_policy_rule_id, - grpc_service_id, grpc_slice_id, grpc_topology_id) + grpc_service_id, grpc_service, grpc_slice_id, grpc_topology_id) class _Resource(Resource): def __init__(self) -> None: super().__init__() self.client = ContextClient() + self.service_client = ServiceClient() class ContextIds(_Resource): def get(self): @@ -61,6 +63,26 @@ class Service(_Resource): def get(self, context_uuid : str, service_uuid : str): return format_grpc_to_json(self.client.GetService(grpc_service_id(context_uuid, service_uuid))) + def post(self, context_uuid : str, service_uuid : str): + service = request.get_json()['services'][0] + return format_grpc_to_json(self.service_client.CreateService(grpc_service( + service_uuid = service['service_id']['service_uuid']['uuid'], + service_type = service['service_type'], + context_uuid = service['service_id']['context_id']['context_uuid']['uuid'], + ))) + + def put(self, context_uuid : str, service_uuid : str): + service = request.get_json()['services'][0] + return format_grpc_to_json(self.service_client.UpdateService(grpc_service( + service_uuid = service['service_id']['service_uuid']['uuid'], + service_type = service['service_type'], + context_uuid = service['service_id']['context_id']['context_uuid']['uuid'], + status = service['service_status']['service_status'], + endpoint_ids = service['service_endpoint_ids'], + constraints = service['service_constraints'], + config_rules = service['service_config']['config_rules'] + ))) + class SliceIds(_Resource): def get(self, context_uuid : str): return format_grpc_to_json(self.client.ListSliceIds(grpc_context_id(context_uuid))) diff --git a/src/compute/service/rest_server/nbi_plugins/debug_api/Tools.py b/src/compute/service/rest_server/nbi_plugins/debug_api/Tools.py index f3dff545b..fd5eb2316 100644 --- a/src/compute/service/rest_server/nbi_plugins/debug_api/Tools.py +++ b/src/compute/service/rest_server/nbi_plugins/debug_api/Tools.py @@ -13,15 +13,20 @@ # limitations under the License. from flask.json import jsonify -from common.proto.context_pb2 import ConnectionId, ContextId, DeviceId, LinkId, ServiceId, SliceId, TopologyId +from common.proto.context_pb2 import ( + ConnectionId, ContextId, DeviceId, LinkId, ServiceId, SliceId, TopologyId, Service, ServiceStatusEnum +) from common.proto.policy_pb2 import PolicyRuleId from common.tools.grpc.Tools import grpc_message_to_json from common.tools.object_factory.Connection import json_connection_id from common.tools.object_factory.Context import json_context_id +from common.tools.object_factory.ConfigRule import json_config_rule +from common.tools.object_factory.Constraint import json_constraint_custom +from common.tools.object_factory.EndPoint import json_endpoint_id from common.tools.object_factory.Device import json_device_id from common.tools.object_factory.Link import json_link_id from common.tools.object_factory.PolicyRule import json_policyrule_id -from common.tools.object_factory.Service import json_service_id +from common.tools.object_factory.Service import json_service_id, json_service from common.tools.object_factory.Slice import json_slice_id from common.tools.object_factory.Topology import json_topology_id @@ -44,6 +49,37 @@ def grpc_link_id(link_uuid): def grpc_service_id(context_uuid, service_uuid): return ServiceId(**json_service_id(service_uuid, context_id=json_context_id(context_uuid))) +def grpc_service( + service_uuid, service_type, context_uuid, status=None, endpoint_ids=None, constraints=None, config_rules=None +): + json_context = json_context_id(context_uuid) + json_status = status if status else ServiceStatusEnum.SERVICESTATUS_PLANNED + json_endpoints_ids = [ + json_endpoint_id( + json_device_id(endpoint_id['device_id']['device_uuid']['uuid']), + endpoint_id['endpoint_uuid']['uuid'] + ) + for endpoint_id in endpoint_ids + ] if endpoint_ids else [] + json_constraints = [ + json_constraint_custom( + constraint['custom']['constraint_type'], + constraint['custom']['constraint_value'] + ) + for constraint in constraints + ] if constraints else [] + json_config_rules = [ + json_config_rule( + config_rule['action'], + config_rule['custom']['resource_key'], + config_rule['custom']['resource_value'] + ) + for config_rule in config_rules + ] if config_rules else [] + return Service(**json_service( + service_uuid, service_type, json_context, json_status, + json_endpoints_ids, json_constraints, json_config_rules)) + def grpc_slice_id(context_uuid, slice_uuid): return SliceId(**json_slice_id(slice_uuid, context_id=json_context_id(context_uuid))) -- GitLab From 69c5ce50329e013c78511c57a275bb4c73a5f3e1 Mon Sep 17 00:00:00 2001 From: gifrerenom Date: Wed, 27 Sep 2023 11:07:00 +0000 Subject: [PATCH 2/2] Compute component: - Added Service Delete REST API method --- .../service/rest_server/nbi_plugins/debug_api/Resources.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/compute/service/rest_server/nbi_plugins/debug_api/Resources.py b/src/compute/service/rest_server/nbi_plugins/debug_api/Resources.py index b3ced86c1..5573b7b02 100644 --- a/src/compute/service/rest_server/nbi_plugins/debug_api/Resources.py +++ b/src/compute/service/rest_server/nbi_plugins/debug_api/Resources.py @@ -82,6 +82,11 @@ class Service(_Resource): config_rules = service['service_config']['config_rules'] ))) + def delete(self, context_uuid : str, service_uuid : str): + return format_grpc_to_json(self.service_client.DeleteService(grpc_service_id( + context_uuid, service_uuid, + ))) + class SliceIds(_Resource): def get(self, context_uuid : str): return format_grpc_to_json(self.client.ListSliceIds(grpc_context_id(context_uuid))) -- GitLab