fix system name, improve config/info, require auth to load

This commit is contained in:
Jordan Rodgers 2019-02-16 19:53:45 -05:00
parent e7731bc66a
commit 12b0f37da5
4 changed files with 24 additions and 12 deletions

View file

@ -38,17 +38,10 @@ with open('proxmox_ssh_key', 'w') as key:
ssh_tunnels = []
retry = 0
while retry < 5:
try:
auth = OIDCAuthentication(
app,
issuer=app.config['OIDC_ISSUER'],
client_registration_info=app.config['OIDC_CLIENT_CONFIG'])
break
except:
retry += 1
time.sleep(2)
auth = OIDCAuthentication(
app,
issuer=app.config['OIDC_ISSUER'],
client_registration_info=app.config['OIDC_CLIENT_CONFIG'])
redis_conn = Redis(app.config['REDIS_HOST'], app.config['REDIS_PORT'])
q = Queue(connection=redis_conn)

View file

@ -42,18 +42,22 @@ def renew_ip(starrs, addr):
return results
# Use various STARRS stored procedures to make sure the hostname is valid/available
def check_hostname(starrs, hostname):
c = starrs.cursor()
try:
# Check for invalid characters in hostname
c.execute("BEGIN")
c.callproc("api.initialize", ('root', ))
c.callproc("api.validate_name", (hostname, ))
c.execute("COMMIT")
# Validate the entire domain name using Data::Validate::Domain
c.execute("BEGIN")
c.callproc("api.initialize", ('root', ))
c.callproc("api.validate_domain", (hostname, 'csh.rit.edu'))
valid = c.fetchall()[0][0]
c.execute("COMMIT")
# Check if the hostname is available (checks A/SRV/CNAME records)
c.execute("BEGIN")
c.callproc("api.initialize", ('root', ))
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]:
available = True
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):
valid = False
available = False

View file

@ -74,7 +74,7 @@ class User(object):
if 'status' in vm:
vm = VM(vm['vmid'])
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)
for disk in vm.disks:
usage['disk'] += int(disk[1])

View file

@ -99,11 +99,19 @@ class VM(object):
@lazy_property
def info(self):
return self.get_info()
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
def get_info(self):
proxmox = connect_proxmox()
return proxmox.nodes(self.node).qemu(self.id).status.current.get()
@lazy_property
def config(self):
return self.get_config()
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
def get_config(self):
proxmox = connect_proxmox()
return proxmox.nodes(self.node).qemu(self.id).config.get()