Skip to content
Snippets Groups Projects

Resolve "(CTTC) Implement methods create/update/delete for services in the NBI debug-api plugin"

Merged Lluis Gifre Renom requested to merge feat/cttc-nbi-post-service into develop
2 files
+ 67
4
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -12,17 +12,19 @@
@@ -12,17 +12,19 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
from flask_restful import Resource
from flask_restful import Resource, request
from common.proto.context_pb2 import Empty
from common.proto.context_pb2 import Empty
from context.client.ContextClient import ContextClient
from context.client.ContextClient import ContextClient
 
from service.client.ServiceClient import ServiceClient
from .Tools import (
from .Tools import (
format_grpc_to_json, grpc_connection_id, grpc_context_id, grpc_device_id, grpc_link_id, grpc_policy_rule_id,
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):
class _Resource(Resource):
def __init__(self) -> None:
def __init__(self) -> None:
super().__init__()
super().__init__()
self.client = ContextClient()
self.client = ContextClient()
 
self.service_client = ServiceClient()
class ContextIds(_Resource):
class ContextIds(_Resource):
def get(self):
def get(self):
@@ -60,6 +62,31 @@ class Service(_Resource):
@@ -60,6 +62,31 @@ class Service(_Resource):
def get(self, context_uuid : str, service_uuid : str):
def get(self, context_uuid : str, service_uuid : str):
return format_grpc_to_json(self.client.GetService(grpc_service_id(context_uuid, service_uuid)))
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']
 
)))
 
 
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):
class SliceIds(_Resource):
def get(self, context_uuid : str):
def get(self, context_uuid : str):
return format_grpc_to_json(self.client.ListSliceIds(grpc_context_id(context_uuid)))
return format_grpc_to_json(self.client.ListSliceIds(grpc_context_id(context_uuid)))
Loading