This commit is contained in:
PCoder 2019-05-09 00:06:22 +02:00
parent 8afed25d04
commit d5dc5df1f2

View file

@ -169,18 +169,47 @@ class OpenNebulaManager():
return user_pool return user_pool
def _get_vm_pool(self, infoextended=True): def _get_vm_pool(self, infoextended=True):
"""
# 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 base 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=-1, filter=-1, # User's resources and any of his groups
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)
@ -208,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