From 3f75fac1581dd28d17263322c67855813cada708 Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 11 Apr 2019 01:05:34 +0200 Subject: [PATCH 1/2] Make use of the infoextended method where needed --- opennebula_api/models.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/opennebula_api/models.py b/opennebula_api/models.py index adc39bf0..a348cf86 100644 --- a/opennebula_api/models.py +++ b/opennebula_api/models.py @@ -168,10 +168,21 @@ class OpenNebulaManager(): raise return user_pool - def _get_vm_pool(self): + def _get_vm_pool(self, vm_id=None, 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 + """ try: vm_pool = oca.VirtualMachinePool(self.client) - vm_pool.info() + 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=3 # look for VMs only in ACTIVE state + ) + else: + vm_pool.info() return vm_pool except AttributeError: logger.error('Could not connect via client, using oneadmin instead') @@ -202,7 +213,7 @@ class OpenNebulaManager(): def get_vm(self, vm_id): vm_id = int(vm_id) try: - vm_pool = self._get_vm_pool() + vm_pool = self._get_vm_pool(vm_id) return vm_pool.get_by_id(vm_id) except WrongIdError: raise WrongIdError From 5f8cc2199bea22f6b525a0b517396e64801c9163 Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 11 Apr 2019 01:39:06 +0200 Subject: [PATCH 2/2] Change vm_pool infoextended to retrieve VMs in any state except DONE --- datacenterlight/tasks.py | 2 ++ opennebula_api/models.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/datacenterlight/tasks.py b/datacenterlight/tasks.py index 2779f79b..5f12b7df 100644 --- a/datacenterlight/tasks.py +++ b/datacenterlight/tasks.py @@ -245,6 +245,8 @@ def create_vm_task(self, vm_template_id, user, specs, template, order_id): } email = EmailMessage(**email_data) email.send() + else: + logger.debug("VM's ipv6 is None. Hence not created VMDetail") except Exception as e: logger.error(str(e)) try: diff --git a/opennebula_api/models.py b/opennebula_api/models.py index a348cf86..73dc4405 100644 --- a/opennebula_api/models.py +++ b/opennebula_api/models.py @@ -179,7 +179,7 @@ class OpenNebulaManager(): vm_pool.infoextended( filter_key_value_str='ID={vm_id}'.format(vm_id=vm_id) if vm_id is not None else '', - vm_state=3 # look for VMs only in ACTIVE state + vm_state=-1 # Look for VMs in any state, except DONE ) else: vm_pool.info()