def BaselineEOS(switchNumber):
location = 28
IP = "10.0.0." + str(switchNumber)
#print "Switch " + str(switchNumber).zfill(2) + ": ",
#Connect to Switch via eAPI
target = "https://" + ScriptUser + ":" + ScriptPass + "@" + IP + "/command-api"
switch = jsonrpclib.Server( target )
# capture Connection problem messages
# Map of erronos is here: http://www.python.org/doc//current/library/errno.html
try:
response = switch.runCmds( 1,
[ "enable" ,
"configure",
"delete EOS*.swi",
"copy " + FileServer + EOSVer + " flash:",
"boot system flash:" + EOSVer,
"write erase now",
"reload now"
], "text")
except KeyboardInterrupt:
print "Caught Keyboard Interrupt - Exiting"
sys.exit()
except socket.error,ERR :
# Socket Errors
ErrorCode = ERR[0]
if ErrorCode == errno.ECONNREFUSED:
win.addstr(switchNumber, location -15, " [ Err " + str(ErrorCode) + ": No eAPI ] ")
refresh()
elif ErrorCode == errno.EHOSTUNREACH:
# Never hit with lower socket timeout
win.addstr(switchNumber, location -15, " [ Err " + str(ErrorCode) + ": Pwr off | Aboot ] ")
refresh()
elif ErrorCode == errno.ECONNRESET:
win.addstr(switchNumber, location -15, " [ Err " + str(ErrorCode) + ": Con RST ] ")
refresh()
except jsonrpclib.ProtocolError:
# Capture eAPI errors
result = jsonrpclib.loads( jsonrpclib.history.response )
print result["error"]["message"]
for error in result["error"]["data"][-1]["errors"]:
print error
except (xmlrpclib.ProtocolError, xmlrpclib.ResponseError), errormsg:
# Capture XML Error (usually bad password)
message = str(errormsg)
message = message.replace(ScriptUser, "user")
message = message.replace(ScriptPass, "pass")
print message
else:
win.addstr(switchNumber, location, "[ Done ]")
refresh()
评论列表
文章目录