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

SIMAP Connector - SimapUpdater:

- Correct code for dispatching devices inherited from underlaying controllers
parent 75db0234
Loading
Loading
Loading
Loading
+43 −46
Original line number Diff line number Diff line
@@ -35,6 +35,14 @@ LOGGER = logging.getLogger(__name__)
RESTCONF_LOGGER = logging.getLogger(__name__ + '.RestConfClient')


SKIPPED_DEVICE_TYPES = {
    DeviceTypeEnum.EMULATED_IP_SDN_CONTROLLER.value,
    DeviceTypeEnum.IP_SDN_CONTROLLER.value,
    DeviceTypeEnum.NCE.value,
    DeviceTypeEnum.TERAFLOWSDN_CONTROLLER.value,
}


class EventDispatcher(BaseEventDispatcher):
    def __init__(
        self, events_queue : queue.PriorityQueue,
@@ -127,12 +135,6 @@ class EventDispatcher(BaseEventDispatcher):
        device = self._object_cache.get(CachedEntities.DEVICE, device_uuid)

        device_type = device.device_type
        SKIPPED_DEVICE_TYPES = {
            DeviceTypeEnum.EMULATED_IP_SDN_CONTROLLER.value,
            DeviceTypeEnum.IP_SDN_CONTROLLER.value,
            DeviceTypeEnum.NCE.value,
            DeviceTypeEnum.TERAFLOWSDN_CONTROLLER.value,
        }
        if device_type in SKIPPED_DEVICE_TYPES:
            self._add_skipped_device(device)
            MSG = (
@@ -144,21 +146,21 @@ class EventDispatcher(BaseEventDispatcher):
            LOGGER.warning(MSG.format(str_device_event, str_device))
            return

        device_controller_uuid = device.controller_id.device_uuid.uuid
        if len(device_controller_uuid) > 0:
            self._add_skipped_device(device)
            MSG = (
                'DeviceEvent({:s}) skipped, is a remotely-managed device. '
                'SIMAP should be populated by remote controller: {:s}'
            )
            str_device_event = grpc_message_to_json_string(device_event)
            str_device = grpc_message_to_json_string(device)
            LOGGER.warning(MSG.format(str_device_event, str_device))
            return
        #device_controller_uuid = device.controller_id.device_uuid.uuid
        #if len(device_controller_uuid) > 0:
        #    self._add_skipped_device(device)
        #    MSG = (
        #        'DeviceEvent({:s}) skipped, is a remotely-managed device. '
        #        'SIMAP should be populated by remote controller: {:s}'
        #    )
        #    str_device_event = grpc_message_to_json_string(device_event)
        #    str_device = grpc_message_to_json_string(device)
        #    LOGGER.warning(MSG.format(str_device_event, str_device))
        #    return

        topology_uuid, endpoint_names = get_device_endpoint(device)
        if topology_uuid is None:
            self._add_skipped_device(device)
            #self._add_skipped_device(device)
            MSG = 'DeviceEvent({:s}) skipped, no endpoints to identify topology: {:s}'
            str_device_event = grpc_message_to_json_string(device_event)
            str_device = grpc_message_to_json_string(device)
@@ -172,8 +174,13 @@ class EventDispatcher(BaseEventDispatcher):
        te_topo.update()

        device_name = device.name
        te_topo.node(device_name).create(termination_point_ids=endpoint_names)
        self._remove_skipped_device(device)
        te_device = te_topo.node(device_name)
        te_device.update()

        for endpoint_name in endpoint_names:
            te_device.termination_point(endpoint_name).update()

        #self._remove_skipped_device(device)

        MSG = 'Device Created: {:s}'
        LOGGER.info(MSG.format(grpc_message_to_json_string(device_event)))
@@ -187,12 +194,6 @@ class EventDispatcher(BaseEventDispatcher):
        device = self._object_cache.get(CachedEntities.DEVICE, device_uuid)

        device_type = device.device_type
        SKIPPED_DEVICE_TYPES = {
            DeviceTypeEnum.EMULATED_IP_SDN_CONTROLLER.value,
            DeviceTypeEnum.IP_SDN_CONTROLLER.value,
            DeviceTypeEnum.NCE.value,
            DeviceTypeEnum.TERAFLOWSDN_CONTROLLER.value,
        }
        if device_type in SKIPPED_DEVICE_TYPES:
            self._add_skipped_device(device)
            MSG = (
@@ -204,21 +205,21 @@ class EventDispatcher(BaseEventDispatcher):
            LOGGER.warning(MSG.format(str_device_event, str_device))
            return

        device_controller_uuid = device.controller_id.device_uuid.uuid
        if len(device_controller_uuid) > 0:
            self._add_skipped_device(device)
            MSG = (
                'DeviceEvent({:s}) skipped, is a remotely-managed device. '
                'SIMAP should be updated by remote controller: {:s}'
            )
            str_device_event = grpc_message_to_json_string(device_event)
            str_device = grpc_message_to_json_string(device)
            LOGGER.warning(MSG.format(str_device_event, str_device))
            return
        #device_controller_uuid = device.controller_id.device_uuid.uuid
        #if len(device_controller_uuid) > 0:
        #    self._add_skipped_device(device)
        #    MSG = (
        #        'DeviceEvent({:s}) skipped, is a remotely-managed device. '
        #        'SIMAP should be updated by remote controller: {:s}'
        #    )
        #    str_device_event = grpc_message_to_json_string(device_event)
        #    str_device = grpc_message_to_json_string(device)
        #    LOGGER.warning(MSG.format(str_device_event, str_device))
        #    return

        topology_uuid, endpoint_names = get_device_endpoint(device)
        if topology_uuid is None:
            self._add_skipped_device(device)
            #self._add_skipped_device(device)
            MSG = 'DeviceEvent({:s}) skipped, no endpoints to identify topology: {:s}'
            str_device_event = grpc_message_to_json_string(device_event)
            str_device = grpc_message_to_json_string(device)
@@ -238,7 +239,7 @@ class EventDispatcher(BaseEventDispatcher):
        for endpoint_name in endpoint_names:
            te_device.termination_point(endpoint_name).update()

        self._remove_skipped_device(device)
        #self._remove_skipped_device(device)

        MSG = 'Device Updated: {:s}'
        LOGGER.info(MSG.format(grpc_message_to_json_string(device_event)))
@@ -252,12 +253,6 @@ class EventDispatcher(BaseEventDispatcher):
        device = self._object_cache.get(CachedEntities.DEVICE, device_uuid)

        device_type = device.device_type
        SKIPPED_DEVICE_TYPES = {
            DeviceTypeEnum.EMULATED_IP_SDN_CONTROLLER.value,
            DeviceTypeEnum.IP_SDN_CONTROLLER.value,
            DeviceTypeEnum.NCE.value,
            DeviceTypeEnum.TERAFLOWSDN_CONTROLLER.value,
        }
        if device_type in SKIPPED_DEVICE_TYPES:
            self._add_skipped_device(device)
            MSG = (
@@ -271,7 +266,9 @@ class EventDispatcher(BaseEventDispatcher):

        device_controller_uuid = device.controller_id.device_uuid.uuid
        if len(device_controller_uuid) > 0:
            self._add_skipped_device(device)
            # if it is a delete of a remotely-managed device,
            # should be managed by owner controller
            #self._add_skipped_device(device)
            MSG = (
                'DeviceEvent({:s}) skipped, is a remotely-managed device. '
                'SIMAP should be updated by remote controller: {:s}'