diff --git a/proxstar/user.py b/proxstar/user.py index 5c0d6f1..785c75e 100644 --- a/proxstar/user.py +++ b/proxstar/user.py @@ -4,6 +4,7 @@ from proxstar.vm import VM from proxstar.util import * from proxstar.proxmox import * from rq.registry import StartedJobRegistry +from proxmoxer.core import ResourceException class User(object): @@ -17,14 +18,18 @@ class User(object): @lazy_property def vms(self): proxmox = connect_proxmox() - pools = get_pools(proxmox, db) - if self.name not in pools: + try: + # try to get the users vms from their pool + vms = proxmox.pools(self.name).get()['members'] + except ResourceException: + # they likely don't have a pool yet, try to create it if is_user(self.name) and not is_rtp(self.name): proxmox.pools.post( poolid=self.name, comment='Managed by Proxstar') + # if created, their pool is empty so return empty array + return [] else: return [] - vms = proxmox.pools(self.name).get()['members'] for vm in vms: if 'name' not in vm: vms.remove(vm)