ShowVer.py 文件源码

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

项目:eAPI-Scripts 作者: GADify 项目源码 文件源码
def GetVersion(x):
   verLoc = 19
   IP = "10.0.0." + str(x)
   switch = Server( "https://" + ScriptUser + ":" + ScriptPass + "@" + IP + "/command-api" )
   # Results in Host Unreach never happening, but [ . ] means same thing 
   #         without waiting
   socket.setdefaulttimeout(3)
   try:
      response = switch.runCmds( 1, [ "show version" ] )
   except socket.error,ERR :
       ErrorCode = ERR[0]
       if ErrorCode == errno.ECONNREFUSED:
          win.addstr(x, verLoc -6, "        [ Err " + str(ErrorCode) + ": No eAPI ]          ")
          refresh() 
       elif ErrorCode == errno.EHOSTUNREACH:
          # Never hit with lower socket timeout
          win.addstr(x, verLoc, "Err " + str(ErrorCode) + ": Pwr off or Aboot ]          ")
          refresh() 
       elif ErrorCode == errno.ECONNRESET:
          win.addstr(x, verLoc, "Err " + str(ErrorCode) + ": Con RST ]          ")
          refresh() 
   else:
      win.addstr(x, verLoc, response[0]["version"] + " ]")
      memTotal = response[0]["memTotal"]
      memFree  = response[0]["memFree"]
      percentUsed = 100 - round((float(memFree) / float(memTotal)) * 100, 1)
      win.addstr(x, verLoc+24, str(percentUsed) + "% ]" )
      refresh()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号