Merge branch 'bugfix/6669/opennebula-vm-query-takes-long' into 'master'
Bugfix/6669/opennebula vm query takes long See merge request ungleich-public/dynamicweb!703
This commit is contained in:
commit
10be0e472d
1 changed files with 32 additions and 8 deletions
|
@ -168,24 +168,48 @@ class OpenNebulaManager():
|
||||||
raise
|
raise
|
||||||
return user_pool
|
return user_pool
|
||||||
|
|
||||||
def _get_vm_pool(self, vm_id=None, infoextended=True):
|
def _get_vm_pool(self, infoextended=True):
|
||||||
"""
|
"""
|
||||||
vm_id: int - the id of the VM that needs to looked up in the vm pool;
|
# filter:
|
||||||
when set to None, looks for everything in the infoextended
|
# -4: Resources belonging to the user’s primary group
|
||||||
|
# -3: Resources belonging to the user
|
||||||
|
# -2: All resources
|
||||||
|
# -1: Resources belonging to the user and any of his groups
|
||||||
|
# >= 0: UID User’s Resources
|
||||||
|
|
||||||
|
# vm states:
|
||||||
|
# *-2 Any state, including DONE
|
||||||
|
# *-1 Any state, except DONE (Default)
|
||||||
|
# *0 INIT
|
||||||
|
# *1 PENDING
|
||||||
|
# *2 HOLD
|
||||||
|
# *3 ACTIVE
|
||||||
|
# *4 STOPPED
|
||||||
|
# *5 SUSPENDED
|
||||||
|
# *6 DONE
|
||||||
|
# *7 FAILED
|
||||||
|
# *8 POWEROFF
|
||||||
|
# *9 UNDEPLOYED
|
||||||
|
|
||||||
|
:param infoextended: When True calls infoextended api method introduced
|
||||||
|
in OpenNebula 5.8 else falls back to info which has limited attributes
|
||||||
|
of a VM
|
||||||
|
|
||||||
|
:return: the oca VirtualMachinePool object
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
vm_pool = oca.VirtualMachinePool(self.client)
|
vm_pool = oca.VirtualMachinePool(self.client)
|
||||||
if infoextended:
|
if infoextended:
|
||||||
vm_pool.infoextended(
|
vm_pool.infoextended(
|
||||||
filter_key_value_str='ID={vm_id}'.format(vm_id=vm_id) if
|
filter=-1, # User's resources and any of his groups
|
||||||
vm_id is not None else '',
|
vm_state=-1 # Look for VMs in any state, except DONE
|
||||||
vm_state=-1 # Look for VMs in any state, except DONE
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
vm_pool.info()
|
vm_pool.info()
|
||||||
return vm_pool
|
return vm_pool
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
logger.error('Could not connect via client, using oneadmin instead')
|
logger.error(
|
||||||
|
'Could not connect via client, using oneadmin instead')
|
||||||
try:
|
try:
|
||||||
vm_pool = oca.VirtualMachinePool(self.oneadmin_client)
|
vm_pool = oca.VirtualMachinePool(self.oneadmin_client)
|
||||||
vm_pool.info(filter=-2)
|
vm_pool.info(filter=-2)
|
||||||
|
@ -213,7 +237,7 @@ class OpenNebulaManager():
|
||||||
def get_vm(self, vm_id):
|
def get_vm(self, vm_id):
|
||||||
vm_id = int(vm_id)
|
vm_id = int(vm_id)
|
||||||
try:
|
try:
|
||||||
vm_pool = self._get_vm_pool(vm_id)
|
vm_pool = self._get_vm_pool()
|
||||||
return vm_pool.get_by_id(vm_id)
|
return vm_pool.get_by_id(vm_id)
|
||||||
except WrongIdError:
|
except WrongIdError:
|
||||||
raise WrongIdError
|
raise WrongIdError
|
||||||
|
|
Loading…
Reference in a new issue