mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
fix system name, improve config/info, require auth to load
This commit is contained in:
parent
e7731bc66a
commit
12b0f37da5
4 changed files with 24 additions and 12 deletions
|
@ -38,17 +38,10 @@ with open('proxmox_ssh_key', 'w') as key:
|
||||||
|
|
||||||
ssh_tunnels = []
|
ssh_tunnels = []
|
||||||
|
|
||||||
retry = 0
|
|
||||||
while retry < 5:
|
|
||||||
try:
|
|
||||||
auth = OIDCAuthentication(
|
auth = OIDCAuthentication(
|
||||||
app,
|
app,
|
||||||
issuer=app.config['OIDC_ISSUER'],
|
issuer=app.config['OIDC_ISSUER'],
|
||||||
client_registration_info=app.config['OIDC_CLIENT_CONFIG'])
|
client_registration_info=app.config['OIDC_CLIENT_CONFIG'])
|
||||||
break
|
|
||||||
except:
|
|
||||||
retry += 1
|
|
||||||
time.sleep(2)
|
|
||||||
|
|
||||||
redis_conn = Redis(app.config['REDIS_HOST'], app.config['REDIS_PORT'])
|
redis_conn = Redis(app.config['REDIS_HOST'], app.config['REDIS_PORT'])
|
||||||
q = Queue(connection=redis_conn)
|
q = Queue(connection=redis_conn)
|
||||||
|
|
|
@ -42,18 +42,22 @@ def renew_ip(starrs, addr):
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
# Use various STARRS stored procedures to make sure the hostname is valid/available
|
||||||
def check_hostname(starrs, hostname):
|
def check_hostname(starrs, hostname):
|
||||||
c = starrs.cursor()
|
c = starrs.cursor()
|
||||||
try:
|
try:
|
||||||
|
# Check for invalid characters in hostname
|
||||||
c.execute("BEGIN")
|
c.execute("BEGIN")
|
||||||
c.callproc("api.initialize", ('root', ))
|
c.callproc("api.initialize", ('root', ))
|
||||||
c.callproc("api.validate_name", (hostname, ))
|
c.callproc("api.validate_name", (hostname, ))
|
||||||
c.execute("COMMIT")
|
c.execute("COMMIT")
|
||||||
|
# Validate the entire domain name using Data::Validate::Domain
|
||||||
c.execute("BEGIN")
|
c.execute("BEGIN")
|
||||||
c.callproc("api.initialize", ('root', ))
|
c.callproc("api.initialize", ('root', ))
|
||||||
c.callproc("api.validate_domain", (hostname, 'csh.rit.edu'))
|
c.callproc("api.validate_domain", (hostname, 'csh.rit.edu'))
|
||||||
valid = c.fetchall()[0][0]
|
valid = c.fetchall()[0][0]
|
||||||
c.execute("COMMIT")
|
c.execute("COMMIT")
|
||||||
|
# Check if the hostname is available (checks A/SRV/CNAME records)
|
||||||
c.execute("BEGIN")
|
c.execute("BEGIN")
|
||||||
c.callproc("api.initialize", ('root', ))
|
c.callproc("api.initialize", ('root', ))
|
||||||
c.callproc("api.check_dns_hostname", (hostname, 'csh.rit.edu'))
|
c.callproc("api.check_dns_hostname", (hostname, 'csh.rit.edu'))
|
||||||
|
@ -61,6 +65,13 @@ def check_hostname(starrs, hostname):
|
||||||
if not c.fetchall()[0][0]:
|
if not c.fetchall()[0][0]:
|
||||||
available = True
|
available = True
|
||||||
c.execute("COMMIT")
|
c.execute("COMMIT")
|
||||||
|
# Check if the system name is taken
|
||||||
|
c.execute("BEGIN")
|
||||||
|
c.callproc("api.initialize", ('root', ))
|
||||||
|
c.callproc("api.get_system", (hostname, ))
|
||||||
|
if c.fetchall():
|
||||||
|
available = False
|
||||||
|
c.execute("COMMIT")
|
||||||
except (psycopg2.InternalError):
|
except (psycopg2.InternalError):
|
||||||
valid = False
|
valid = False
|
||||||
available = False
|
available = False
|
||||||
|
|
|
@ -74,7 +74,7 @@ class User(object):
|
||||||
if 'status' in vm:
|
if 'status' in vm:
|
||||||
vm = VM(vm['vmid'])
|
vm = VM(vm['vmid'])
|
||||||
if vm.status == 'running' or vm.status == 'paused':
|
if vm.status == 'running' or vm.status == 'paused':
|
||||||
usage['cpu'] += int(vm.cpu * vm.config.get('sockets', 1))
|
usage['cpu'] += int(vm.cpu)
|
||||||
usage['mem'] += (int(vm.mem) / 1024)
|
usage['mem'] += (int(vm.mem) / 1024)
|
||||||
for disk in vm.disks:
|
for disk in vm.disks:
|
||||||
usage['disk'] += int(disk[1])
|
usage['disk'] += int(disk[1])
|
||||||
|
|
|
@ -99,11 +99,19 @@ class VM(object):
|
||||||
|
|
||||||
@lazy_property
|
@lazy_property
|
||||||
def info(self):
|
def info(self):
|
||||||
|
return self.get_info()
|
||||||
|
|
||||||
|
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
|
||||||
|
def get_info(self):
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
return proxmox.nodes(self.node).qemu(self.id).status.current.get()
|
return proxmox.nodes(self.node).qemu(self.id).status.current.get()
|
||||||
|
|
||||||
@lazy_property
|
@lazy_property
|
||||||
def config(self):
|
def config(self):
|
||||||
|
return self.get_config()
|
||||||
|
|
||||||
|
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
|
||||||
|
def get_config(self):
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
return proxmox.nodes(self.node).qemu(self.id).config.get()
|
return proxmox.nodes(self.node).qemu(self.id).config.get()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue