Skip to content
Snippets Groups Projects
Commit d7e4f301 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Compute component:

- Extract changes to separate merge
parent d348e1e6
No related branches found
No related tags found
2 merge requests!142Release TeraFlowSDN 2.1,!89First implementation of location-aware services
......@@ -12,22 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from flask_restful import Resource, request
from flask_restful import Resource
from common.proto.context_pb2 import Empty
from context.client.ContextClient import ContextClient
from service.client.ServiceClient import ServiceClient
import logging
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_service, grpc_slice_id, grpc_topology_id)
LOGGER = logging.getLogger(__name__)
grpc_service_id, 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):
......@@ -64,26 +59,6 @@ class Services(_Resource):
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):
......
......@@ -13,21 +13,17 @@
# limitations under the License.
from flask.json import jsonify
from common.proto.context_pb2 import ConnectionId, ContextId, DeviceId, LinkId, ServiceId, SliceId, TopologyId, Service
from common.proto.context_pb2 import ConnectionId, ContextId, DeviceId, LinkId, ServiceId, SliceId, TopologyId
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, json_service
from common.tools.object_factory.Service import json_service_id
from common.tools.object_factory.Slice import json_slice_id
from common.tools.object_factory.Topology import json_topology_id
from common.proto.context_pb2 import ServiceStatusEnum
def format_grpc_to_json(grpc_reply):
......@@ -48,15 +44,6 @@ 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)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment