Commit 80ada479 authored by Waleed Akbar's avatar Waleed Akbar
Browse files

Replaces two hub and leaf templates with generic template

parent 786fd180
Loading
Loading
Loading
Loading
+13 −23
Original line number Diff line number Diff line
@@ -98,19 +98,19 @@ if LOAD_ALL_DEVICE_DRIVERS:
            }
        ]))

if LOAD_ALL_DEVICE_DRIVERS:
    from .gnmi_openconfig.GnmiOpenConfigDriver import GnmiOpenConfigDriver # pylint: disable=wrong-import-position
    DRIVERS.append(
        (GnmiOpenConfigDriver, [
            {
                # Real Packet Router, specifying gNMI OpenConfig Driver => use GnmiOpenConfigDriver
                FilterFieldEnum.DEVICE_TYPE: [
                    DeviceTypeEnum.PACKET_POP,
                    DeviceTypeEnum.PACKET_ROUTER,
                ],
                FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_GNMI_OPENCONFIG,
            }
        ]))
# if LOAD_ALL_DEVICE_DRIVERS:
#     from .gnmi_openconfig.GnmiOpenConfigDriver import GnmiOpenConfigDriver # pylint: disable=wrong-import-position
#     DRIVERS.append(
#         (GnmiOpenConfigDriver, [
#             {
#                 # Real Packet Router, specifying gNMI OpenConfig Driver => use GnmiOpenConfigDriver
#                 FilterFieldEnum.DEVICE_TYPE: [
#                     DeviceTypeEnum.PACKET_POP,
#                     DeviceTypeEnum.PACKET_ROUTER,
#                 ],
#                 FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_GNMI_OPENCONFIG,
#             }
#         ]))

if LOAD_ALL_DEVICE_DRIVERS:
    from .gnmi_nokia_srlinux.GnmiNokiaSrLinuxDriver import GnmiNokiaSrLinuxDriver # pylint: disable=wrong-import-position
@@ -251,13 +251,3 @@ if LOAD_ALL_DEVICE_DRIVERS:
            }
        ]))
if LOAD_ALL_DEVICE_DRIVERS:
    from .netconf_dscm.NetConfDriver import NetConfDriver # pylint: disable=wrong-import-position
    DRIVERS.append(
        (NetConfDriver, [
            {
                # Real DSCM, specifying NetConf Driver => use NetConfDriver
                FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.DSCM_NODE,
                FilterFieldEnum.DRIVER     : DeviceDriverEnum.DRVICEDRIVER_NETCONF_DSCM,
            }
        ]))
+5 −18
Original line number Diff line number Diff line
@@ -137,24 +137,11 @@ def compose_config( # template generation
                templates.append(JINJA_ENV.get_template(acl_entry_path))
                templates.append(JINJA_ENV.get_template(acl_ingress_path))
        elif "pluggable" in resource_key:  # MANAGING DSCM (Digital Subcarrier Modules)
            # Resource key format: /pluggable/{template_index}/config/{template_identifier}
            # Example: /pluggable/1/config/hub or /pluggable/1/config/leaf
            # Extract template identifier (hub or leaf) from the resource key
            key_parts = resource_key.strip('/').split('/')
            if len(key_parts) >= 4 and key_parts[-1] in ['hub', 'leaf']:
                template_identifier = key_parts[-1]  # 'hub' or 'leaf'
                template_index = key_parts[1] if len(key_parts) > 1 else '1'
                
                # Build template path: pluggable/{index}/config/edit_config_{hub|leaf}_template.xml
                template_path = f'pluggable/{template_index}/config/edit_config_{template_identifier}_template.xml'
                templates.append(JINJA_ENV.get_template(template_path))
                
                LOGGER.info(f"Loading DSCM template: {template_path}")
            else:
                # Fallback to generic template if format doesn't match expected pattern
                LOGGER.warning(f"Unexpected DSCM resource key format: {resource_key}, using default template")
            # Use generic pluggable template for all devices (hub and leaf)
            # Resource key format: /pluggable/{template_index}/config
            template_name = '{:s}/edit_config.xml'.format(RE_REMOVE_FILTERS.sub('', resource_key))
            templates.append(JINJA_ENV.get_template(template_name))
            LOGGER.info(f"Loading DSCM template: {template_name}")
            
            data : Dict[str, Any] = json.loads(resource_value)
        else:
+0 −31
Original line number Diff line number Diff line
<components xmlns="http://openconfig.net/yang/platform">
    <component{% if operation is defined %} xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="{{operation}}"{% endif %}>
        <name>{{name}}</name>
        <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>
                                <subcarrier-id>{{sub_carrier.sub_carrier_id}}</subcarrier-id>
                                <active>{{sub_carrier.active}}</active>
                            </digital-subcarrier-id>
                            {% endfor %}
                        {% endif %}
                    </digital-subcarriers-group>
                    {% endfor %}
                {% endif %}
            </config>
            {% endif %}
        </optical-channel>
    </component>
</components>
+7 −25
Original line number Diff line number Diff line
@@ -60,42 +60,24 @@ class PluggablesServiceServicerImpl(PluggablesServiceServicer):
        
        LOGGER.info(f"Translated pluggable config to NETCONF format: {netconf_config}")
        
        # Step 2: Extract device IP address from _connect/address config rule
        device_address = None
        for config_rule in device.device_config.config_rules:  # type: ignore
            if config_rule.custom.resource_key == '_connect/address':  # type: ignore
                device_address = config_rule.custom.resource_value  # type: ignore
                break
        
        # Step 3: Determine the appropriate template based on device IP address (TODO: This need to be updated later)
        if device_address == '10.30.7.7':
            template_identifier = 'hub'
        elif device_address == '10.30.7.8':
            template_identifier = 'leaf'
        else:
            LOGGER.warning(f"Cannot determine device type from IP address {device_address}, defaulting to hub template")
            raise InvalidArgumentException( 'Device IP address', device_address, extra_details='Unknown device IP adress')
        
        LOGGER.info(f"Using template identifier: {template_identifier} for device {device.name} (IP: {device_address})")
        
        # Step 4: Create configuration rule with template-specific resource key
        # For simplicity, we use a fixed pluggable index of 1 for template lookup
        template_index = 1  # TODO: This should be dynamic based on actual pluggable index
        resource_key = f"/pluggable/{template_index}/config/{template_identifier}"
        # Step 2: Create configuration rule with generic pluggable template
        # Use template index 1 for standard pluggable configuration
        template_index = 1
        resource_key = f"/pluggable/{template_index}/config"
        
        # Create config rule dict and convert to protobuf
        config_json = json.dumps(netconf_config)
        config_rule_dict = json_config_rule_set(resource_key, config_json)
        config_rule = create_config_rule_from_dict(config_rule_dict)
        
        # Step 5: Create a minimal Device object with only the DSCM config rule
        # Step 3: Create a minimal Device object with only the DSCM config rule
        config_device = Device()
        config_device.device_id.device_uuid.uuid = device_uuid  # type: ignore
        config_device.device_config.config_rules.append(config_rule)  # type: ignore
        
        LOGGER.info(f"Created minimal device with config rule: resource_key={resource_key}, template={template_identifier}")
        LOGGER.info(f"Created minimal device with config rule: resource_key={resource_key}")

        # Step 6: Call ConfigureDevice to push the configuration
        # Step 4: Call ConfigureDevice to push the configuration
        try:
            device_id = self.device_client.ConfigureDevice(config_device)
            LOGGER.info(f"Successfully configured device {device_id.device_uuid.uuid}")  # type: ignore