Add connection error handling
This commit is contained in:
parent
d7bd142387
commit
1e2b8b1652
5 changed files with 106 additions and 29 deletions
|
|
@ -86,6 +86,7 @@ class OpenNebulaManager():
|
|||
logger.info('Could not connect via client, using oneadmin instead')
|
||||
vm_pool = oca.VirtualMachinePool(self.oneadmin_client)
|
||||
vm_pool.info(filter=-2)
|
||||
return vm_pool
|
||||
|
||||
except ConnectionRefusedError:
|
||||
logger.info('Could not connect to host: {host} via protocol {protocol}'.format(
|
||||
|
|
@ -93,13 +94,16 @@ class OpenNebulaManager():
|
|||
protocol=settings.OPENNEBULA_PROTOCOL)
|
||||
)
|
||||
raise ConnectionRefusedError
|
||||
return vm_pool
|
||||
# For now we'll just handle all other errors as connection errors
|
||||
except:
|
||||
raise ConnectionRefusedError
|
||||
|
||||
def get_vms(self):
|
||||
try:
|
||||
return self._get_vm_pool()
|
||||
except ConnectionRefusedError:
|
||||
return []
|
||||
raise ConnectionRefusedError
|
||||
|
||||
|
||||
def get_vm(self, vm_id):
|
||||
vm_id = int(vm_id)
|
||||
|
|
@ -107,7 +111,7 @@ class OpenNebulaManager():
|
|||
vm_pool = self._get_vm_pool()
|
||||
return vm_pool.get_by_id(vm_id)
|
||||
except:
|
||||
return None
|
||||
raise ConnectionRefusedError
|
||||
|
||||
def create_template(self, name, cores, memory, disk_size, core_price, memory_price,
|
||||
disk_size_price, ssh='' ):
|
||||
|
|
@ -233,13 +237,16 @@ class OpenNebulaManager():
|
|||
try:
|
||||
template_pool = oca.VmTemplatePool(self.oneadmin_client)
|
||||
template_pool.info()
|
||||
return template_pool
|
||||
except ConnectionRefusedError:
|
||||
logger.info('Could not connect to host: {host} via protocol {protocol}'.format(
|
||||
host=settings.OPENNEBULA_DOMAIN,
|
||||
protocol=settings.OPENNEBULA_PROTOCOL)
|
||||
)
|
||||
raise ConnectionRefusedError
|
||||
return template_pool
|
||||
except:
|
||||
raise ConnectionRefusedError
|
||||
|
||||
|
||||
def get_templates(self):
|
||||
try:
|
||||
|
|
@ -250,6 +257,14 @@ class OpenNebulaManager():
|
|||
]
|
||||
return public_templates
|
||||
except ConnectionRefusedError:
|
||||
raise ConnectionRefusedError
|
||||
except:
|
||||
raise ConnectionRefusedError
|
||||
|
||||
def try_get_templates(self):
|
||||
try:
|
||||
return self.get_templates()
|
||||
except:
|
||||
return []
|
||||
|
||||
def get_template(self, template_id):
|
||||
|
|
@ -258,7 +273,7 @@ class OpenNebulaManager():
|
|||
template_pool = self._get_template_pool()
|
||||
return template_pool.get_by_id(template_id)
|
||||
except:
|
||||
return None
|
||||
raise ConnectionRefusedError
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue