From 55d2632d78b888c6e5b37657113c0b5e6e4cb5d9 Mon Sep 17 00:00:00 2001 From: Wojciech Wypior Date: Tue, 19 Mar 2019 07:12:50 +0100 Subject: [PATCH] adds function to do version checks for bigiq (#53985) --- .../module_utils/network/f5/icontrol.py | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/network/f5/icontrol.py b/lib/ansible/module_utils/network/f5/icontrol.py index 7f8e294a3b..57d0bb727b 100644 --- a/lib/ansible/module_utils/network/f5/icontrol.py +++ b/lib/ansible/module_utils/network/f5/icontrol.py @@ -280,7 +280,7 @@ class TransactionContextManager(object): return self.client def __exit__(self, exc_type, exc_value, exc_tb): - self.client.request.headers.pop('X-F5-REST-Coordination-Id') + self.client.api.request.headers.pop('X-F5-REST-Coordination-Id') if exc_tb is None: uri = "https://{0}:{1}/mgmt/tm/transaction/{2}".format( self.client.provider['server'], @@ -506,6 +506,35 @@ def tmos_version(client): return version +def bigiq_version(client): + uri = "https://{0}:{1}/mgmt/shared/resolver/device-groups/cm-shared-all-big-iqs/devices".format( + client.provider['server'], + client.provider['server_port'], + ) + query = "?$select=version" + + resp = client.api.get(uri + query) + + try: + response = resp.json() + except ValueError as ex: + raise F5ModuleError(str(ex)) + + if 'code' in response and response['code'] in [400, 403]: + if 'message' in response: + raise F5ModuleError(response['message']) + else: + raise F5ModuleError(resp.content) + + if 'items' in response: + version = response['items'][0]['version'] + return version + + raise F5ModuleError( + 'Failed to retrieve BIGIQ version information.' + ) + + def module_provisioned(client, module_name): provisioned = modules_provisioned(client) if module_name in provisioned: