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:
pcoder116 2019-05-09 00:09:41 +02:00
commit 10be0e472d

View file

@ -168,24 +168,48 @@ class OpenNebulaManager():
raise
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;
when set to None, looks for everything in the infoextended
# filter:
# -4: Resources belonging to the users primary group
# -3: Resources belonging to the user
# -2: All resources
# -1: Resources belonging to the user and any of his groups
# >= 0: UID Users 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:
vm_pool = oca.VirtualMachinePool(self.client)
if infoextended:
vm_pool.infoextended(
filter_key_value_str='ID={vm_id}'.format(vm_id=vm_id) if
vm_id is not None else '',
vm_state=-1 # Look for VMs in any state, except DONE
filter=-1, # User's resources and any of his groups
vm_state=-1 # Look for VMs in any state, except DONE
)
else:
vm_pool.info()
return vm_pool
except AttributeError:
logger.error('Could not connect via client, using oneadmin instead')
logger.error(
'Could not connect via client, using oneadmin instead')
try:
vm_pool = oca.VirtualMachinePool(self.oneadmin_client)
vm_pool.info(filter=-2)
@ -213,7 +237,7 @@ class OpenNebulaManager():
def get_vm(self, vm_id):
vm_id = int(vm_id)
try:
vm_pool = self._get_vm_pool(vm_id)
vm_pool = self._get_vm_pool()
return vm_pool.get_by_id(vm_id)
except WrongIdError:
raise WrongIdError