diff --git a/src/device/service/drivers/openconfig/OpenConfigDriver.py b/src/device/service/drivers/openconfig/OpenConfigDriver.py index c35ae9b9dc610572f77f8e139c5c6f0c76f48e77..536afcac3ce0f34b7c6be2271e2bc072a464c964 100644 --- a/src/device/service/drivers/openconfig/OpenConfigDriver.py +++ b/src/device/service/drivers/openconfig/OpenConfigDriver.py @@ -61,6 +61,7 @@ class NetconfSessionHandler: self.__port = int(port) self.__username = settings.get('username') self.__password = settings.get('password') + self.__vendor =settings.get('vendor') self.__key_filename = settings.get('key_filename') self.__hostkey_verify = settings.get('hostkey_verify', True) self.__look_for_keys = settings.get('look_for_keys', True) @@ -94,6 +95,9 @@ class NetconfSessionHandler: @property def commit_per_rule(self): return self.__commit_per_delete + @property + def vendor(self): return self.__vendor + @RETRY_DECORATOR def get(self, filter=None, with_defaults=None): # pylint: disable=redefined-builtin with self.__lock: @@ -199,7 +203,7 @@ def edit_config( chk_length(str_resource_name, resource, min_length=2, max_length=2) resource_key,resource_value = resource chk_string(str_resource_name + '.key', resource_key, allow_empty=False) - str_config_message = compose_config(resource_key, resource_value, delete=delete) + str_config_message = compose_config(resource_key, resource_value, delete=delete,vendor=netconf_handler.vendor) if str_config_message is None: raise UnsupportedResourceKeyException(resource_key) LOGGER.info('[{:s}] str_config_message[{:d}] = {:s}'.format( str_method, len(str_config_message), str(str_config_message))) diff --git a/src/device/service/drivers/openconfig/templates/__init__.py b/src/device/service/drivers/openconfig/templates/__init__.py index 901f5cf0291dca1bda155e20abd16db5989df7dc..c3da4a5f8c3dceb44011f9319125f93c23855067 100644 --- a/src/device/service/drivers/openconfig/templates/__init__.py +++ b/src/device/service/drivers/openconfig/templates/__init__.py @@ -13,7 +13,7 @@ # limitations under the License. import json, logging, lxml.etree as ET, re -from typing import Any, Dict +from typing import Any, Dict, Optional from jinja2 import Environment, PackageLoader, select_autoescape from device.service.driver_api._Driver import ( RESOURCE_ENDPOINTS, RESOURCE_INTERFACES, RESOURCE_NETWORK_INSTANCES, RESOURCE_ROUTING_POLICIES, RESOURCE_ACL) @@ -77,9 +77,9 @@ def parse(resource_key : str, xml_data : ET.Element): if parser is None: return [(resource_key, xml_data)] return parser(xml_data) -def compose_config(resource_key : str, resource_value : str, delete : bool = False) -> str: +def compose_config(resource_key : str, resource_value : str, delete : bool = False,vendor : Optional[str] = None) -> str: template_name = '{:s}/edit_config.xml'.format(RE_REMOVE_FILTERS.sub('', resource_key)) template = JINJA_ENV.get_template(template_name) data : Dict[str, Any] = json.loads(resource_value) operation = 'delete' if delete else 'merge' - return '<config>{:s}</config>'.format(template.render(**data, operation=operation).strip()) + return '<config>{:s}</config>'.format(template.render(**data, operation=operation, vendor=vendor).strip()) diff --git a/src/device/service/drivers/openconfig/templates/interface/subinterface/edit_config.xml b/src/device/service/drivers/openconfig/templates/interface/subinterface/edit_config.xml index 6eb1fbc86bb676b8e3c9d2e6b6a6bf17de2efb1f..fdfd771f603fd2f054f34e6d0ebeddfc9b4343a1 100644 --- a/src/device/service/drivers/openconfig/templates/interface/subinterface/edit_config.xml +++ b/src/device/service/drivers/openconfig/templates/interface/subinterface/edit_config.xml @@ -14,7 +14,7 @@ <config> <index>{{index}}</index> <description>{{description}}</description> - {% if vlan_id is not defined %} + {% if vendor=="ADVA" and vlan_id is not defined %} <untagged-allowed xmlns="http://www.advaoptical.com/cim/adva-dnos-oc-interfaces">true</untagged-allowed> {% endif%} </config>