Add ConnectionRefusedError exception
This commit is contained in:
parent
714849fb49
commit
ec945cc31b
1 changed files with 15 additions and 4 deletions
|
@ -31,6 +31,7 @@ class OpenNebulaManager():
|
||||||
settings.OPENNEBULA_PASSWORD
|
settings.OPENNEBULA_PASSWORD
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if not create_user:
|
if not create_user:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -60,15 +61,25 @@ class OpenNebulaManager():
|
||||||
|
|
||||||
def _get_or_create_user(self, email, password):
|
def _get_or_create_user(self, email, password):
|
||||||
try:
|
try:
|
||||||
user_pool = oca.UserPool(self.oneadmin_client)
|
user_pool = self._get_user_pool()
|
||||||
user_pool.info()
|
|
||||||
opennebula_user = user_pool.get_by_name(email)
|
opennebula_user = user_pool.get_by_name(email)
|
||||||
return opennebula_user
|
return opennebula_user
|
||||||
except WrongNameError as wrong_name_err:
|
except WrongNameError as wrong_name_err:
|
||||||
opennebula_user = self.oneadmin_client.call(oca.User.METHODS['allocate'], email,
|
opennebula_user = self.oneadmin_client.call(oca.User.METHODS['allocate'], email,
|
||||||
password, 'core')
|
password, 'core')
|
||||||
|
except ConnectionRefusedError:
|
||||||
|
print('Could not connect to host: {host} via protocol {protocol}'.format(
|
||||||
|
host=settings.OPENNEBULA_DOMAIN,
|
||||||
|
protocol=settings.OPENNEBULA_PROTOCOL)
|
||||||
|
)
|
||||||
return opennebula_user
|
return opennebula_user
|
||||||
def _get_user_pool(self):
|
def _get_user_pool(self):
|
||||||
|
try:
|
||||||
user_pool = oca.UserPool(self.oneadmin_client)
|
user_pool = oca.UserPool(self.oneadmin_client)
|
||||||
user_pool.info()
|
user_pool.info()
|
||||||
|
except ConnectionRefusedError:
|
||||||
|
print('Could not connect to host: {host} via protocol {protocol}'.format(
|
||||||
|
host=settings.OPENNEBULA_DOMAIN,
|
||||||
|
protocol=settings.OPENNEBULA_PROTOCOL)
|
||||||
|
)
|
||||||
return user_pool
|
return user_pool
|
||||||
|
|
Loading…
Reference in a new issue