def __init__(self, config, env_switches, mib_dir):
"""Initialize SNMPCmd class
Args:
config(list[dict]): environment config
env_switches(dict): switches dictionary in format {switch_id: switch_object}
mib_dir(str): MIB module name
"""
self.switches = {}
# get community info from config file:
for conf in config:
if 'get_community' in conf:
self.get_community = conf['get_community']
self.mib_dir = mib_dir
if 'set_community' in conf:
self.set_community = conf['set_community']
# get switches ip addresses and ports
for switch_id in list(env_switches.keys()):
sw_ipaddr = env_switches[switch_id].ipaddr
if 'sshtun_port' in env_switches[switch_id].config:
sw_port = 161
if env_switches[switch_id].config['sshtun_port'] != 22:
sw_ipaddr = "10.10.{0}.{1}".format(*str(env_switches[switch_id].config['sshtun_port']).split('0'))
else:
sw_port = int(env_switches[switch_id].port) - 8080 + 4700
self.switches.update({switch_id: {'host': sw_ipaddr, 'port': sw_port}})
self.mib_builder = builder.MibBuilder()
mib_path = self.mib_builder.getMibPath() + (mib_dir, )
self.mib_builder.setMibPath(*mib_path)
# self.suite_logger.debug("mib_builder __modPathsSeen: %s" % (self.mib_builder._MibBuilder__modPathsSeen, ))
# self.suite_logger.debug("mib_builder __modSeen: %s" % (self.mib_builder._MibBuilder__modSeen, ))
self.mibViewController = view.MibViewController(self.mib_builder)
# loading SNMP types as instances
self.suite_logger.debug("Loading basic types from standard MIB modules")
self.OctetString, Integer = self.mib_builder.importSymbols('ASN1', 'OctetString', 'Integer')[0:2]
Counter32, Unsigned32, Counter64 = self.mib_builder.importSymbols('SNMPv2-SMI', 'Counter32', 'Unsigned32', 'Counter64')[0:3]
InetAddressType, self.InetAddress, InetAddressIPv4, InetAddressIPv6, InetAddressIPv4z, InetAddressIPv6z, InetAddressDNS = \
self.mib_builder.importSymbols('INET-ADDRESS-MIB', 'InetAddressType', 'InetAddress', 'InetAddressIPv4',
'InetAddressIPv6', 'InetAddressIPv4z', 'InetAddressIPv6z', 'InetAddressDNS')[0:7]
self.__integer = Integer()
self.__counter32 = Counter32()
self.__unsigned32 = Unsigned32()
self.__counter64 = Counter64()
self.__octetString = self.OctetString()
# creating InetAddress types dict with keys corresponded to InetAddressType named values
self.InetAddresses = {'ipv4': InetAddressIPv4(), 'ipv6': InetAddressIPv6(), 'ipv4z': InetAddressIPv4z(),
'ipv6z': InetAddressIPv6z(), 'dns': InetAddressDNS()}
评论列表
文章目录