mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Adds token cleanup for bigip_partition (#34415)
Tokens need to be cleaned up or else the bigip may wedge itself over time if not enough tokens auto-expire.
This commit is contained in:
parent
38a31d3156
commit
b40c779e46
4 changed files with 59 additions and 11 deletions
|
@ -356,8 +356,20 @@ class ArgumentSpec(object):
|
||||||
self.f5_product_name = 'bigip'
|
self.f5_product_name = 'bigip'
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def cleanup_tokens(client):
|
||||||
try:
|
try:
|
||||||
|
resource = client.api.shared.authz.tokens_s.token.load(
|
||||||
|
name=client.api.icrs.token
|
||||||
|
)
|
||||||
|
resource.delete()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if not HAS_F5SDK:
|
||||||
|
raise F5ModuleError("The python f5-sdk module is required")
|
||||||
|
|
||||||
spec = ArgumentSpec()
|
spec = ArgumentSpec()
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
client = AnsibleF5Client(
|
||||||
|
@ -366,13 +378,13 @@ def main():
|
||||||
f5_product_name=spec.f5_product_name
|
f5_product_name=spec.f5_product_name
|
||||||
)
|
)
|
||||||
|
|
||||||
if not HAS_F5SDK:
|
try:
|
||||||
raise F5ModuleError("The python f5-sdk module is required")
|
|
||||||
|
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(client)
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
|
cleanup_tokens(client)
|
||||||
client.module.exit_json(**results)
|
client.module.exit_json(**results)
|
||||||
except F5ModuleError as e:
|
except F5ModuleError as e:
|
||||||
|
cleanup_tokens(client)
|
||||||
client.module.fail_json(msg=str(e))
|
client.module.fail_json(msg=str(e))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -194,10 +194,10 @@ import re
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
from ansible.module_utils.f5_utils import AnsibleF5Client
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Parameters
|
from ansible.module_utils.f5_utils import AnsibleF5Parameters
|
||||||
from ansible.module_utils.f5_utils import defaultdict
|
|
||||||
from ansible.module_utils.f5_utils import HAS_F5SDK
|
from ansible.module_utils.f5_utils import HAS_F5SDK
|
||||||
from ansible.module_utils.f5_utils import F5ModuleError
|
from ansible.module_utils.f5_utils import F5ModuleError
|
||||||
from ansible.module_utils.six import iteritems
|
from ansible.module_utils.six import iteritems
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
@ -669,6 +669,16 @@ class ArgumentSpec(object):
|
||||||
self.f5_product_name = 'bigip'
|
self.f5_product_name = 'bigip'
|
||||||
|
|
||||||
|
|
||||||
|
def cleanup_tokens(client):
|
||||||
|
try:
|
||||||
|
resource = client.api.shared.authz.tokens_s.token.load(
|
||||||
|
name=client.api.icrs.token
|
||||||
|
)
|
||||||
|
resource.delete()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if not HAS_F5SDK:
|
if not HAS_F5SDK:
|
||||||
raise F5ModuleError("The python f5-sdk module is required")
|
raise F5ModuleError("The python f5-sdk module is required")
|
||||||
|
@ -684,8 +694,10 @@ def main():
|
||||||
try:
|
try:
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(client)
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
|
cleanup_tokens(client)
|
||||||
client.module.exit_json(**results)
|
client.module.exit_json(**results)
|
||||||
except F5ModuleError as e:
|
except F5ModuleError as e:
|
||||||
|
cleanup_tokens(client)
|
||||||
client.module.fail_json(msg=str(e))
|
client.module.fail_json(msg=str(e))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -688,6 +688,16 @@ class ArgumentSpec(object):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def cleanup_tokens(client):
|
||||||
|
try:
|
||||||
|
resource = client.api.shared.authz.tokens_s.token.load(
|
||||||
|
name=client.api.icrs.token
|
||||||
|
)
|
||||||
|
resource.delete()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if not HAS_F5SDK:
|
if not HAS_F5SDK:
|
||||||
raise F5ModuleError("The python f5-sdk module is required")
|
raise F5ModuleError("The python f5-sdk module is required")
|
||||||
|
@ -706,9 +716,12 @@ def main():
|
||||||
try:
|
try:
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(client)
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
|
cleanup_tokens(client)
|
||||||
client.module.exit_json(**results)
|
client.module.exit_json(**results)
|
||||||
except F5ModuleError as e:
|
except F5ModuleError as e:
|
||||||
|
cleanup_tokens(client)
|
||||||
client.module.fail_json(msg=str(e))
|
client.module.fail_json(msg=str(e))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -121,7 +121,6 @@ class AnsibleF5ClientStub(AnsibleF5Client):
|
||||||
the result will replace this work here.
|
the result will replace this work here.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, argument_spec=None, supports_check_mode=False,
|
def __init__(self, argument_spec=None, supports_check_mode=False,
|
||||||
mutually_exclusive=None, required_together=None,
|
mutually_exclusive=None, required_together=None,
|
||||||
required_if=None, required_one_of=None, add_file_common_args=False,
|
required_if=None, required_one_of=None, add_file_common_args=False,
|
||||||
|
@ -396,6 +395,16 @@ class ArgumentSpec(object):
|
||||||
self.f5_product_name = 'bigip'
|
self.f5_product_name = 'bigip'
|
||||||
|
|
||||||
|
|
||||||
|
def cleanup_tokens(client):
|
||||||
|
try:
|
||||||
|
resource = client.api.shared.authz.tokens_s.token.load(
|
||||||
|
name=client.api.icrs.token
|
||||||
|
)
|
||||||
|
resource.delete()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if not HAS_F5SDK:
|
if not HAS_F5SDK:
|
||||||
raise F5ModuleError("The python f5-sdk module is required")
|
raise F5ModuleError("The python f5-sdk module is required")
|
||||||
|
@ -411,8 +420,10 @@ def main():
|
||||||
try:
|
try:
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(client)
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
|
cleanup_tokens(client)
|
||||||
client.module.exit_json(**results)
|
client.module.exit_json(**results)
|
||||||
except F5ModuleError as e:
|
except F5ModuleError as e:
|
||||||
|
cleanup_tokens(client)
|
||||||
client.module.fail_json(msg=str(e))
|
client.module.fail_json(msg=str(e))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue