forked from 3wordchant/capsul-flask
first steps towards multiple hosts -- schema & heartbeat
This commit is contained in:
@ -8,6 +8,10 @@ class DBModel:
|
||||
self.connection = connection
|
||||
self.cursor = cursor
|
||||
|
||||
|
||||
# ------ LOGIN ---------
|
||||
|
||||
|
||||
def login(self, email):
|
||||
self.cursor.execute("SELECT * FROM accounts WHERE email = %s", (email, ))
|
||||
if len(self.cursor.fetchall()) == 0:
|
||||
@ -33,6 +37,10 @@ class DBModel:
|
||||
return email
|
||||
return None
|
||||
|
||||
|
||||
# ------ VM & ACCOUNT MANAGEMENT ---------
|
||||
|
||||
|
||||
def all_non_deleted_vm_ids(self,):
|
||||
self.cursor.execute("SELECT id FROM vms WHERE deleted IS NULL")
|
||||
return list(map(lambda x: x[0], self.cursor.fetchall()))
|
||||
@ -144,6 +152,10 @@ class DBModel:
|
||||
|
||||
return vm
|
||||
|
||||
|
||||
# ------ PAYMENTS & ACCOUNT BALANCE ---------
|
||||
|
||||
|
||||
def list_payments_for_account(self, email):
|
||||
self.cursor.execute("""
|
||||
SELECT id, dollars, invalidated, created
|
||||
@ -253,6 +265,15 @@ class DBModel:
|
||||
return list(map(lambda row: dict(email=row[0], account_balance_warning=row[1]), self.cursor.fetchall()))
|
||||
|
||||
|
||||
# ------ HOSTS ---------
|
||||
|
||||
def authorized_for_host(self, id, token):
|
||||
self.cursor.execute("SELECT id FROM hosts WHERE id = %s token = %s", (id, token))
|
||||
return self.cursor.fetchone() != None
|
||||
|
||||
def host_heartbeat(self, id):
|
||||
self.cursor.execute("UPDATE hosts SET last_health_check = NOW() WHERE id = %s", (id,))
|
||||
self.connection.commit()
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user