Commit 381bb2f3 authored by Waleed Akbar's avatar Waleed Akbar
Browse files

Enhance device configuration population and logging in OpenConfig driver for DSCM pluugable

- Updated `populate_config_rules` to accept optional resource keys for fetching specific configuration.
- Improved logging in `edit_config` to include resource key information for better traceability.
- Cleaned up XML template by removing unnecessary frequency and power fields.
parent 68229a21
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -138,8 +138,12 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
            is_optical_device = request.device_drivers[0] in OPTICAL_DRIVERS
            if len(device.device_config.config_rules) == len(connection_config_rules) and not is_optical_device:
                # created from request, populate config rules using driver
                # _connect/populate_resource_keys (comma-separated) overrides which
                # resource keys are fetched; if absent, all keys known to the driver are fetched.
                populate_keys_raw = str(connection_config_rules.get('populate_resource_keys', '')).strip()
                resource_keys = [k.strip() for k in populate_keys_raw.split(',') if k.strip()] if populate_keys_raw else None
                t7 = time.time()
                errors.extend(populate_config_rules(device, driver))
                errors.extend(populate_config_rules(device, driver, resource_keys=resource_keys))
                t8 = time.time()
                t_pop_config_rules = t8 - t7
            else:
+13 −2
Original line number Diff line number Diff line
@@ -368,9 +368,20 @@ def _raw_config_rules_to_grpc(

    return errors

def populate_config_rules(device : Device, driver : _Driver) -> List[str]:
def populate_config_rules(device : Device, driver : _Driver, resource_keys : Optional[List[str]] = None) -> List[str]:
    """Populate device config rules from the driver.

    Args:
        device: The device to populate.
        driver: The device driver.
        resource_keys: Specific resource keys to fetch (e.g. ['__inventory__', '__interfaces__']).
                       If None (default), fetches all resource keys known to the driver.
    """
    device_uuid = device.device_id.device_uuid.uuid
    if resource_keys is None:
        results_getconfig = driver.GetConfig()
    else:
        results_getconfig = driver.GetConfig(resource_keys=resource_keys)
    return _raw_config_rules_to_grpc(
        device_uuid, device.device_config, ERROR_GET, ConfigActionEnum.CONFIGACTION_SET, results_getconfig)

+2 −2
Original line number Diff line number Diff line
@@ -243,8 +243,8 @@ def edit_config(
                    resource_key, resource_value, delete=delete, vendor=netconf_handler.vendor, message_renderer=netconf_handler.message_renderer)
                for str_config_message in str_config_messages:                                                                 # configuration of the received templates
                    if str_config_message is None: raise UnsupportedResourceKeyException(resource_key)
                    logger.debug('[{:s}] str_config_message[{:d}] = {:s}'.format(
                    str_method, len(str_config_message), str(str_config_message)))
                    logger.debug('[{:s}] resource_key={:s}, str_config_message[{:d}] = {:s}'.format(
                    str_method, resource_key, len(str_config_message), str(str_config_message)))
                    netconf_handler.edit_config(                                                                               # configure the device
                        config=str_config_message, target=target, default_operation=default_operation,
                        test_option=test_option, error_option=error_option, format=format)
+0 −5
Original line number Diff line number Diff line
@@ -4,15 +4,10 @@
        <optical-channel xmlns="http://openconfig.net/yang/terminal-device-digital-subcarriers">
            {% if operation is defined and operation != 'delete' %}
            <config>
                {% if frequency is defined %}<frequency>{{frequency}}</frequency>{% endif %}
                {% if target_output_power is defined %}<target-output-power>{{target_output_power}}</target-output-power>{% endif %}
                {% if operational_mode is defined %}<operational-mode>{{operational_mode}}</operational-mode>{% endif %}

                {% if digital_sub_carriers_group is defined and digital_sub_carriers_group %}
                    {% for group in digital_sub_carriers_group %}
                    <digital-subcarriers-group>
                        <digital-subcarriers-group-id>{{group.digital_sub_carriers_group_id}}</digital-subcarriers-group-id>

                        {% if group.digital_sub_carrier_id is defined and group.digital_sub_carrier_id %}
                            {% for sub_carrier in group.digital_sub_carrier_id %}
                            <digital-subcarrier-id>