Commit bb410f9b authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Service component - L3NM Ryu Service Handler:

- Fixed imports, typehints
- Added methods Set/Delete Config/Constraints
parent 45a9df42
Loading
Loading
Loading
Loading
+54 −3
Original line number Original line Diff line number Diff line
@@ -21,9 +21,10 @@ from common.tools.grpc.Tools import grpc_message_to_json_string
from common.tools.object_factory.ConfigRule import json_config_rule_delete, json_config_rule_set
from common.tools.object_factory.ConfigRule import json_config_rule_delete, json_config_rule_set
from common.tools.object_factory.Device import json_device_id
from common.tools.object_factory.Device import json_device_id
from common.type_checkers.Checkers import chk_type
from common.type_checkers.Checkers import chk_type
from service.service.service_handler_api._ServiceHandler import _ServiceHandler
from service.service.service_handler_api.AnyTreeTools import TreeNode
from service.service.service_handler_api.SettingsHandler import SettingsHandler
from service.service.service_handler_api.SettingsHandler import SettingsHandler
from service.service.service_handler_api.Tools import get_device_endpoint_uuids, get_endpoint_matching
from service.service.service_handler_api.Tools import get_device_endpoint_uuids, get_endpoint_matching
from service.service.service_handler_api._ServiceHandler import _ServiceHandler
from service.service.task_scheduler.TaskExecutor import TaskExecutor
from service.service.task_scheduler.TaskExecutor import TaskExecutor


LOGGER = logging.getLogger(__name__)
LOGGER = logging.getLogger(__name__)
@@ -42,8 +43,8 @@ class EndpointData:


    @classmethod
    @classmethod
    def create(
    def create(
        cls, device_obj : Device, endpoint_obj : Endpoint, endpoint_settings : Optional[TreeNode]
        cls, device_obj : Device, endpoint_obj : EndPoint, endpoint_settings : Optional[TreeNode]
    ) -> 'EndpointIds':
    ) -> 'EndpointData':
        device_uuid    = device_obj.device_id.device_uuid.uuid
        device_uuid    = device_obj.device_id.device_uuid.uuid
        ep_device_uuid = endpoint_obj.endpoint_id.device_id.device_uuid.uuid
        ep_device_uuid = endpoint_obj.endpoint_id.device_id.device_uuid.uuid
        if device_uuid != ep_device_uuid:
        if device_uuid != ep_device_uuid:
@@ -243,3 +244,53 @@ class L3NMRyuServiceHandler(_ServiceHandler):
        except Exception as e:
        except Exception as e:
            LOGGER.exception("Error in SetEndpoint")
            LOGGER.exception("Error in SetEndpoint")
            return [e]
            return [e]

    @metered_subclass_method(METRICS_POOL)
    def SetConstraint(self, constraints : List[Tuple[str, Any]]) -> List[Union[bool, Exception]]:
        chk_type('constraints', constraints, list)
        if len(constraints) == 0: return []

        msg = '[SetConstraint] Method not implemented. Constraints({:s}) are being ignored.'
        LOGGER.warning(msg.format(str(constraints)))
        return [True for _ in range(len(constraints))]

    @metered_subclass_method(METRICS_POOL)
    def DeleteConstraint(self, constraints : List[Tuple[str, Any]]) -> List[Union[bool, Exception]]:
        chk_type('constraints', constraints, list)
        if len(constraints) == 0: return []

        msg = '[DeleteConstraint] Method not implemented. Constraints({:s}) are being ignored.'
        LOGGER.warning(msg.format(str(constraints)))
        return [True for _ in range(len(constraints))]

    @metered_subclass_method(METRICS_POOL)
    def SetConfig(self, resources : List[Tuple[str, Any]]) -> List[Union[bool, Exception]]:
        chk_type('resources', resources, list)
        if len(resources) == 0: return []

        results = []
        for resource in resources:
            try:
                resource_value = json.loads(resource[1])
                self.__settings_handler.set(resource[0], resource_value)
                results.append(True)
            except Exception as e: # pylint: disable=broad-except
                LOGGER.exception('Unable to SetConfig({:s})'.format(str(resource)))
                results.append(e)

        return results

    @metered_subclass_method(METRICS_POOL)
    def DeleteConfig(self, resources : List[Tuple[str, Any]]) -> List[Union[bool, Exception]]:
        chk_type('resources', resources, list)
        if len(resources) == 0: return []

        results = []
        for resource in resources:
            try:
                self.__settings_handler.delete(resource[0])
            except Exception as e: # pylint: disable=broad-except
                LOGGER.exception('Unable to DeleteConfig({:s})'.format(str(resource)))
                results.append(e)

        return results