diff --git a/src/device/service/drivers/gnmi_openconfig/handlers/Component.py b/src/device/service/drivers/gnmi_openconfig/handlers/Component.py index fab4722330a398330d1025bcf85fe0d975812960..6f26bee86e24bbdeb86be67641e009bf7f6e52cf 100644 --- a/src/device/service/drivers/gnmi_openconfig/handlers/Component.py +++ b/src/device/service/drivers/gnmi_openconfig/handlers/Component.py @@ -17,6 +17,7 @@ from typing import Any, Dict, List, Tuple from common.proto.kpi_sample_types_pb2 import KpiSampleType from ._Handler import _Handler from .YangHandler import YangHandler +from inter_device_translation import get_dict_helper LOGGER = logging.getLogger(__name__) @@ -24,8 +25,11 @@ PATH_IF_CTR = '/openconfig-interfaces:interfaces/interface[name={:s}]/state/coun #pylint: disable=abstract-method class ComponentHandler(_Handler): + def __init__(self, device_type=None): + self._dict_helper = get_dict_helper(device_type) + def get_resource_key(self) -> str: return '/endpoints/endpoint' - def get_path(self) -> str: return '/openconfig-platform:components' + def get_path(self) -> str: return self._dict_helper.get_path('components') def parse( self, json_data : Dict, yang_handler : YangHandler @@ -36,7 +40,7 @@ class ComponentHandler(_Handler): json_data_valid = yang_handler.parse_to_dict(yang_components_path, json_data, fmt='json') entries = [] - for component in json_data_valid['components']['component']: + for component in json_data_valid[self._dict_helper.get_object('components')][self._dict_helper.get_object('component')]: LOGGER.debug('component={:s}'.format(str(component))) component_name = component['name'] diff --git a/src/device/service/drivers/openconfig/templates/EndPoints.py b/src/device/service/drivers/openconfig/templates/EndPoints.py index dc607cb6763d38153cada21d9e2794d4ea128f07..ab745e282ffb5dfd47d22c9b7e54cf88642098f2 100644 --- a/src/device/service/drivers/openconfig/templates/EndPoints.py +++ b/src/device/service/drivers/openconfig/templates/EndPoints.py @@ -17,6 +17,7 @@ from typing import Any, Dict, List, Tuple from common.proto.kpi_sample_types_pb2 import KpiSampleType from .Namespace import NAMESPACES from .Tools import add_value_from_collection, add_value_from_tag +from inter_device_translation import get_dict_helper, DictHelper LOGGER = logging.getLogger(__name__) diff --git a/src/device/service/drivers/openconfig/templates/Interfaces.py b/src/device/service/drivers/openconfig/templates/Interfaces.py index aea737100bcd980a097d2d2254750e44d59809a0..4efcd324b1959db54ae908a006f5c1c12c9874d6 100644 --- a/src/device/service/drivers/openconfig/templates/Interfaces.py +++ b/src/device/service/drivers/openconfig/templates/Interfaces.py @@ -16,6 +16,7 @@ import logging, lxml.etree as ET from typing import Any, Dict, List, Tuple from .Namespace import NAMESPACES from .Tools import add_value_from_tag +from inter_device_translation import get_dict_helper, DictHelper LOGGER = logging.getLogger(__name__) diff --git a/src/device/service/drivers/openconfig/templates/Namespace.py b/src/device/service/drivers/openconfig/templates/Namespace.py index 4604481bb666365752e33e9a8ef3bcf8523e6d1c..ec2177d53dcc2ded79239a04a2250c7978be3d45 100644 --- a/src/device/service/drivers/openconfig/templates/Namespace.py +++ b/src/device/service/drivers/openconfig/templates/Namespace.py @@ -30,6 +30,10 @@ NAMESPACE_ROUTING_POLICY = 'http://openconfig.net/yang/routing-policy' NAMESPACE_VLAN = 'http://openconfig.net/yang/vlan' NAMESPACE_PLATFORM_TRANSCEIVER = 'http://openconfig.net/yang/platform/transceiver' +NAMESPACE_IPI_INTERFACE = 'http://www.ipinfusion.com/yang/ocnos/ipi-interface' +NAMESPACE_IPI_INTERFACE_EXTENDED = 'http://www.ipinfusion.com/yang/ocnos/ipi-if-extended' +NAMESPACE_IPI_INTERFACE_IP = 'http://www.ipinfusion.com/yang/ocnos/ipi-if-ip' + NAMESPACES = { 'nc' : NAMESPACE_NETCONF, 'ocacl': NAMESPACE_ACL, @@ -46,4 +50,8 @@ NAMESPACES = { 'ocrp' : NAMESPACE_ROUTING_POLICY, 'ocv' : NAMESPACE_VLAN, 'ocptr': NAMESPACE_PLATFORM_TRANSCEIVER, + + 'ipii': NAMESPACE_IPI_INTERFACE, + 'ipiie': NAMESPACE_IPI_INTERFACE_EXTENDED, + 'ipiiip': NAMESPACE_IPI_INTERFACE_IP, } diff --git a/src/device/service/drivers/openconfig/templates/component/get.xml b/src/device/service/drivers/openconfig/templates/component/get.xml index aa25ed1e3b11e0c324b361eb52d064dac87a64c5..1f98ca78f78ec98e1e1af294590b399c1d03102a 100644 --- a/src/device/service/drivers/openconfig/templates/component/get.xml +++ b/src/device/service/drivers/openconfig/templates/component/get.xml @@ -1,3 +1,3 @@ - - - +<{{components}}> + <{{component}}/> + diff --git a/src/device/service/drivers/openconfig/templates/interface/get.xml b/src/device/service/drivers/openconfig/templates/interface/get.xml index c0867655bd325ee9c3cdd74077ac905e36808d5f..26cc3e9662681546f50e99fd8ff8601f54bee0e0 100644 --- a/src/device/service/drivers/openconfig/templates/interface/get.xml +++ b/src/device/service/drivers/openconfig/templates/interface/get.xml @@ -1,3 +1,3 @@ - - - +<{{interfaces}}> + <{{interface}}/> + diff --git a/src/inter_device_translation/__init__.py b/src/inter_device_translation/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..98d44dd8bc2d9390126f6ba673368ff92fd27c0e --- /dev/null +++ b/src/inter_device_translation/__init__.py @@ -0,0 +1,55 @@ +import yaml + + +with open('config/config.yml') as cfg: + config : dict = yaml.safe_load(cfg) + +dict_name = config.get('name') +dict_default = config.get('default') + + +class DictHelper: + def __init__(self, file): + self.file = file + + def _read(self) -> dict: + with open(self.file) as cfg: + return yaml.safe_load(cfg) + + def get_object(self, name, plural=False) -> str: + return self._read().get(name).get('plural' if plural else 'singular') + + def get_namespaces(self, name) -> str: + return self._read().get(name) + + def get_path(self, name) -> str: + path_details = self._read().get(name) + + path : str = path_details.get('path') + namespace = path_details.get('namespace') + + if namespace is None: + return path + + path_segments = path.split('/') + required_namespaces = len([s for s in path_segments if len(s > 1)]) + + if type(namespace) == list and len(namespace) != required_namespaces: + raise Exception(f'Number of namespaces do not match the specified path : {path}') + + elif type(namespace) == str: + namespace = [namespace for _ in range(required_namespaces)] + + ns_i = 0 + processed_segments = [] + for s in path_segments: + if len(s) > 1: + processed_segments.append(f'{namespace[ns_i]}:{s}') + ns_i += 1 + else: + processed_segments.append(s) + + +def get_dict_helper(dict_type = None) -> DictHelper: + if dict_type is None: dict_type = dict_default + return DictHelper(f'config/{dict_name}.{dict_type}.yml') diff --git a/src/inter_device_translation/config/config.yml b/src/inter_device_translation/config/config.yml new file mode 100644 index 0000000000000000000000000000000000000000..37f7fb1fe36346ab0986897b017a30f65bcde803 --- /dev/null +++ b/src/inter_device_translation/config/config.yml @@ -0,0 +1,2 @@ +name: dict +default: oc \ No newline at end of file diff --git a/src/inter_device_translation/config/dict.ipi.yml b/src/inter_device_translation/config/dict.ipi.yml new file mode 100644 index 0000000000000000000000000000000000000000..5db6eaa8db4cc6eb5ddc8483a139aeeda95c2db2 --- /dev/null +++ b/src/inter_device_translation/config/dict.ipi.yml @@ -0,0 +1,13 @@ +namespaces: + interfaces: ipii + interfaces_ip: ipiiip + +objects: + components: + singular: interface + plural: interfaces + +paths: + component_type: + namespace: ipiie + path: extended/state/hardware-type \ No newline at end of file diff --git a/src/inter_device_translation/config/dict.oc.yml b/src/inter_device_translation/config/dict.oc.yml new file mode 100644 index 0000000000000000000000000000000000000000..437783f9c1493b3e2c1695af0899cc9f460796dc --- /dev/null +++ b/src/inter_device_translation/config/dict.oc.yml @@ -0,0 +1,13 @@ +namespaces: + interfaces: oci + interfaces_ip: ociip + +objects: + components: + singular: component + plural: components + +paths: + component_type: + namespace: ocpp + path: port/breakout-mode/state/channel-speed \ No newline at end of file