def GET(self): i = web.input(id=None) try: DB.update('eventos', where='id=$i.id', user_state='t', vars=locals()) except: print "Error Inesperado /user/updateevent:", sys.exc_info() raise web.seeother('/eventos')
def GET(self): i = web.input(id=None) try: DB.update('eventos', where='id=$i.id', admin_state='t', vars=locals()) except: print "Error Inesperado /updateevent:", sys.exc_info() raise web.seeother('/managevents')
def GET(self): i = web.input(id=None) #print "****************************** Update Event:", i.id try: DB.update('eventos', where='id=$i.id', admin_state='t', vars=locals()) except: print "Error Inesperado /updateevent:", sys.exc_info() #return updateevent raise web.seeother('/managevents')
def update_session(session_id): '''Increments the evaluation pair for a session''' result = DB.select(SESSION_DB_NAME, where='session_id=%d' % session_id, \ what='num_eval') num_eval = result[0]['num_eval'] + 1 DB.update(SESSION_DB_NAME, where='session_id=%d' % session_id, num_eval=num_eval) return num_eval
def POST(self, name): user = web.input('user')['user'] desc = web.input(desc=None)['desc'] machine = load_machine(name) if machine.locked: raise web.Forbidden() if machine.type == 'vps': curkey = machine.sshpubkey else: curkey, getstatus = get_sshkey(name) if getstatus != 0: curkey = machine.sshpubkey if machine.sshpubkey != curkey: newkey = curkey else: newkey = machine.sshpubkey res = DB.update('machine', where='name = $name AND locked = false', vars=dict(name=name), locked=True, description=desc, sshpubkey=newkey, locked_by=user, locked_since=web.db.SQLLiteral('NOW()')) assert res == 1, 'Failed to lock machine {name}'.format(name=name) print user, 'locked single machine', name, 'desc', desc
def PUT(self, name): desc = web.input(desc=None)['desc'] status = web.input(status=None)['status'] sshpubkey = web.input(sshpubkey=None)['sshpubkey'] updated = {} if desc is not None: updated['description'] = desc if status is not None: updated['up'] = (status == 'up') if sshpubkey is not None: updated['sshpubkey'] = sshpubkey if not updated: raise web.BadRequest() DB.update('machine', where='name = $name', vars=dict(name=name), **updated)
def update_sshkey(name, key, type): if type == 'vps': return res = DB.update('machine', where='name = $name AND locked = false', vars=dict(name=name), sshpubkey=key,) assert res == 1, 'Failed to update key of machine {name}'.format(name=name) print 'Updated key on ', name
def POST(self, name): user = web.input('user')['user'] machine = load_machine(name) if machine.locked: raise web.Forbidden() res = DB.update('machine', where='name = $name AND locked = false', vars=dict(name=name), locked=True, locked_by=user, locked_since=web.db.SQLLiteral('NOW()')) assert res == 1, 'Failed to lock machine {name}'.format(name=name)
def update_sshkey(name, key, type): if type == 'vps': return res = DB.update( 'machine', where='name = $name AND locked = false', vars=dict(name=name), sshpubkey=key, ) assert res == 1, 'Failed to update key of machine {name}'.format(name=name) print 'Updated key on ', name
def DELETE(self, name): user = web.input('user')['user'] machine = load_machine(name) if not machine.locked: raise web.BadRequest() if machine.locked_by != user: raise web.Forbidden() res = DB.update('machine', where='locked = true AND name = $name AND locked_by = $user', vars=dict(name=name, user=user), locked=False, locked_by=None) assert res == 1, 'Failed to unlock machine {name}'.format(name=name)
def add_id(session_id): '''Adds new id to the session database''' round_select = DB.select(ROUND_ROBIN_DB_NAME)[0] curr_round = round_select['current_round'] total_rounds = round_select['total_rounds'] DB.insert(SESSION_DB_NAME, session_id=session_id, round_rbn=curr_round, num_eval=0) next_round = (curr_round + 1) % total_rounds return DB.update(ROUND_ROBIN_DB_NAME, where='current_round=%d' % curr_round, current_round=next_round)
def POST(self): user = web.input('user')['user'] num = int(web.input('num')['num']) if num < 1: raise web.BadRequest() tries = 0 while True: try: # transaction will be rolled back if an exception is raised with DB.transaction(): results = list(DB.select('machine', what='name, sshpubkey', where='locked = false AND up = true', limit=num)) if len(results) < num: raise web.HTTPError(status='503 Service Unavailable') name_keys = {} for row in results: name_keys[row.name] = row.sshpubkey where_cond = web.db.sqlors('name = ', name_keys.keys()) \ + ' AND locked = false AND up = true' num_locked = DB.update('machine', where=where_cond, locked=True, locked_by=user, locked_since=web.db.SQLLiteral('NOW()')) assert num_locked == num, 'Failed to lock machines' except: tries += 1 if tries < 10: continue raise else: break web.header('Content-type', 'text/json') return json.dumps(name_keys)
def POST(self): user = web.input('user')['user'] desc = web.input(desc=None)['desc'] num = int(web.input('num')['num']) machinetype = dict(machinetype=(web.input(machinetype='plana')['machinetype'])) if num < 1: raise web.BadRequest() tries = 0 check_existing = True while True: try: # transaction will be rolled back if an exception is raised with DB.transaction(): if desc is not None and check_existing: # if a description is provided, treat it as a # key for locking in case the same run locked # machines in the db successfully before, but # the web server reported failure to it # because the request took too long. Only try # this once per request. check_existing = False results = list(DB.select('machine', machinetype, desc, user, what='name, sshpubkey', where='locked = true AND up = true AND type = $machinetype AND description = $desc AND locked_by = $user', limit=num)) if len(results) == num: name_keys = {} for row in results: name_keys[row.name] = row.sshpubkey print 'reusing machines', name_keys.keys() break results = list(DB.select('machine', machinetype, what='name, sshpubkey, type', where='locked = false AND up = true AND type = $machinetype', limit=num)) if len(results) < num: raise web.HTTPError(status='503 Service Unavailable') name_keys = {} for row in results: if row.type == 'vps': curkey = row.sshpubkey else: curkey, getstatus = get_sshkey(row.name) if getstatus != 0: curkey = row.sshpubkey if row.sshpubkey != curkey: newkey = curkey update_sshkey(row.name, curkey, row.type) else: newkey = row.sshpubkey name_keys[row.name] = newkey where_cond = web.db.sqlors('name = ', name_keys.keys()) \ + ' AND locked = false AND up = true' num_locked = DB.update('machine', where=where_cond, locked=True, locked_by=user, description=desc, locked_since=web.db.SQLLiteral('NOW()')) assert num_locked == num, 'Failed to lock machines' except Exception: log.exception("Saw exception") tries += 1 if tries < 10: continue raise else: break print user, 'locked', name_keys.keys(), 'desc', desc web.header('Content-type', 'text/json') return json.dumps(name_keys)
def POST(self): user = web.input('user')['user'] desc = web.input(desc=None)['desc'] num = int(web.input('num')['num']) machinetype = dict(machinetype=(web.input( machinetype='plana')['machinetype'])) if num < 1: raise web.BadRequest() tries = 0 check_existing = True while True: try: # transaction will be rolled back if an exception is raised with DB.transaction(): if desc is not None and check_existing: # if a description is provided, treat it as a # key for locking in case the same run locked # machines in the db successfully before, but # the web server reported failure to it # because the request took too long. Only try # this once per request. check_existing = False results = list( DB.select( 'machine', machinetype, desc, user, what='name, sshpubkey', where= 'locked = true AND up = true AND type = $machinetype AND description = $desc AND locked_by = $user', limit=num)) if len(results) == num: name_keys = {} for row in results: name_keys[row.name] = row.sshpubkey print 'reusing machines', name_keys.keys() break results = list( DB.select( 'machine', machinetype, what='name, sshpubkey, type', where= 'locked = false AND up = true AND type = $machinetype', limit=num)) if len(results) < num: raise web.HTTPError(status='503 Service Unavailable') name_keys = {} for row in results: if row.type == 'vps': curkey = row.sshpubkey else: curkey, getstatus = get_sshkey(row.name) if getstatus != 0: curkey = row.sshpubkey if row.sshpubkey != curkey: newkey = curkey update_sshkey(row.name, curkey, row.type) else: newkey = row.sshpubkey name_keys[row.name] = newkey where_cond = web.db.sqlors('name = ', name_keys.keys()) \ + ' AND locked = false AND up = true' num_locked = DB.update( 'machine', where=where_cond, locked=True, locked_by=user, description=desc, locked_since=web.db.SQLLiteral('NOW()')) assert num_locked == num, 'Failed to lock machines' except Exception: log.exception("Saw exception") tries += 1 if tries < 10: continue raise else: break print user, 'locked', name_keys.keys(), 'desc', desc web.header('Content-type', 'text/json') return json.dumps(name_keys)
def save_current_pair(session_id, pair_number): '''Saves the current pair being evaluated''' return DB.update(SESSION_DB_NAME, where='session_id=%d' % session_id, curr_pair=pair_number)