Fixes repeated calls to create an API object (#35816)

This patch fixes repeated attempts that the module would make to
re-create an API object. The change stores a copy for later lookup
instead. This prevents uncontrolled tokens from being created.
This commit is contained in:
Tim Rupp 2018-02-06 22:16:26 -08:00 committed by GitHub
parent e62c1cd050
commit 95188ed35c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 28 deletions

View file

@ -27,7 +27,8 @@ except ImportError:
class F5Client(F5BaseClient):
@property
def api(self):
result = None
if self._client:
return self._client
for x in range(0, 10):
try:
result = ManagementRoot(
@ -38,13 +39,11 @@ class F5Client(F5BaseClient):
verify=self.params['validate_certs'],
token='local'
)
break
self._client = result
return self._client
except Exception:
time.sleep(3)
if result:
return result
else:
raise F5ModuleError(
'Unable to connect to {0} on port {1}. '
'Is "validate_certs" preventing this?'.format(self.params['server'], self.params['server_port'])
)
raise F5ModuleError(
'Unable to connect to {0} on port {1}. '
'Is "validate_certs" preventing this?'.format(self.params['server'], self.params['server_port'])
)