Can't figure out why it won't allow me to pass variables into the method. The variable "module" is actually creating an object of LinkFailure:
from lib.remediation.link_failure import LinkFailure
from mapping import get_remediation
def remediation(dstamp,tstamp,device,error_code,error_message,ntw_device):
module = get_remediation(error_code)
device = module(*ntw_device)
device.troubleshoot(dstamp,tstamp,device,error_code,error_message)
Here is my mapping file to get the LinkFailure:
######################## FUNCTIONS ##############################
from lib.remediation import link_failure
from lib.remediation import default
ERROR_CODES_TO_REMEDIATIONS = {
'LINEPROTO-5-UPDOWN': link_failure.LinkFailure
}
DEFAULT_REMEDIATION = {
'default': default.Default
}
def get_remediation(error_code):
if error_code in ERROR_CODES_TO_REMEDIATIONS:
module = ERROR_CODES_TO_REMEDIATIONS[error_code]
else:
module = DEFAULT_REMEDIATION['default']
return module
Here is my class file:
from initialize import Initialize
class LinkFailure(Initialize):
def troubleshoot(self,dstamp,tstamp,device,error_code,error_message):
print 'LINK FAILURE'
print dstamp,device
When I run it, here is the traceback:
Why does it only allow 1 argument when I've already defined 6 including itself in the method?
<Thread(Thread-1, started 140335459219200)>
Sep 22 18:26:49 x.x.x.x LINK-5-CHANGED Interface GigabitEthernet1/0/12, changed state to administratively down
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/root/staging/superloopAR/parser.py", line 23, in parser
event(dstamp,tstamp,device,error_code,error_message,ntw_device)
File "/root/staging/superloopAR/event.py", line 9, in event
remediation(e.datestamp,e.timestamp,e.device,e.error_code,e.error_message,ntw_device)
File "/root/staging/superloopAR/remediation.py", line 11, in remediation
device.troubleshoot(dstamp,tstamp,device,error_code,error_message)
TypeError: troubleshoot() takes exactly 1 argument (6 given)
I was checking the wrong module.. The default module with the troubleshoot method only accepted 1 argument.
I was looking at another module, link_failure and had thought it accepted 6. Human error on my side.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.