From db834cafaadb0ea55d48e48241d0d10161600c1f Mon Sep 17 00:00:00 2001 From: Tim Rupp Date: Wed, 14 Jun 2017 09:09:48 -0700 Subject: [PATCH] Adds a reconnect method (#25625) This is being made available so that module developers do not need to use the gnarly long-form version to get a similar result --- lib/ansible/module_utils/f5_utils.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/ansible/module_utils/f5_utils.py b/lib/ansible/module_utils/f5_utils.py index 65579747096..567f7e86160 100644 --- a/lib/ansible/module_utils/f5_utils.py +++ b/lib/ansible/module_utils/f5_utils.py @@ -203,6 +203,8 @@ class AnsibleF5Client(object): required_if=None, required_one_of=None, f5_product_name='bigip'): + self.f5_product_name = f5_product_name + merged_arg_spec = dict() merged_arg_spec.update(F5_COMMON_ARGS) if argument_spec: @@ -275,6 +277,25 @@ class AnsibleF5Client(object): token='local' ) + def reconnect(self): + """Attempts to reconnect to a device + + The existing token from a ManagementRoot can become invalid if you, + for example, upgrade the device (such as is done in the *_software + module. + + This method can be used to reconnect to a remote device without + having to re-instantiate the ArgumentSpec and AnsibleF5Client classes + it will use the same values that were initially provided to those + classes + + :return: + :raises iControlUnexpectedHTTPError + """ + self.client.api = self._get_mgmt_root( + self.f5_product_name, **self._connect_params + ) + class AnsibleF5Parameters(object): def __init__(self, params=None):