Commit 93fb6d5d authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Service component:

- added helper methods to check endpoints
- updated service handlers to use new helper method
- corrected service handlers to use endpoint name from devices instead of internal endpoint UUID when composing rules for devices
- removed unneeded log messages
parent 33f71796
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -13,9 +13,10 @@
# limitations under the License.

import functools
from typing import Any, List, Union
from typing import Any, List, Optional, Tuple, Union
from common.method_wrappers.ServiceExceptions import NotFoundException
from common.proto.context_pb2 import Device, EndPoint
from common.type_checkers.Checkers import chk_length, chk_type

ACTION_MSG_SET_ENDPOINT      = 'Set EndPoint(device_uuid={:s}, endpoint_uuid={:s}, topology_uuid={:s})'
ACTION_MSG_DELETE_ENDPOINT   = 'Delete EndPoint(device_uuid={:s}, endpoint_uuid={:s}, topology_uuid={:s})'
@@ -51,3 +52,9 @@ def get_endpoint_matching(device : Device, endpoint_uuid_or_name : str) -> EndPo
    device_uuid = device.device_id.device_uuid.uuid
    extra_details = 'Device({:s})'.format(str(device_uuid))
    raise NotFoundException('Endpoint', endpoint_uuid_or_name, extra_details=extra_details)

def get_device_endpoint_uuids(endpoint : Tuple[str, str, Optional[str]]) -> Tuple[str, str]:
    chk_type('endpoint', endpoint, (tuple, list))
    chk_length('endpoint', endpoint, min_length=2, max_length=3)
    device_uuid, endpoint_uuid = endpoint[0:2] # ignore topology_uuid by now
    return device_uuid, endpoint_uuid
+4 −4
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ from common.tools.object_factory.ConfigRule import json_config_rule_delete, json
from service.service.service_handler_api.AnyTreeTools import TreeNode

def setup_config_rules(
    service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str,
    service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, endpoint_name : str,
    service_settings : TreeNode, endpoint_settings : TreeNode
) -> List[Dict]:

@@ -38,7 +38,7 @@ def setup_config_rules(
    remote_router       = json_endpoint_settings.get('remote_router',       '0.0.0.0')  # '5.5.5.5'
    circuit_id          = json_endpoint_settings.get('circuit_id',          '000'    )  # '111'

    if_cirid_name         = '{:s}.{:s}'.format(endpoint_uuid, str(circuit_id))
    if_cirid_name         = '{:s}.{:s}'.format(endpoint_name, str(circuit_id))
    network_instance_name = 'ELAN-AC:{:s}'.format(str(circuit_id))
    connection_point_id   = 'VC-1'

@@ -76,7 +76,7 @@ def setup_config_rules(
    return json_config_rules

def teardown_config_rules(
    service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str,
    service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, endpoint_name : str,
    service_settings : TreeNode, endpoint_settings : TreeNode
) -> List[Dict]:

@@ -97,7 +97,7 @@ def teardown_config_rules(
    #remote_router       = json_endpoint_settings.get('remote_router',       '0.0.0.0')  # '5.5.5.5'
    circuit_id          = json_endpoint_settings.get('circuit_id',          '000'    )  # '111'

    if_cirid_name         = '{:s}.{:s}'.format(endpoint_uuid, str(circuit_id))
    if_cirid_name         = '{:s}.{:s}'.format(endpoint_name, str(circuit_id))
    network_instance_name = 'ELAN-AC:{:s}'.format(str(circuit_id))
    connection_point_id   = 'VC-1'

+10 −10
Original line number Diff line number Diff line
@@ -17,8 +17,8 @@ from typing import Any, List, Optional, Tuple, Union
from common.method_wrappers.Decorator import MetricTypeEnum, MetricsPool, metered_subclass_method, INF
from common.proto.context_pb2 import ConfigRule, DeviceId, Service
from common.tools.object_factory.Device import json_device_id
from common.type_checkers.Checkers import chk_length, chk_type
from service.service.service_handler_api.Tools import get_endpoint_matching
from common.type_checkers.Checkers import chk_type
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.service_handler_api.SettingsHandler import SettingsHandler
from service.service.task_scheduler.TaskExecutor import TaskExecutor
@@ -64,16 +64,16 @@ class L2NMEmulatedServiceHandler(_ServiceHandler):
        results = []
        for endpoint in endpoints:
            try:
                chk_type('endpoint', endpoint, (tuple, list))
                chk_length('endpoint', endpoint, min_length=2, max_length=3)
                device_uuid, endpoint_uuid = endpoint[0:2] # ignore topology_uuid by now
                device_uuid, endpoint_uuid = get_device_endpoint_uuids(endpoint)

                device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid)))
                endpoint_obj = get_endpoint_matching(device_obj, endpoint_uuid)
                endpoint_settings = self.__settings_handler.get_endpoint_settings(device_obj, endpoint_obj)
                endpoint_name = endpoint_obj.name

                json_config_rules = setup_config_rules(
                    service_uuid, connection_uuid, device_uuid, endpoint_uuid, settings, endpoint_settings)
                    service_uuid, connection_uuid, device_uuid, endpoint_uuid, endpoint_name,
                    settings, endpoint_settings)

                del device_obj.device_config.config_rules[:]
                for json_config_rule in json_config_rules:
@@ -99,16 +99,16 @@ class L2NMEmulatedServiceHandler(_ServiceHandler):
        results = []
        for endpoint in endpoints:
            try:
                chk_type('endpoint', endpoint, (tuple, list))
                chk_length('endpoint', endpoint, min_length=2, max_length=3)
                device_uuid, endpoint_uuid = endpoint[0:2] # ignore topology_uuid by now
                device_uuid, endpoint_uuid = get_device_endpoint_uuids(endpoint)

                device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid)))
                endpoint_obj = get_endpoint_matching(device_obj, endpoint_uuid)
                endpoint_settings = self.__settings_handler.get_endpoint_settings(device_obj, endpoint_obj)
                endpoint_name = endpoint_obj.name

                json_config_rules = teardown_config_rules(
                    service_uuid, connection_uuid, device_uuid, endpoint_uuid, settings, endpoint_settings)
                    service_uuid, connection_uuid, device_uuid, endpoint_uuid, endpoint_name,
                    settings, endpoint_settings)

                del device_obj.device_config.config_rules[:]
                for json_config_rule in json_config_rules:
+4 −4
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ from common.tools.object_factory.ConfigRule import json_config_rule_delete, json
from service.service.service_handler_api.AnyTreeTools import TreeNode

def setup_config_rules(
    service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str,
    service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, endpoint_name : str,
    service_settings : TreeNode, endpoint_settings : TreeNode
) -> List[Dict]:

@@ -38,7 +38,7 @@ def setup_config_rules(
    remote_router       = json_endpoint_settings.get('remote_router',       '0.0.0.0')  # '5.5.5.5'
    circuit_id          = json_endpoint_settings.get('circuit_id',          '000'    )  # '111'

    if_cirid_name         = '{:s}.{:s}'.format(endpoint_uuid, str(circuit_id))
    if_cirid_name         = '{:s}.{:s}'.format(endpoint_name, str(circuit_id))
    network_instance_name = 'ELAN-AC:{:s}'.format(str(circuit_id))
    connection_point_id   = 'VC-1'

@@ -76,7 +76,7 @@ def setup_config_rules(
    return json_config_rules

def teardown_config_rules(
    service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str,
    service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, endpoint_name : str,
    service_settings : TreeNode, endpoint_settings : TreeNode
) -> List[Dict]:

@@ -97,7 +97,7 @@ def teardown_config_rules(
    #remote_router       = json_endpoint_settings.get('remote_router',       '0.0.0.0')  # '5.5.5.5'
    circuit_id          = json_endpoint_settings.get('circuit_id',          '000'    )  # '111'

    if_cirid_name         = '{:s}.{:s}'.format(endpoint_uuid, str(circuit_id))
    if_cirid_name         = '{:s}.{:s}'.format(endpoint_name, str(circuit_id))
    network_instance_name = 'ELAN-AC:{:s}'.format(str(circuit_id))
    connection_point_id   = 'VC-1'

+10 −10
Original line number Diff line number Diff line
@@ -17,8 +17,8 @@ from typing import Any, List, Optional, Tuple, Union
from common.method_wrappers.Decorator import MetricTypeEnum, MetricsPool, metered_subclass_method, INF
from common.proto.context_pb2 import ConfigRule, DeviceId, Service
from common.tools.object_factory.Device import json_device_id
from common.type_checkers.Checkers import chk_length, chk_type
from service.service.service_handler_api.Tools import get_endpoint_matching
from common.type_checkers.Checkers import chk_type
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.service_handler_api.SettingsHandler import SettingsHandler
from service.service.task_scheduler.TaskExecutor import TaskExecutor
@@ -64,16 +64,16 @@ class L2NMOpenConfigServiceHandler(_ServiceHandler):
        results = []
        for endpoint in endpoints:
            try:
                chk_type('endpoint', endpoint, (tuple, list))
                chk_length('endpoint', endpoint, min_length=2, max_length=3)
                device_uuid, endpoint_uuid = endpoint[0:2] # ignore topology_uuid by now
                device_uuid, endpoint_uuid = get_device_endpoint_uuids(endpoint)

                device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid)))
                endpoint_obj = get_endpoint_matching(device_obj, endpoint_uuid)
                endpoint_settings = self.__settings_handler.get_endpoint_settings(device_obj, endpoint_obj)
                endpoint_name = endpoint_obj.name

                json_config_rules = setup_config_rules(
                    service_uuid, connection_uuid, device_uuid, endpoint_uuid, settings, endpoint_settings)
                    service_uuid, connection_uuid, device_uuid, endpoint_uuid, endpoint_name,
                    settings, endpoint_settings)

                del device_obj.device_config.config_rules[:]
                for json_config_rule in json_config_rules:
@@ -99,16 +99,16 @@ class L2NMOpenConfigServiceHandler(_ServiceHandler):
        results = []
        for endpoint in endpoints:
            try:
                chk_type('endpoint', endpoint, (tuple, list))
                chk_length('endpoint', endpoint, min_length=2, max_length=3)
                device_uuid, endpoint_uuid = endpoint[0:2] # ignore topology_uuid by now
                device_uuid, endpoint_uuid = get_device_endpoint_uuids(endpoint)

                device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid)))
                endpoint_obj = get_endpoint_matching(device_obj, endpoint_uuid)
                endpoint_settings = self.__settings_handler.get_endpoint_settings(device_obj, endpoint_obj)
                endpoint_name = endpoint_obj.name

                json_config_rules = teardown_config_rules(
                    service_uuid, connection_uuid, device_uuid, endpoint_uuid, settings, endpoint_settings)
                    service_uuid, connection_uuid, device_uuid, endpoint_uuid, endpoint_name,
                    settings, endpoint_settings)

                del device_obj.device_config.config_rules[:]
                for json_config_rule in json_config_rules:
Loading