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

Device component:

- Activated population of sub-device drivers
parent d8b99999
Loading
Loading
Loading
Loading
+12 −13
Original line number Diff line number Diff line
@@ -100,11 +100,6 @@ def check_no_endpoints(device_endpoints) -> None:
def get_device_controller_uuid(device : Device) -> Optional[str]:
    controller_uuid = device.controller_id.device_uuid.uuid
    if len(controller_uuid) > 0: return controller_uuid
    #for config_rule in device.device_config.config_rules:
    #    if config_rule.WhichOneof('config_rule') != 'custom': continue
    #    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(
@@ -161,14 +156,18 @@ def populate_endpoints(
            _sub_device.device_type = resource_value['type']
            _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 controller.
            #_sub_device.device_drivers.extend(resource_value['drivers'])        # pylint: disable=no-member
            #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)
            # Sub-devices might not have a driver assigned.
            if 'drivers' in resource_value:
                drivers = resource_value['drivers']
                if isinstance(drivers, (list, set)):
                    _sub_device.device_drivers.extend(drivers)  # pylint: disable=no-member
                elif isinstance(drivers, (int, str)):
                    _sub_device.device_drivers.append(drivers)  # pylint: disable=no-member
                else:
                    MSG = 'Unsupported drivers definition in sub-device({:s}, {:s})'
                    raise Exception(MSG.format(str(resource_key), str(resource_value)))

            # Sub-devices should always have a controller associated.
            _sub_device.controller_id.device_uuid.uuid = device_uuid

            new_sub_devices[_sub_device_uuid] = _sub_device