![]() |
class AttributeError: - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: class AttributeError: (/thread-22173.html) |
class AttributeError: - anna - Nov-02-2019 Hi All, I am polling Nokia Router device for port optical details through snmp. This router is having 52 ports, all details will be fetched if port status in operational. currently returning few details, later I need to append returning dict in list to print all details. However getting AttributeError: 'str' object has no attribute 'get_Ports' from easysnmp import Session import time from datetime import datetime import datetime from collections import namedtuple class NokiaPortdetails(): #port ID to cli Interface Ports = {'35684352':'1/1/1','35717120':'1/1/2','35749888':'1/1/3','35782656':'1/1/4','35815424':'1/1/5',\ '35848192':'1/1/6','35880960':'1/1/7','35913728':'1/1/8','35946496':'1/1/9','35979264':'1/1/10',\ '36012032':'1/1/11','36044800':'1/1/12','36077568':'1/1/13','36110336':'1/1/14','36143104':'1/1/15',\ '36175872':'1/1/16','36208640':'1/1/17','36241408':'1/1/18','36274176':'1/1/19','36306944':'1/1/20',\ '36339712':'1/1/21','36372480':'1/1/22','36405248':'1/1/23','36438016':'1/1/24','36470784':'1/1/25',\ '36503552':'1/1/26','36536320':'1/1/27','36569088':'1/1/28','36601856':'1/1/29','36634624':'1/1/30',\ '36667392':'1/1/31','36700160':'1/1/32','36732928':'1/1/33','36765696':'1/1/34','36798464':'1/1/35',\ '36831232':'1/1/36','36864000':'1/1/37','36896768':'1/1/38','36929536':'1/1/39','36962304':'1/1/40',\ '36995072':'1/1/41','37027840':'1/1/42','37060608':'1/1/43','37093376':'1/1/44','37126144':'1/1/45',\ '37158912':'1/1/46','37191680':'1/1/47','37224448':'1/1/48','37257216':'1/1/49','37289984':'1/1/50',\ '37322752':'1/1/51','37355520':'1/1/52'} #Port Operations status dict Portstat = {'1':'Unknown', '2':'Operational', '3':'not-equipped', '4':'diagnosing', '5':'failed' } def __init__(self,host,community,version,timeout): self.host = host self.community = community self.version = version self.timeout = timeout def get_Ports(self, value): return self.Ports.get(value,"other") def get_Portstat(self,value): return self.Portstat.get(value,"other") def get_Opticaldetails(self): #SNMP session, get the details to print below data """ A:HYD-GP-SAS-1# show port optical 1/1/1 =============================================================================== Optical Interface =============================================================================== Transceiver Data Transceiver Status : operational Transceiver Type : SFP TX Laser Wavelength: 1310 nm Diag Capable : yes Connector Code : LC Manufacture date : 2018/05/08 Media : Ethernet Serial Number : KT18050466 Part Number : KT-S1310-1G-20D """ session = Session(hostname=host, community='cacti', version=2,timeout=5) tmnxPortOperStatus,tmnxPortTransceiverType,tmnxPortTransceiverLaserWaveLen,tmnxPortSFPConnectorCode,\ tmnxPortSFPVendorManufactureDate,tmnxPortTransceiverDiagCapable,tmnxPortSFPMedia,tmnxPortSFPVendorSerialNum,\ tmnxPortSFPVendorPartNum = (list(session.bulkwalk('1.3.6.1.4.1.6527.3.1.2.2.4.2.1.'+c, \ non_repeaters=0, max_repetitions=50))for c in ('38','25','27','30','32','28','33','45','46')) #namedtuple for PortOptical details portOptical = namedtuple('portOptical','PortOperStatus PortTransceiverType PortTransceiverLaserWaveLen \ PortSFPConnectorCode PortSFPVendorManufactureDate PortTransceiverDiagCapable \ PortSFPMedia PortSFPVendorSerialNum PortSFPVendorPartNum') portOptical_inters = [portOptical(*uple) for uple in zip(*[tmnxPortOperStatus,tmnxPortTransceiverType,\ tmnxPortTransceiverLaserWaveLen,tmnxPortSFPConnectorCode,tmnxPortSFPVendorManufactureDate,\ tmnxPortTransceiverDiagCapable,tmnxPortSFPMedia,tmnxPortSFPVendorSerialNum,\ tmnxPortSFPVendorPartNum])] for Optical_data in portOptical_inters: return { 'host': host, 'portID': Optical_data.PortOperStatus.oid.split('.')[-1], # spliting SNMP output to get portID 'interface':self.get_Ports(portID), # passing PortID to get interface name like '1/1/1' 'PortOperStatus':self.get_Portstat(portOptical.PortOperStatus.value) # getting operation status of port } if __name__ == "__main__": hosts = ['10.124.209.66','10.124.209.74'] for host in hosts: #print(host) details = NokiaPortdetails.get_Opticaldetails(host) print(details)
RE: class AttributeError: - MckJohan - Nov-02-2019 portOptical_details['interface'] = cli_interface(portOptical_details['portID']) RE: class AttributeError: - anna - Nov-02-2019 got the solutions... working on the same. |