Skip to content

Commit

Permalink
fix system name, improve config/info, require auth to load
Browse files Browse the repository at this point in the history
  • Loading branch information
com6056 committed Feb 17, 2019
1 parent e7731bc commit 12b0f37
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
15 changes: 4 additions & 11 deletions proxstar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,10 @@

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)
Expand Down
11 changes: 11 additions & 0 deletions proxstar/starrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,36 @@ 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'))
available = False
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
Expand Down
2 changes: 1 addition & 1 deletion proxstar/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def usage(self):
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])
Expand Down
8 changes: 8 additions & 0 deletions proxstar/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,19 @@ def resume(self):

@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()

Expand Down

0 comments on commit 12b0f37

Please sign in to comment.