BaslineEOS.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:eAPI-Scripts 作者: GADify 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号