Commit 09d9f0ae authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Device component:

- Renamed device "manager" to device "controller"
parent 20ee05ab
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -28,9 +28,9 @@ from .driver_api.DriverInstanceCache import DriverInstanceCache, get_driver
from .monitoring.MonitoringLoops import MonitoringLoops
from .ErrorMessages import ERROR_MISSING_DRIVER, ERROR_MISSING_KPI
from .Tools import (
    check_connect_rules, check_no_endpoints, compute_rules_to_add_delete, configure_rules, deconfigure_rules, get_device_manager_uuid,
    populate_config_rules, populate_endpoint_monitoring_resources, populate_endpoints, populate_initial_config_rules,
    subscribe_kpi, unsubscribe_kpi, update_endpoints)
    check_connect_rules, check_no_endpoints, compute_rules_to_add_delete, configure_rules, deconfigure_rules,
    get_device_controller_uuid, populate_config_rules, populate_endpoint_monitoring_resources, populate_endpoints,
    populate_initial_config_rules, subscribe_kpi, unsubscribe_kpi, update_endpoints)

LOGGER = logging.getLogger(__name__)

@@ -125,11 +125,12 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
            if device is None:
                raise NotFoundException('Device', device_uuid, extra_details='loading in ConfigureDevice')

            device_manager_uuid = get_device_manager_uuid(device)
            if device_manager_uuid is not None:
                device = get_device(context_client, device_manager_uuid, rw_copy=True)
            device_controller_uuid = get_device_controller_uuid(device)
            if device_controller_uuid is not None:
                device = get_device(context_client, device_controller_uuid, rw_copy=True)
                if device is None:
                    raise NotFoundException('Device', device_manager_uuid, extra_details='loading in ConfigureDevice')
                    raise NotFoundException(
                        'Device', device_controller_uuid, extra_details='loading in ConfigureDevice')

            driver : _Driver = get_driver(self.driver_instance_cache, device)
            if driver is None:
+10 −10
Original line number Diff line number Diff line
@@ -78,12 +78,12 @@ def check_no_endpoints(device_endpoints) -> None:
        extra_details='RPC method AddDevice does not accept Endpoints. Endpoints are discovered through '\
                        'interrogation of the physical device.')

def get_device_manager_uuid(device : Device) -> Optional[str]:
def get_device_controller_uuid(device : Device) -> Optional[str]:
    for config_rule in device.device_config.config_rules:
        if config_rule.WhichOneof('config_rule') != 'custom': continue
        if config_rule.custom.resource_key != '_manager': continue
        device_manager_id = json.loads(config_rule.custom.resource_value)
        return device_manager_id['uuid']
        if config_rule.custom.resource_key != '_controller': continue
        device_controller_id = json.loads(config_rule.custom.resource_value)
        return device_controller_id['uuid']
    return None

def populate_endpoints(
@@ -140,13 +140,13 @@ def populate_endpoints(
            _sub_device.device_operational_status = resource_value['status']
            
            # Sub-devices should not have a driver assigned. Instead, they should have
            # a config rule specifying their manager.
            # a config rule specifying their controller.
            #_sub_device.device_drivers.extend(resource_value['drivers'])        # pylint: disable=no-member
            manager_config_rule = _sub_device.device_config.config_rules.add()
            manager_config_rule.action = ConfigActionEnum.CONFIGACTION_SET
            manager_config_rule.custom.resource_key = '_manager'
            manager = {'uuid': device_uuid, 'name': device_name}
            manager_config_rule.custom.resource_value = json.dumps(manager, indent=0, sort_keys=True)
            controller_config_rule = _sub_device.device_config.config_rules.add()
            controller_config_rule.action = ConfigActionEnum.CONFIGACTION_SET
            controller_config_rule.custom.resource_key = '_controller'
            controller = {'uuid': device_uuid, 'name': device_name}
            controller_config_rule.custom.resource_value = json.dumps(controller, indent=0, sort_keys=True)

            new_sub_devices[_sub_device_uuid] = _sub_device