Loading src/context/service/rest_server/Resources.py +24 −2 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ from flask.json import jsonify from flask_restful import Resource from common.orm.Database import Database from common.tools.grpc.Tools import grpc_message_to_json from context.proto.context_pb2 import ConnectionId, ContextId, DeviceId, Empty, LinkId, ServiceId, TopologyId from context.proto.context_pb2 import ConnectionId, ContextId, DeviceId, Empty, LinkId, ServiceId, SliceId, TopologyId from context.service.grpc_server.ContextServiceServicerImpl import ContextServiceServicerImpl def format_grpc_to_json(grpc_reply): Loading Loading @@ -49,6 +49,12 @@ def grpc_service_id(context_uuid, service_uuid): 'service_uuid': {'uuid': service_uuid} }) def grpc_slice_id(context_uuid, slice_uuid): return SliceId(**{ 'context_id': {'context_uuid': {'uuid': context_uuid}}, 'slice_uuid': {'uuid': slice_uuid} }) def grpc_topology_id(context_uuid, topology_uuid): return TopologyId(**{ 'context_id': {'context_uuid': {'uuid': context_uuid}}, Loading Loading @@ -97,6 +103,18 @@ class Service(_Resource): def get(self, context_uuid : str, service_uuid : str): return format_grpc_to_json(self.servicer.GetService(grpc_service_id(context_uuid, service_uuid), None)) class SliceIds(_Resource): def get(self, context_uuid : str): return format_grpc_to_json(self.servicer.ListSliceIds(grpc_context_id(context_uuid), None)) class Slices(_Resource): def get(self, context_uuid : str): return format_grpc_to_json(self.servicer.ListSlices(grpc_context_id(context_uuid), None)) class Slice(_Resource): def get(self, context_uuid : str, slice_uuid : str): return format_grpc_to_json(self.servicer.GetSlice(grpc_slice_id(context_uuid, slice_uuid), None)) class DeviceIds(_Resource): def get(self): return format_grpc_to_json(self.servicer.ListDeviceIds(Empty(), None)) Loading Loading @@ -141,7 +159,7 @@ class DumpText(Resource): def get(self): db_entries = self.database.dump() num_entries = len(db_entries) response = ['----- Database Dump [{:3d} entries] -------------------------'.format(len(db_entries))] response = ['----- Database Dump [{:3d} entries] -------------------------'.format(num_entries)] for db_entry in db_entries: response.append(' [{:>4s}] {:40s} :: {:s}'.format(*db_entry)) # pragma: no cover response.append('-----------------------------------------------------------') Loading Loading @@ -185,6 +203,10 @@ RESOURCES = [ ('api.services', Services, '/context/<string:context_uuid>/services'), ('api.service', Service, '/context/<string:context_uuid>/service/<path:service_uuid>'), ('api.slice_ids', SliceIds, '/context/<string:context_uuid>/slice_ids'), ('api.slices', Slices, '/context/<string:context_uuid>/slices'), ('api.slice', Slice, '/context/<string:context_uuid>/slice/<path:slice_uuid>'), ('api.device_ids', DeviceIds, '/device_ids'), ('api.devices', Devices, '/devices'), ('api.device', Device, '/device/<string:device_uuid>'), Loading Loading
src/context/service/rest_server/Resources.py +24 −2 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ from flask.json import jsonify from flask_restful import Resource from common.orm.Database import Database from common.tools.grpc.Tools import grpc_message_to_json from context.proto.context_pb2 import ConnectionId, ContextId, DeviceId, Empty, LinkId, ServiceId, TopologyId from context.proto.context_pb2 import ConnectionId, ContextId, DeviceId, Empty, LinkId, ServiceId, SliceId, TopologyId from context.service.grpc_server.ContextServiceServicerImpl import ContextServiceServicerImpl def format_grpc_to_json(grpc_reply): Loading Loading @@ -49,6 +49,12 @@ def grpc_service_id(context_uuid, service_uuid): 'service_uuid': {'uuid': service_uuid} }) def grpc_slice_id(context_uuid, slice_uuid): return SliceId(**{ 'context_id': {'context_uuid': {'uuid': context_uuid}}, 'slice_uuid': {'uuid': slice_uuid} }) def grpc_topology_id(context_uuid, topology_uuid): return TopologyId(**{ 'context_id': {'context_uuid': {'uuid': context_uuid}}, Loading Loading @@ -97,6 +103,18 @@ class Service(_Resource): def get(self, context_uuid : str, service_uuid : str): return format_grpc_to_json(self.servicer.GetService(grpc_service_id(context_uuid, service_uuid), None)) class SliceIds(_Resource): def get(self, context_uuid : str): return format_grpc_to_json(self.servicer.ListSliceIds(grpc_context_id(context_uuid), None)) class Slices(_Resource): def get(self, context_uuid : str): return format_grpc_to_json(self.servicer.ListSlices(grpc_context_id(context_uuid), None)) class Slice(_Resource): def get(self, context_uuid : str, slice_uuid : str): return format_grpc_to_json(self.servicer.GetSlice(grpc_slice_id(context_uuid, slice_uuid), None)) class DeviceIds(_Resource): def get(self): return format_grpc_to_json(self.servicer.ListDeviceIds(Empty(), None)) Loading Loading @@ -141,7 +159,7 @@ class DumpText(Resource): def get(self): db_entries = self.database.dump() num_entries = len(db_entries) response = ['----- Database Dump [{:3d} entries] -------------------------'.format(len(db_entries))] response = ['----- Database Dump [{:3d} entries] -------------------------'.format(num_entries)] for db_entry in db_entries: response.append(' [{:>4s}] {:40s} :: {:s}'.format(*db_entry)) # pragma: no cover response.append('-----------------------------------------------------------') Loading Loading @@ -185,6 +203,10 @@ RESOURCES = [ ('api.services', Services, '/context/<string:context_uuid>/services'), ('api.service', Service, '/context/<string:context_uuid>/service/<path:service_uuid>'), ('api.slice_ids', SliceIds, '/context/<string:context_uuid>/slice_ids'), ('api.slices', Slices, '/context/<string:context_uuid>/slices'), ('api.slice', Slice, '/context/<string:context_uuid>/slice/<path:slice_uuid>'), ('api.device_ids', DeviceIds, '/device_ids'), ('api.devices', Devices, '/devices'), ('api.device', Device, '/device/<string:device_uuid>'), Loading