mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Adds better error handling to f5 api connections (#35020)
Previously, the failure of the API connection would result in a stack trace. This patch makes the failure capable of exiting with fail_json
This commit is contained in:
parent
3371b5eb03
commit
8cc0e74448
3 changed files with 56 additions and 26 deletions
|
@ -16,19 +16,27 @@ except ImportError:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from library.module_utils.network.f5.common import F5BaseClient
|
from library.module_utils.network.f5.common import F5BaseClient
|
||||||
|
from library.module_utils.network.f5.common import F5ModuleError
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from ansible.module_utils.network.f5.common import F5BaseClient
|
from ansible.module_utils.network.f5.common import F5BaseClient
|
||||||
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
||||||
|
|
||||||
|
|
||||||
class F5Client(F5BaseClient):
|
class F5Client(F5BaseClient):
|
||||||
@property
|
@property
|
||||||
def api(self):
|
def api(self):
|
||||||
result = ManagementRoot(
|
try:
|
||||||
self.params['server'],
|
result = ManagementRoot(
|
||||||
self.params['user'],
|
self.params['server'],
|
||||||
self.params['password'],
|
self.params['user'],
|
||||||
port=self.params['server_port'],
|
self.params['password'],
|
||||||
verify=self.params['validate_certs'],
|
port=self.params['server_port'],
|
||||||
token='tmos'
|
verify=self.params['validate_certs'],
|
||||||
)
|
token='tmos'
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
raise F5ModuleError(
|
||||||
|
'Unable to connect to {0} on port {1}. '
|
||||||
|
'Is "validate_certs" preventing this?'.format(self.params['server'], self.params['server_port'])
|
||||||
|
)
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -14,18 +14,29 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_F5SDK = False
|
HAS_F5SDK = False
|
||||||
|
|
||||||
from ansible.module_utils.network.f5.common import F5BaseClient
|
try:
|
||||||
|
from library.module_utils.network.f5.common import F5BaseClient
|
||||||
|
from library.module_utils.network.f5.common import F5ModuleError
|
||||||
|
except ImportError:
|
||||||
|
from ansible.module_utils.network.f5.common import F5BaseClient
|
||||||
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
||||||
|
|
||||||
|
|
||||||
class F5Client(F5BaseClient):
|
class F5Client(F5BaseClient):
|
||||||
@property
|
@property
|
||||||
def api(self):
|
def api(self):
|
||||||
result = ManagementRoot(
|
try:
|
||||||
self.params['server'],
|
result = ManagementRoot(
|
||||||
self.params['user'],
|
self.params['server'],
|
||||||
self.params['password'],
|
self.params['user'],
|
||||||
port=self.params['server_port'],
|
self.params['password'],
|
||||||
verify=self.params['validate_certs'],
|
port=self.params['server_port'],
|
||||||
token='local'
|
verify=self.params['validate_certs'],
|
||||||
)
|
token='local'
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
raise F5ModuleError(
|
||||||
|
'Unable to connect to {0} on port {1}. '
|
||||||
|
'Is "validate_certs" preventing this?'.format(self.params['server'], self.params['server_port'])
|
||||||
|
)
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -14,18 +14,29 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_F5SDK = False
|
HAS_F5SDK = False
|
||||||
|
|
||||||
from ansible.module_utils.network.f5.common import F5BaseClient
|
try:
|
||||||
|
from library.module_utils.network.f5.common import F5BaseClient
|
||||||
|
from library.module_utils.network.f5.common import F5ModuleError
|
||||||
|
except ImportError:
|
||||||
|
from ansible.module_utils.network.f5.common import F5BaseClient
|
||||||
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
||||||
|
|
||||||
|
|
||||||
class F5Client(F5BaseClient):
|
class F5Client(F5BaseClient):
|
||||||
@property
|
@property
|
||||||
def api(self):
|
def api(self):
|
||||||
result = ManagementRoot(
|
try:
|
||||||
self.params['server'],
|
result = ManagementRoot(
|
||||||
self.params['user'],
|
self.params['server'],
|
||||||
self.params['password'],
|
self.params['user'],
|
||||||
port=self.params['server_port'],
|
self.params['password'],
|
||||||
verify=self.params['validate_certs'],
|
port=self.params['server_port'],
|
||||||
token='local'
|
verify=self.params['validate_certs'],
|
||||||
)
|
token='local'
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
raise F5ModuleError(
|
||||||
|
'Unable to connect to {0} on port {1}. '
|
||||||
|
'Is "validate_certs" preventing this?'.format(self.params['server'], self.params['server_port'])
|
||||||
|
)
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Add table
Reference in a new issue