示例#1
0
def list_hardware():
    """URL: */* 
    
    Index page. Lists all boards in the hardware database.
    """
    # Retrieve hardware list from database
    # Establish database connection
    dbconnect = sqlite3.connect(DB_NAME)
    db = dbconnect.cursor()
    flashmsgs = []

    try:
        hardware_list = dbgetall()

        # Make a list of things to ping
        hostlist = [ping.Host(h["IP_address"]) for h in hardware_list]
        xphostlist = [ping.Host(h["XPORT_address"]) for h in hardware_list]

        # Ping the fkrs
        statuslist = ping.pingHosts(hostlist)
        xpstatuslist = ping.pingHosts(xphostlist)

        i = 0
        for roach in hardware_list:
            roach["status"] = statuslist[i].status
            roach["XPORT_status"] = xpstatuslist[i].status
            i += 1

        # Turn all boards ON
        if (request.GET.get('power', '').strip() == "Power all ON"):
            for roach in hardware_list:
                if (roach["XPORT_status"] == 1):
                    xp = xport.Xport(roach["XPORT_address"], 10001)
                    flashmsgs.append("%s: %s" %
                                     (roach["hostname"], xp.power_up()))
                    xp.close()

        # Turn all boards OFF
        if (request.GET.get('power', '').strip() == "Power all OFF"):
            for roach in hardware_list:
                if (roach["XPORT_status"] == 1):
                    xp = xport.Xport(roach["XPORT_address"], 10001)
                    flashmsgs.append("%s: %s" %
                                     (roach["hostname"], xp.power_down()))
                    xp.close()

        output = template('index', rows=hardware_list, flashmsgs=flashmsgs)

        return output
    except:
        output = template('index', rows=[], flashmsgs=flashmsgs)
        return output
示例#2
0
def list_hardware():
    """URL: */* 
    
    Index page. Lists all boards in the hardware database.
    """
    # Retrieve hardware list from database
    # Establish database connection
    dbconnect = sqlite3.connect(DB_NAME)    
    db = dbconnect.cursor()
    flashmsgs = []
    
    try:
      hardware_list = dbgetall()
      
      # Make a list of things to ping
      hostlist   = [ping.Host(h["IP_address"]) for h in hardware_list]
      xphostlist = [ping.Host(h["XPORT_address"]) for h in hardware_list]
      
      # Ping the fkrs
      statuslist   = ping.pingHosts(hostlist)
      xpstatuslist = ping.pingHosts(xphostlist)
      
      i = 0
      for roach in hardware_list:
          roach["status"]       = statuslist[i].status
          roach["XPORT_status"] = xpstatuslist[i].status
          i += 1
          
      # Turn all boards ON 
      if(request.GET.get('power','').strip() == "Power all ON"):
        for roach in hardware_list:
          if(roach["XPORT_status"] == 1):
            xp = xport.Xport(roach["XPORT_address"], 10001)
            flashmsgs.append("%s: %s"%(roach["hostname"], xp.power_up()))
            xp.close()
            
      # Turn all boards OFF       
      if(request.GET.get('power','').strip() == "Power all OFF"):
        for roach in hardware_list:
          if(roach["XPORT_status"] == 1):
            xp = xport.Xport(roach["XPORT_address"], 10001)
            flashmsgs.append("%s: %s"%(roach["hostname"], xp.power_down()))
            xp.close()
      
      
      output = template('index', rows=hardware_list, flashmsgs=flashmsgs)
      
      return output
    except:
      output = template('index', rows=[], flashmsgs=flashmsgs)
      return output
示例#3
0
def view_hardware(id):
    """ URL: */status/:id*
    
    Provides overview of a single piece of kit.
    """
    # Retrieve hardware list from database
    roach = dbget(id)
    flashmsgs = []

    # Check if XPORT is responding or not
    xping = ping.Host(roach["XPORT_address"])
    xstatus = ping.pingHosts([xping])[0].status

    if(xstatus == 1):
      # Get operating voltages etc from XPORT
      xp = xport.Xport(roach["XPORT_address"], 10001)
      
      xinfo = {
      "serial"     : xp.get_serial(),
      "id"         : xp.get_id(),
      "boardtime"  : xp.get_board_time(),
      "powerstate" : xp.get_power_state(),
      "shutdown"   : xp.get_last_shutdown(),
      "powergood"  : xp.get_power_good(),
      "channels"   : xp.get_channels(),
      "fanspeeds"  : xp.get_fan_speeds()
      }
      
      xp.close()
    else:
      flashmsgs.append("Warning: Xport is not responding to pings. Detailed status not available.")
      xinfo = 0

    output = template('status', roach=roach, flashmsgs=flashmsgs, xinfo=xinfo)
    return output
示例#4
0
def view_hardware(id):
    """ URL: */status/:id*
    
    Provides overview of a single piece of kit.
    """
    # Retrieve hardware list from database
    roach = dbget(id)
    flashmsgs = []

    # Check if XPORT is responding or not
    xping = ping.Host(roach["XPORT_address"])
    xstatus = ping.pingHosts([xping])[0].status

    if (xstatus == 1):
        # Get operating voltages etc from XPORT
        xp = xport.Xport(roach["XPORT_address"], 10001)

        xinfo = {
            "serial": xp.get_serial(),
            "id": xp.get_id(),
            "boardtime": xp.get_board_time(),
            "powerstate": xp.get_power_state(),
            "shutdown": xp.get_last_shutdown(),
            "powergood": xp.get_power_good(),
            "channels": xp.get_channels(),
            "fanspeeds": xp.get_fan_speeds()
        }

        xp.close()
    else:
        flashmsgs.append(
            "Warning: Xport is not responding to pings. Detailed status not available."
        )
        xinfo = 0

    output = template('status', roach=roach, flashmsgs=flashmsgs, xinfo=xinfo)
    return output