diff --git a/proxstar/__init__.py b/proxstar/__init__.py index e9254f5..c877ca2 100644 --- a/proxstar/__init__.py +++ b/proxstar/__init__.py @@ -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) diff --git a/proxstar/starrs.py b/proxstar/starrs.py index 8a95155..fa0d0a7 100644 --- a/proxstar/starrs.py +++ b/proxstar/starrs.py @@ -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 diff --git a/proxstar/user.py b/proxstar/user.py index 9e2cbdc..6bda641 100644 --- a/proxstar/user.py +++ b/proxstar/user.py @@ -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]) diff --git a/proxstar/vm.py b/proxstar/vm.py index 4592654..4ba709e 100644 --- a/proxstar/vm.py +++ b/proxstar/vm.py @@ -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()