def get_server(mac): with db_connection('./ipxe.sqlite3') as conn: with db_transaction(conn) as cursor: sql = "%s WHERE mac=?" server = cursor.execute(sql % SELECT_SQL, (mac,)).fetchone() if server is None: return jsonify({}), 404 server_dict = dict(mac=server[0], hostname=server[1], state=server[2], profile=server[3], created=server[4]*1000, updated=server[5]*1000) return jsonify(server_dict)
def servers(): with db_connection('./ipxe.sqlite3') as conn: with db_transaction(conn) as cursor: servers = cursor.execute(SELECT_SQL).fetchall() servers_list = [] for server in servers: server_dict = dict(mac=server[0], hostname=server[1], state=server[2], profile=server[3], created=server[4]*1000, updated=server[5]*1000) servers_list.append(server_dict) return jsonify(servers=servers_list)