Loading src/device/service/drivers/gnmi_openconfig/GnmiSessionHandler.py +9 −4 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ class GnmiSessionHandler: self._username = settings.get('username') self._password = settings.get('password') self._use_tls = settings.get('use_tls', False) self._vendor = settings.get('vendor') self._channel : Optional[grpc.Channel] = None self._stub : Optional[gNMIStub] = None self._monit_thread = None Loading @@ -64,6 +65,10 @@ class GnmiSessionHandler: @property def out_samples(self): return self._out_samples @property def device_type(self): return self._vendor.lower() if self._vendor else 'oc' def connect(self): with self._lock: self._channel = get_grpc_channel(self._address, self._port, self._use_tls, self._logger) Loading Loading @@ -97,7 +102,7 @@ class GnmiSessionHandler: try: chk_string(str_resource_name, resource_key, allow_empty=False) self._logger.debug('[GnmiSessionHandler:get] resource_key = {:s}'.format(str(resource_key))) str_path = get_path(resource_key) str_path = get_path(resource_key, self.device_type) self._logger.debug('[GnmiSessionHandler:get] str_path = {:s}'.format(str(str_path))) get_request.path.append(path_from_string(str_path)) except Exception as e: # pylint: disable=broad-except Loading Loading @@ -141,7 +146,7 @@ class GnmiSessionHandler: value = decode_value(update.val) #resource_key_tuple[1] = value #resource_key_tuple[2] = True results.extend(parse(str_path, value, self._yang_handler)) results.extend(parse(str_path, value, self._yang_handler, self.device_type)) except Exception as e: # pylint: disable=broad-except MSG = 'Exception processing update {:s}' self._logger.exception(MSG.format(grpc_message_to_json_string(update))) Loading Loading @@ -178,7 +183,7 @@ class GnmiSessionHandler: #if resource_tuple is None: continue #_, value, exists, operation_done = resource_tuple if isinstance(resource_value, str): resource_value = json.loads(resource_value) str_path, str_data = compose(resource_key, resource_value, self._yang_handler, delete=False) str_path, str_data = compose(resource_key, resource_value, self._yang_handler, delete=False, device_type=self.device_type) if str_path is None: continue # nothing to set #self._logger.info('---3') #self._logger.info(str(str_path)) Loading Loading @@ -252,7 +257,7 @@ class GnmiSessionHandler: #if not exists: continue if isinstance(resource_value, str): resource_value = json.loads(resource_value) # pylint: disable=unused-variable str_path, str_data = compose(resource_key, resource_value, self._yang_handler, delete=True) str_path, str_data = compose(resource_key, resource_value, self._yang_handler, delete=True, device_type=self.device_type) if str_path is None: continue # nothing to do with this resource_key #self._logger.info('---3') #self._logger.info(str(str_path)) Loading src/device/service/drivers/gnmi_openconfig/handlers/Acl.py +6 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ from typing import Any, Dict, List, Tuple import libyang from inter_device_translation import get_dict_helper from ._Handler import _Handler from .YangHandler import YangHandler Loading @@ -43,11 +44,14 @@ _OC_TFS_FWD_ACTION = {v: k for k, v in _TFS_OC_FWD_ACTION.items()} class AclHandler(_Handler): def __init__(self, device_type=None): self._dict_helper = get_dict_helper(device_type or 'oc') def get_resource_key(self) -> str: return '/device/endpoint/acl_ruleset' def get_path(self) -> str: return '/openconfig-acl:acl' return self._dict_helper.get_path('acl') def compose( # pylint: disable=too-many-locals self, Loading @@ -66,7 +70,7 @@ class AclHandler(_Handler): path = f'/acl/acl-sets/acl-set[name={rs_name}][type={oc_type}]' return path, '' yang_acl: libyang.DContainer = yang.get_data_path('/openconfig-acl:acl') yang_acl: libyang.DContainer = yang.get_data_path(self._dict_helper.get_path('acl')) y_sets = yang_acl.create_path('acl-sets') y_set = y_sets.create_path(f'acl-set[name="{rs_name}"][type="{oc_type}"]') Loading src/device/service/drivers/gnmi_openconfig/handlers/Component.py +14 −8 Original line number Diff line number Diff line Loading @@ -17,15 +17,19 @@ 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__) PATH_IF_CTR = '/openconfig-interfaces:interfaces/interface[name={:s}]/state/counters/{:s}' # Path will be constructed dynamically using device translation #pylint: disable=abstract-method class ComponentHandler(_Handler): def __init__(self, device_type=None): self._dict_helper = get_dict_helper(device_type or 'oc') 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 Loading @@ -36,7 +40,8 @@ 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', plural=True)][self._dict_helper.get_object('components')]: LOGGER.debug('component={:s}'.format(str(component))) component_name = component['name'] Loading @@ -59,12 +64,13 @@ class ComponentHandler(_Handler): endpoint = {'uuid': interface_name, 'type': '-'} endpoint['sample_types'] = { KpiSampleType.KPISAMPLETYPE_BYTES_RECEIVED : PATH_IF_CTR.format(interface_name, 'in-octets' ), KpiSampleType.KPISAMPLETYPE_BYTES_TRANSMITTED : PATH_IF_CTR.format(interface_name, 'out-octets'), KpiSampleType.KPISAMPLETYPE_PACKETS_RECEIVED : PATH_IF_CTR.format(interface_name, 'in-pkts' ), KpiSampleType.KPISAMPLETYPE_PACKETS_TRANSMITTED: PATH_IF_CTR.format(interface_name, 'out-pkts' ), KpiSampleType.KPISAMPLETYPE_BYTES_RECEIVED : self._dict_helper.get_path('interface_counters', name=interface_name, counter='in-octets'), KpiSampleType.KPISAMPLETYPE_BYTES_TRANSMITTED : self._dict_helper.get_path('interface_counters', name=interface_name, counter='out-octets'), KpiSampleType.KPISAMPLETYPE_PACKETS_RECEIVED : self._dict_helper.get_path('interface_counters', name=interface_name, counter='in-pkts'), KpiSampleType.KPISAMPLETYPE_PACKETS_TRANSMITTED: self._dict_helper.get_path('interface_counters', name=interface_name, counter='out-pkts'), } entries.append(('/endpoints/endpoint[{:s}]'.format(endpoint['uuid']), endpoint)) resource_key = self._dict_helper.get_resource_key('endpoints_endpoint', uuid=endpoint['uuid']) entries.append((resource_key, endpoint)) return entries src/device/service/drivers/gnmi_openconfig/handlers/Interface.py +8 −4 Original line number Diff line number Diff line Loading @@ -17,12 +17,17 @@ from typing import Any, Dict, List, Tuple from ._Handler import _Handler from .Tools import get_bool, get_int, get_str from .YangHandler import YangHandler from inter_device_translation import get_dict_helper LOGGER = logging.getLogger(__name__) class InterfaceHandler(_Handler): def __init__(self, device_type=None): self._dict_helper = get_dict_helper(device_type or 'oc') def get_resource_key(self) -> str: return '/interface/subinterface' def get_path(self) -> str: return '/openconfig-interfaces:interfaces' def get_path(self) -> str: return self._dict_helper.get_path('interfaces') def compose( self, resource_key : str, resource_value : Dict, yang_handler : YangHandler, delete : bool = False Loading @@ -31,8 +36,7 @@ class InterfaceHandler(_Handler): sif_index = get_int(resource_value, 'index', 0) # 0 if delete: PATH_TMPL = '/interfaces/interface[name={:s}]/subinterfaces/subinterface[index={:d}]' str_path = PATH_TMPL.format(if_name, sif_index) str_path = self._dict_helper.get_path('interface_subinterface', name=if_name, index=sif_index) str_data = json.dumps({}) root_node : libyang.DContainer = yang_handler.get_data_path( Loading @@ -58,7 +62,7 @@ class InterfaceHandler(_Handler): address_prefix = get_int (resource_value, 'address_prefix') # 24 mtu = get_int (resource_value, 'mtu' ) # 1500 yang_ifs : libyang.DContainer = yang_handler.get_data_path('/openconfig-interfaces:interfaces') yang_ifs : libyang.DContainer = yang_handler.get_data_path(self._dict_helper.get_path('interfaces')) yang_if_path = 'interface[name="{:s}"]'.format(if_name) yang_if : libyang.DContainer = yang_ifs.create_path(yang_if_path) yang_if.create_path('config/name', if_name ) Loading src/device/service/drivers/gnmi_openconfig/handlers/InterfaceCounter.py +7 −2 Original line number Diff line number Diff line Loading @@ -16,13 +16,18 @@ import json, libyang, logging from typing import Any, Dict, List, Tuple from ._Handler import _Handler from .YangHandler import YangHandler from inter_device_translation import get_dict_helper LOGGER = logging.getLogger(__name__) #pylint: disable=abstract-method class InterfaceCounterHandler(_Handler): def __init__(self, device_type=None): self._dict_helper = get_dict_helper(device_type or 'oc') def get_resource_key(self) -> str: return '/interface/counters' def get_path(self) -> str: return '/openconfig-interfaces:interfaces/interface/state/counters' def get_path(self) -> str: return self._dict_helper.get_path('interface_counters_path') def parse( self, json_data : Dict, yang_handler : YangHandler Loading Loading @@ -58,7 +63,7 @@ class InterfaceCounterHandler(_Handler): } LOGGER.debug('interface = {:s}'.format(str(interface))) entry_interface_key = '/interface[{:s}]'.format(interface_name) entry_interface_key = self._dict_helper.get_resource_key('interface', name=interface_name) entries.append((entry_interface_key, _interface)) return entries Loading
src/device/service/drivers/gnmi_openconfig/GnmiSessionHandler.py +9 −4 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ class GnmiSessionHandler: self._username = settings.get('username') self._password = settings.get('password') self._use_tls = settings.get('use_tls', False) self._vendor = settings.get('vendor') self._channel : Optional[grpc.Channel] = None self._stub : Optional[gNMIStub] = None self._monit_thread = None Loading @@ -64,6 +65,10 @@ class GnmiSessionHandler: @property def out_samples(self): return self._out_samples @property def device_type(self): return self._vendor.lower() if self._vendor else 'oc' def connect(self): with self._lock: self._channel = get_grpc_channel(self._address, self._port, self._use_tls, self._logger) Loading Loading @@ -97,7 +102,7 @@ class GnmiSessionHandler: try: chk_string(str_resource_name, resource_key, allow_empty=False) self._logger.debug('[GnmiSessionHandler:get] resource_key = {:s}'.format(str(resource_key))) str_path = get_path(resource_key) str_path = get_path(resource_key, self.device_type) self._logger.debug('[GnmiSessionHandler:get] str_path = {:s}'.format(str(str_path))) get_request.path.append(path_from_string(str_path)) except Exception as e: # pylint: disable=broad-except Loading Loading @@ -141,7 +146,7 @@ class GnmiSessionHandler: value = decode_value(update.val) #resource_key_tuple[1] = value #resource_key_tuple[2] = True results.extend(parse(str_path, value, self._yang_handler)) results.extend(parse(str_path, value, self._yang_handler, self.device_type)) except Exception as e: # pylint: disable=broad-except MSG = 'Exception processing update {:s}' self._logger.exception(MSG.format(grpc_message_to_json_string(update))) Loading Loading @@ -178,7 +183,7 @@ class GnmiSessionHandler: #if resource_tuple is None: continue #_, value, exists, operation_done = resource_tuple if isinstance(resource_value, str): resource_value = json.loads(resource_value) str_path, str_data = compose(resource_key, resource_value, self._yang_handler, delete=False) str_path, str_data = compose(resource_key, resource_value, self._yang_handler, delete=False, device_type=self.device_type) if str_path is None: continue # nothing to set #self._logger.info('---3') #self._logger.info(str(str_path)) Loading Loading @@ -252,7 +257,7 @@ class GnmiSessionHandler: #if not exists: continue if isinstance(resource_value, str): resource_value = json.loads(resource_value) # pylint: disable=unused-variable str_path, str_data = compose(resource_key, resource_value, self._yang_handler, delete=True) str_path, str_data = compose(resource_key, resource_value, self._yang_handler, delete=True, device_type=self.device_type) if str_path is None: continue # nothing to do with this resource_key #self._logger.info('---3') #self._logger.info(str(str_path)) Loading
src/device/service/drivers/gnmi_openconfig/handlers/Acl.py +6 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ from typing import Any, Dict, List, Tuple import libyang from inter_device_translation import get_dict_helper from ._Handler import _Handler from .YangHandler import YangHandler Loading @@ -43,11 +44,14 @@ _OC_TFS_FWD_ACTION = {v: k for k, v in _TFS_OC_FWD_ACTION.items()} class AclHandler(_Handler): def __init__(self, device_type=None): self._dict_helper = get_dict_helper(device_type or 'oc') def get_resource_key(self) -> str: return '/device/endpoint/acl_ruleset' def get_path(self) -> str: return '/openconfig-acl:acl' return self._dict_helper.get_path('acl') def compose( # pylint: disable=too-many-locals self, Loading @@ -66,7 +70,7 @@ class AclHandler(_Handler): path = f'/acl/acl-sets/acl-set[name={rs_name}][type={oc_type}]' return path, '' yang_acl: libyang.DContainer = yang.get_data_path('/openconfig-acl:acl') yang_acl: libyang.DContainer = yang.get_data_path(self._dict_helper.get_path('acl')) y_sets = yang_acl.create_path('acl-sets') y_set = y_sets.create_path(f'acl-set[name="{rs_name}"][type="{oc_type}"]') Loading
src/device/service/drivers/gnmi_openconfig/handlers/Component.py +14 −8 Original line number Diff line number Diff line Loading @@ -17,15 +17,19 @@ 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__) PATH_IF_CTR = '/openconfig-interfaces:interfaces/interface[name={:s}]/state/counters/{:s}' # Path will be constructed dynamically using device translation #pylint: disable=abstract-method class ComponentHandler(_Handler): def __init__(self, device_type=None): self._dict_helper = get_dict_helper(device_type or 'oc') 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 Loading @@ -36,7 +40,8 @@ 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', plural=True)][self._dict_helper.get_object('components')]: LOGGER.debug('component={:s}'.format(str(component))) component_name = component['name'] Loading @@ -59,12 +64,13 @@ class ComponentHandler(_Handler): endpoint = {'uuid': interface_name, 'type': '-'} endpoint['sample_types'] = { KpiSampleType.KPISAMPLETYPE_BYTES_RECEIVED : PATH_IF_CTR.format(interface_name, 'in-octets' ), KpiSampleType.KPISAMPLETYPE_BYTES_TRANSMITTED : PATH_IF_CTR.format(interface_name, 'out-octets'), KpiSampleType.KPISAMPLETYPE_PACKETS_RECEIVED : PATH_IF_CTR.format(interface_name, 'in-pkts' ), KpiSampleType.KPISAMPLETYPE_PACKETS_TRANSMITTED: PATH_IF_CTR.format(interface_name, 'out-pkts' ), KpiSampleType.KPISAMPLETYPE_BYTES_RECEIVED : self._dict_helper.get_path('interface_counters', name=interface_name, counter='in-octets'), KpiSampleType.KPISAMPLETYPE_BYTES_TRANSMITTED : self._dict_helper.get_path('interface_counters', name=interface_name, counter='out-octets'), KpiSampleType.KPISAMPLETYPE_PACKETS_RECEIVED : self._dict_helper.get_path('interface_counters', name=interface_name, counter='in-pkts'), KpiSampleType.KPISAMPLETYPE_PACKETS_TRANSMITTED: self._dict_helper.get_path('interface_counters', name=interface_name, counter='out-pkts'), } entries.append(('/endpoints/endpoint[{:s}]'.format(endpoint['uuid']), endpoint)) resource_key = self._dict_helper.get_resource_key('endpoints_endpoint', uuid=endpoint['uuid']) entries.append((resource_key, endpoint)) return entries
src/device/service/drivers/gnmi_openconfig/handlers/Interface.py +8 −4 Original line number Diff line number Diff line Loading @@ -17,12 +17,17 @@ from typing import Any, Dict, List, Tuple from ._Handler import _Handler from .Tools import get_bool, get_int, get_str from .YangHandler import YangHandler from inter_device_translation import get_dict_helper LOGGER = logging.getLogger(__name__) class InterfaceHandler(_Handler): def __init__(self, device_type=None): self._dict_helper = get_dict_helper(device_type or 'oc') def get_resource_key(self) -> str: return '/interface/subinterface' def get_path(self) -> str: return '/openconfig-interfaces:interfaces' def get_path(self) -> str: return self._dict_helper.get_path('interfaces') def compose( self, resource_key : str, resource_value : Dict, yang_handler : YangHandler, delete : bool = False Loading @@ -31,8 +36,7 @@ class InterfaceHandler(_Handler): sif_index = get_int(resource_value, 'index', 0) # 0 if delete: PATH_TMPL = '/interfaces/interface[name={:s}]/subinterfaces/subinterface[index={:d}]' str_path = PATH_TMPL.format(if_name, sif_index) str_path = self._dict_helper.get_path('interface_subinterface', name=if_name, index=sif_index) str_data = json.dumps({}) root_node : libyang.DContainer = yang_handler.get_data_path( Loading @@ -58,7 +62,7 @@ class InterfaceHandler(_Handler): address_prefix = get_int (resource_value, 'address_prefix') # 24 mtu = get_int (resource_value, 'mtu' ) # 1500 yang_ifs : libyang.DContainer = yang_handler.get_data_path('/openconfig-interfaces:interfaces') yang_ifs : libyang.DContainer = yang_handler.get_data_path(self._dict_helper.get_path('interfaces')) yang_if_path = 'interface[name="{:s}"]'.format(if_name) yang_if : libyang.DContainer = yang_ifs.create_path(yang_if_path) yang_if.create_path('config/name', if_name ) Loading
src/device/service/drivers/gnmi_openconfig/handlers/InterfaceCounter.py +7 −2 Original line number Diff line number Diff line Loading @@ -16,13 +16,18 @@ import json, libyang, logging from typing import Any, Dict, List, Tuple from ._Handler import _Handler from .YangHandler import YangHandler from inter_device_translation import get_dict_helper LOGGER = logging.getLogger(__name__) #pylint: disable=abstract-method class InterfaceCounterHandler(_Handler): def __init__(self, device_type=None): self._dict_helper = get_dict_helper(device_type or 'oc') def get_resource_key(self) -> str: return '/interface/counters' def get_path(self) -> str: return '/openconfig-interfaces:interfaces/interface/state/counters' def get_path(self) -> str: return self._dict_helper.get_path('interface_counters_path') def parse( self, json_data : Dict, yang_handler : YangHandler Loading Loading @@ -58,7 +63,7 @@ class InterfaceCounterHandler(_Handler): } LOGGER.debug('interface = {:s}'.format(str(interface))) entry_interface_key = '/interface[{:s}]'.format(interface_name) entry_interface_key = self._dict_helper.get_resource_key('interface', name=interface_name) entries.append((entry_interface_key, _interface)) return entries