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
pull/35028/head
Tim Rupp 7 years ago committed by GitHub
parent 3371b5eb03
commit 8cc0e74448
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,13 +16,16 @@ except ImportError:
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):
@property
def api(self):
try:
result = ManagementRoot(
self.params['server'],
self.params['user'],
@ -31,4 +34,9 @@ class F5Client(F5BaseClient):
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

@ -14,12 +14,18 @@ try:
except ImportError:
HAS_F5SDK = False
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):
@property
def api(self):
try:
result = ManagementRoot(
self.params['server'],
self.params['user'],
@ -28,4 +34,9 @@ class F5Client(F5BaseClient):
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

@ -14,12 +14,18 @@ try:
except ImportError:
HAS_F5SDK = False
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):
@property
def api(self):
try:
result = ManagementRoot(
self.params['server'],
self.params['user'],
@ -28,4 +34,9 @@ class F5Client(F5BaseClient):
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

Loading…
Cancel
Save