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

Common - Tools - Descriptor:

- Added device type IP SDN Controller
- Added logic to split controllers and devices
- Controllers are onboarded first, then devices
parent b4c94e13
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ class DeviceTypeEnum(Enum):
    # Emulated device types
    EMULATED_CLIENT                 = 'emu-client'
    EMULATED_DATACENTER             = 'emu-datacenter'
    EMULATED_IP_SDN_CONTROLLER      = 'emu-ip-sdn-controller'
    EMULATED_MICROWAVE_RADIO_SYSTEM = 'emu-microwave-radio-system'
    EMULATED_OPEN_LINE_SYSTEM       = 'emu-open-line-system'
    EMULATED_OPTICAL_ROADM          = 'emu-optical-roadm'
@@ -36,6 +37,7 @@ class DeviceTypeEnum(Enum):
    # Real device types
    CLIENT                          = 'client'
    DATACENTER                      = 'datacenter'
    IP_SDN_CONTROLLER               = 'ip-sdn-controller'
    MICROWAVE_RADIO_SYSTEM          = 'microwave-radio-system'
    OPEN_LINE_SYSTEM                = 'open-line-system'
    OPTICAL_ROADM                   = 'optical-roadm'
+25 −19
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ from slice.client.SliceClient import SliceClient
from .Tools import (
    format_device_custom_config_rules, format_service_custom_config_rules, format_slice_custom_config_rules,
    get_descriptors_add_contexts, get_descriptors_add_services, get_descriptors_add_slices,
    get_descriptors_add_topologies, split_devices_by_rules)
    get_descriptors_add_topologies, split_controllers_and_network_devices, split_devices_by_rules)

LOGGER = logging.getLogger(__name__)
LOGGERS = {
@@ -59,6 +59,7 @@ ENTITY_TO_TEXT = {
    # name      => singular,     plural
    'context'   : ('Context',    'Contexts'       ),
    'topology'  : ('Topology',   'Topologies'     ),
    'controller': ('Controller', 'Controllers'    ),
    'device'    : ('Device',     'Devices'        ),
    'link'      : ('Link',       'Links'          ),
    'service'   : ('Service',    'Services'       ),
@@ -231,10 +232,12 @@ class DescriptorLoader:

    def _load_dummy_mode(self) -> None:
        # Dummy Mode: used to pre-load databases (WebUI debugging purposes) with no smart or automated tasks.
        controllers, network_devices = split_controllers_and_network_devices(self.__devices)
        self.__ctx_cli.connect()
        self._process_descr('context',    'add',    self.__ctx_cli.SetContext,    Context,    self.__contexts_add  )
        self._process_descr('topology',   'add',    self.__ctx_cli.SetTopology,   Topology,   self.__topologies_add)
        self._process_descr('device',     'add',    self.__ctx_cli.SetDevice,     Device,     self.__devices       )
        self._process_descr('controller', 'add',    self.__ctx_cli.SetDevice,     Device,     controllers          )
        self._process_descr('device',     'add',    self.__ctx_cli.SetDevice,     Device,     network_devices      )
        self._process_descr('link',       'add',    self.__ctx_cli.SetLink,       Link,       self.__links         )
        self._process_descr('service',    'add',    self.__ctx_cli.SetService,    Service,    self.__services      )
        self._process_descr('slice',      'add',    self.__ctx_cli.SetSlice,      Slice,      self.__slices        )
@@ -262,6 +265,8 @@ class DescriptorLoader:
        self.__services_add = get_descriptors_add_services(self.__services)
        self.__slices_add = get_descriptors_add_slices(self.__slices)

        controllers_add, network_devices_add = split_controllers_and_network_devices(self.__devices_add)

        self.__ctx_cli.connect()
        self.__dev_cli.connect()
        self.__svc_cli.connect()
@@ -269,7 +274,8 @@ class DescriptorLoader:

        self._process_descr('context',    'add',    self.__ctx_cli.SetContext,      Context,  self.__contexts_add  )
        self._process_descr('topology',   'add',    self.__ctx_cli.SetTopology,     Topology, self.__topologies_add)
        self._process_descr('device',   'add',    self.__dev_cli.AddDevice,       Device,   self.__devices_add   )
        self._process_descr('controller', 'add',    self.__dev_cli.AddDevice,       Device,   controllers_add      )
        self._process_descr('device',     'add',    self.__dev_cli.AddDevice,       Device,   network_devices_add  )
        self._process_descr('device',     'config', self.__dev_cli.ConfigureDevice, Device,   self.__devices_config)
        self._process_descr('link',       'add',    self.__ctx_cli.SetLink,         Link,     self.__links         )
        self._process_descr('service',    'add',    self.__svc_cli.CreateService,   Service,  self.__services_add  )
+22 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@

import copy, json
from typing import Dict, List, Optional, Tuple, Union
from common.DeviceTypes import DeviceTypeEnum

def get_descriptors_add_contexts(contexts : List[Dict]) -> List[Dict]:
    contexts_add = copy.deepcopy(contexts)
@@ -103,3 +104,24 @@ def split_devices_by_rules(devices : List[Dict]) -> Tuple[List[Dict], List[Dict]
            devices_config.append(device)

    return devices_add, devices_config

CONTROLLER_DEVICE_TYPES = {
    DeviceTypeEnum.EMULATED_IP_SDN_CONTROLLER.value,
    DeviceTypeEnum.EMULATED_MICROWAVE_RADIO_SYSTEM.value,
    DeviceTypeEnum.EMULATED_OPEN_LINE_SYSTEM.value,
    DeviceTypeEnum.IP_SDN_CONTROLLER.value,
    DeviceTypeEnum.MICROWAVE_RADIO_SYSTEM.value,
    DeviceTypeEnum.OPEN_LINE_SYSTEM.value,
    DeviceTypeEnum.TERAFLOWSDN_CONTROLLER.value,
}

def split_controllers_and_network_devices(devices : List[Dict]) -> Tuple[List[Dict], List[Dict]]:
    controllers     : List[Dict] = list()
    network_devices : List[Dict] = list()
    for device in devices:
        device_type = device.get('device_type')
        if device_type in CONTROLLER_DEVICE_TYPES:
            controllers.append(device)
        else:
            network_devices.append(device)
    return controllers, network_devices