forked from 3wordchant/capsul-flask
more managed ips work: cli sql improvements, added admin panel
This commit is contained in:
capsulflask
@ -56,9 +56,23 @@ class DBModel:
|
||||
|
||||
# ------ VM & ACCOUNT MANAGEMENT ---------
|
||||
|
||||
def all_non_deleted_vms(self):
|
||||
self.cursor.execute("SELECT id, host, network_name, last_seen_ipv4, last_seen_ipv6 FROM vms WHERE deleted IS NULL")
|
||||
return list(map(lambda x: dict(id=x[0], host=x[1], network_name=x[2], last_seen_ipv4=x[3], last_seen_ipv6=x[4]), self.cursor.fetchall()))
|
||||
def all_non_deleted_vms_by_host_and_network(self):
|
||||
self.cursor.execute("SELECT id, host, network_name, public_ipv4, public_ipv6 FROM vms WHERE deleted IS NULL")
|
||||
|
||||
hosts = dict()
|
||||
for row in self.cursor.fetchall():
|
||||
host_id = row[1]
|
||||
network_name = row[2]
|
||||
if host_id not in hosts:
|
||||
hosts[host_id] = dict()
|
||||
if network_name not in hosts[host_id]:
|
||||
hosts[host_id][network_name] = []
|
||||
|
||||
hosts[host_id][network_name].append(
|
||||
dict(id=row[0], public_ipv4=row[3], public_ipv6=row[4])
|
||||
)
|
||||
|
||||
return hosts
|
||||
|
||||
def all_non_deleted_vm_ids(self):
|
||||
self.cursor.execute("SELECT id FROM vms WHERE deleted IS NULL")
|
||||
@ -108,7 +122,7 @@ class DBModel:
|
||||
|
||||
def list_vms_for_account(self, email):
|
||||
self.cursor.execute("""
|
||||
SELECT vms.id, vms.last_seen_ipv4, vms.last_seen_ipv6, vms.size, vms.os, vms.created, vms.deleted, vm_sizes.dollars_per_month
|
||||
SELECT vms.id, vms.public_ipv4, vms.public_ipv6, vms.size, vms.os, vms.created, vms.deleted, vm_sizes.dollars_per_month
|
||||
FROM vms JOIN vm_sizes on vms.size = vm_sizes.id
|
||||
WHERE vms.email = %s""",
|
||||
(email, )
|
||||
@ -119,7 +133,7 @@ class DBModel:
|
||||
))
|
||||
|
||||
def update_vm_ip(self, email, id, ipv4):
|
||||
self.cursor.execute("UPDATE vms SET last_seen_ipv4 = %s WHERE email = %s AND id = %s", (ipv4, email, id))
|
||||
self.cursor.execute("UPDATE vms SET public_ipv4 = %s WHERE email = %s AND id = %s", (ipv4, email, id))
|
||||
self.connection.commit()
|
||||
|
||||
def update_vm_ssh_host_keys(self, email, id, ssh_host_keys):
|
||||
@ -155,7 +169,7 @@ class DBModel:
|
||||
|
||||
def get_vm_detail(self, email, id):
|
||||
self.cursor.execute("""
|
||||
SELECT vms.id, vms.last_seen_ipv4, vms.last_seen_ipv6, os_images.description, vms.created, vms.deleted,
|
||||
SELECT vms.id, vms.public_ipv4, vms.public_ipv6, os_images.description, vms.created, vms.deleted,
|
||||
vm_sizes.id, vm_sizes.dollars_per_month, vm_sizes.vcpus, vm_sizes.memory_mb, vm_sizes.bandwidth_gb_per_month
|
||||
FROM vms
|
||||
JOIN os_images on vms.os = os_images.id
|
||||
|
Reference in New Issue
Block a user