mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-02-14 22:11:51 +00:00
instead of getting all pools, try to get the pool and then create it on failure
This commit is contained in:
parent
88ef6daa8a
commit
cefe605bb9
1 changed files with 8 additions and 3 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue