def index(self): # pull MAC address, the primary key, from query string d = request.GET try: mac = h.mac_str_to_int(d[CHECKIN_ARG_MAC]) except: abort(400, "Missing or invalid mac") # look for a record of this host host_q = Session.query(Host) try: host = host_q.filter_by(mac=mac).one() except: abort(404, "Not one host with this mac") # put checkin in the database status = None try: status = d[CHECKIN_ARG_STATUS] assert status in ["ok", "shutdown"] except: abort(400, "Invalid status") temp = None try: temp = float(d.get(CHECKIN_ARG_TEMP, u"0.0")) except: abort(400, "Invalid temp") try: c.checkin = Checkin(mac, status, temp) except Exception, e: abort(400, 'Missing or invalid data: (%012x,%s,%s): "%s"' % (mac, status, temp, str(e)))
def index(self): """Tunnel administration.""" c.rows = [] host_q = Session.query(Host) tunnel_q = Session.query(Tunnel) checkin_q = Session.query(Checkin) # walk through all known hosts for host in host_q.all(): # find the tunnel record for this host tunnel = tunnel_q.filter_by(mac=host.mac).one() # update tunnel enabled flag (unless just arriving) if request.POST.has_key("update"): if request.POST.has_key(host.get_mac()): tunnel.set_port(h.get_free_port()) tunnel.set_enabled(True) else: tunnel.set_port(0) tunnel.set_enabled(False) Session.save_or_update(tunnel) # find most recent checkin, if any checkins = checkin_q.filter_by(mac=host.mac) latest = checkins.order_by(Checkin.tstamp.desc()).first() temp = latest.temp tstamp = latest.tstamp blurb = secs_to_blurb(tstamp) # build output for template enabled = ['','checked'][tunnel.enabled] c.rows.append((host.get_mac(), enabled, tunnel.get_port(), host.get_type(), host.get_host(), host.get_cust(), host.get_desc(), tstamp, blurb, temp)) Session.commit() return render('/admin.mako')
def index(self): # pull MAC address, the primary key, from query string d = request.GET try: mac = h.mac_str_to_int(d[REGISTER_ARG_MAC]) except: abort(400, 'Missing or invalid mac') # look for a record of this host, else start a new one host_q = Session.query(Host) c.host = host_q.filter_by(mac=mac).first() if c.host: c.host.brand_new = False else: try: c.host = Host(mac) c.host.brand_new = True except Exception, e: abort(400, str(e))
def index(self): c.hosts = [host for host in Session.query(Host).all()] c.tunnels = [tunnel for tunnel in Session.query(Tunnel).all()] c.checkins = [checkin for checkin in Session.query(Checkin).all()] return render('/dump.mako')