From d746f2d91f55c8f9b34374027af1b371d23b8f83 Mon Sep 17 00:00:00 2001 From: purhan Date: Thu, 29 Jul 2021 19:46:19 +0530 Subject: [PATCH] [change] Use Trie instead of Dict in walk function --- netengine/backends/snmp/airos.py | 4 +--- netengine/backends/snmp/base.py | 3 ++- netengine/backends/snmp/openwrt.py | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/netengine/backends/snmp/airos.py b/netengine/backends/snmp/airos.py index 06418b0..8b68103 100644 --- a/netengine/backends/snmp/airos.py +++ b/netengine/backends/snmp/airos.py @@ -9,8 +9,6 @@ import logging from datetime import datetime -from pytrie import StringTrie as Trie - from netengine.exceptions import NetEngineError from .base import SNMP @@ -510,7 +508,7 @@ def resources_to_dict(self, snmpdump=None): def to_dict(self, snmpdump=None, autowalk=True): if autowalk: - snmpdump = Trie(self.walk('1.3.6')) + snmpdump = self.walk('1.3.6') result = self._dict( { 'type': 'DeviceMonitoring', diff --git a/netengine/backends/snmp/base.py b/netengine/backends/snmp/base.py index 8cbaf69..1f6cb9c 100644 --- a/netengine/backends/snmp/base.py +++ b/netengine/backends/snmp/base.py @@ -10,6 +10,7 @@ import netaddr from pysnmp.hlapi import ContextData, ObjectIdentity, ObjectType, SnmpEngine, nextCmd +from pytrie import StringTrie from netengine.backends import BaseBackend from netengine.exceptions import NetEngineError @@ -96,7 +97,7 @@ def _oid(self, oid): return str(oid) def walk(self, oid): - result = dict() + result = StringTrie() for (errorIndication, errorStatus, errorIndex, varBinds) in nextCmd( SnmpEngine(), self.community, diff --git a/netengine/backends/snmp/openwrt.py b/netengine/backends/snmp/openwrt.py index ea5a52c..909d1c2 100644 --- a/netengine/backends/snmp/openwrt.py +++ b/netengine/backends/snmp/openwrt.py @@ -12,7 +12,6 @@ import pytz from netaddr import EUI, mac_unix_expanded -from pytrie import StringTrie as Trie from netengine.backends.snmp import SNMP from netengine.exceptions import NetEngineError @@ -606,7 +605,7 @@ def neighbors(self, snmpdump=None): def to_dict(self, snmpdump=None, autowalk=True): if autowalk: - snmpdump = Trie(self.walk('1.2')) + snmpdump = self.walk('1.2') result = self._dict( { 'type': 'DeviceMonitoring',