mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fixes various http monitor things (#33497)
Added token cleanup. Refactored a small amount of code. formatting and cleanup of code.
This commit is contained in:
parent
798de98b0c
commit
da2e20ef45
4 changed files with 89 additions and 91 deletions
|
@ -8,11 +8,9 @@ from __future__ import absolute_import, division, print_function
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
'supported_by': 'community',
|
'supported_by': 'community'}
|
||||||
'metadata_version': '1.1'
|
|
||||||
}
|
|
||||||
|
|
||||||
DOCUMENTATION = r'''
|
DOCUMENTATION = r'''
|
||||||
---
|
---
|
||||||
|
@ -240,8 +238,8 @@ class Parameters(AnsibleF5Parameters):
|
||||||
for returnable in self.returnables:
|
for returnable in self.returnables:
|
||||||
result[returnable] = getattr(self, returnable)
|
result[returnable] = getattr(self, returnable)
|
||||||
result = self._filter_params(result)
|
result = self._filter_params(result)
|
||||||
return result
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
pass
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def api_params(self):
|
def api_params(self):
|
||||||
|
@ -254,14 +252,6 @@ class Parameters(AnsibleF5Parameters):
|
||||||
result = self._filter_params(result)
|
result = self._filter_params(result)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@property
|
|
||||||
def username(self):
|
|
||||||
return self._values['target_username']
|
|
||||||
|
|
||||||
@property
|
|
||||||
def password(self):
|
|
||||||
return self._values['target_password']
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def destination(self):
|
def destination(self):
|
||||||
if self.ip is None and self.port is None:
|
if self.ip is None and self.port is None:
|
||||||
|
@ -337,6 +327,18 @@ class Parameters(AnsibleF5Parameters):
|
||||||
def type(self):
|
def type(self):
|
||||||
return 'http'
|
return 'http'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def username(self):
|
||||||
|
return self._values['target_username']
|
||||||
|
|
||||||
|
@property
|
||||||
|
def password(self):
|
||||||
|
return self._values['target_password']
|
||||||
|
|
||||||
|
|
||||||
|
class Changes(Parameters):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Difference(object):
|
class Difference(object):
|
||||||
def __init__(self, want, have=None):
|
def __init__(self, want, have=None):
|
||||||
|
@ -410,7 +412,7 @@ class ModuleManager(object):
|
||||||
self.client = client
|
self.client = client
|
||||||
self.have = None
|
self.have = None
|
||||||
self.want = Parameters(self.client.module.params)
|
self.want = Parameters(self.client.module.params)
|
||||||
self.changes = Parameters()
|
self.changes = Changes()
|
||||||
|
|
||||||
def _set_changed_options(self):
|
def _set_changed_options(self):
|
||||||
changed = {}
|
changed = {}
|
||||||
|
@ -418,7 +420,7 @@ class ModuleManager(object):
|
||||||
if getattr(self.want, key) is not None:
|
if getattr(self.want, key) is not None:
|
||||||
changed[key] = getattr(self.want, key)
|
changed[key] = getattr(self.want, key)
|
||||||
if changed:
|
if changed:
|
||||||
self.changes = Parameters(changed)
|
self.changes = Changes(changed)
|
||||||
|
|
||||||
def _update_changed_options(self):
|
def _update_changed_options(self):
|
||||||
diff = Difference(self.want, self.have)
|
diff = Difference(self.want, self.have)
|
||||||
|
@ -428,10 +430,13 @@ class ModuleManager(object):
|
||||||
change = diff.compare(k)
|
change = diff.compare(k)
|
||||||
if change is None:
|
if change is None:
|
||||||
continue
|
continue
|
||||||
|
else:
|
||||||
|
if isinstance(change, dict):
|
||||||
|
changed.update(change)
|
||||||
else:
|
else:
|
||||||
changed[k] = change
|
changed[k] = change
|
||||||
if changed:
|
if changed:
|
||||||
self.changes = Parameters(changed)
|
self.changes = Changes(changed)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -584,6 +589,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():
|
||||||
spec = ArgumentSpec()
|
spec = ArgumentSpec()
|
||||||
|
|
||||||
|
@ -592,6 +607,7 @@ def main():
|
||||||
supports_check_mode=spec.supports_check_mode,
|
supports_check_mode=spec.supports_check_mode,
|
||||||
f5_product_name=spec.f5_product_name
|
f5_product_name=spec.f5_product_name
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
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")
|
||||||
|
@ -601,8 +617,10 @@ def main():
|
||||||
|
|
||||||
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))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,15 @@
|
||||||
# Copyright (c) 2017 F5 Networks Inc.
|
# Copyright (c) 2017 F5 Networks Inc.
|
||||||
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
'supported_by': 'community'}
|
'supported_by': 'community'}
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = r'''
|
||||||
---
|
---
|
||||||
module: bigip_monitor_https
|
module: bigip_monitor_https
|
||||||
short_description: Manages F5 BIG-IP LTM https monitors
|
short_description: Manages F5 BIG-IP LTM https monitors
|
||||||
|
@ -95,38 +99,38 @@ author:
|
||||||
- Tim Rupp (@caphrim007)
|
- Tim Rupp (@caphrim007)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = r'''
|
||||||
- name: Create HTTPS Monitor
|
- name: Create HTTPS Monitor
|
||||||
bigip_monitor_https:
|
bigip_monitor_https:
|
||||||
state: "present"
|
state: present
|
||||||
ip: "10.10.10.10"
|
ip: 10.10.10.10
|
||||||
server: "lb.mydomain.com"
|
server: lb.mydomain.com
|
||||||
user: "admin"
|
user: admin
|
||||||
password: "secret"
|
password: secret
|
||||||
name: "my_http_monitor"
|
name: my_http_monitor
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: Remove HTTPS Monitor
|
- name: Remove HTTPS Monitor
|
||||||
bigip_monitor_https:
|
bigip_monitor_https:
|
||||||
state: "absent"
|
state: absent
|
||||||
server: "lb.mydomain.com"
|
server: lb.mydomain.com
|
||||||
user: "admin"
|
user: admin
|
||||||
password: "secret"
|
password: secret
|
||||||
name: "my_http_monitor"
|
name: my_http_monitor
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = r'''
|
||||||
parent:
|
parent:
|
||||||
description: New parent template of the monitor.
|
description: New parent template of the monitor.
|
||||||
returned: changed
|
returned: changed
|
||||||
type: string
|
type: string
|
||||||
sample: "https"
|
sample: https
|
||||||
ip:
|
ip:
|
||||||
description: The new IP of IP/port definition.
|
description: The new IP of IP/port definition.
|
||||||
returned: changed
|
returned: changed
|
||||||
type: string
|
type: string
|
||||||
sample: "10.12.13.14"
|
sample: 10.12.13.14
|
||||||
interval:
|
interval:
|
||||||
description: The new interval in which to run the monitor check.
|
description: The new interval in which to run the monitor check.
|
||||||
returned: changed
|
returned: changed
|
||||||
|
@ -156,8 +160,8 @@ 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 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.f5_utils import iteritems
|
from ansible.module_utils.six import iteritems
|
||||||
from ansible.module_utils.f5_utils import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
||||||
|
|
|
@ -1,21 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# Copyright 2017 F5 Networks Inc.
|
# Copyright (c) 2017 F5 Networks Inc.
|
||||||
#
|
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public Liccense for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
@ -30,22 +16,24 @@ if sys.version_info < (2, 7):
|
||||||
raise SkipTest("F5 Ansible modules require Python >= 2.7")
|
raise SkipTest("F5 Ansible modules require Python >= 2.7")
|
||||||
|
|
||||||
from ansible.compat.tests import unittest
|
from ansible.compat.tests import unittest
|
||||||
from ansible.compat.tests.mock import patch, Mock
|
from ansible.compat.tests.mock import Mock
|
||||||
|
from ansible.compat.tests.mock import patch
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
from ansible.module_utils.f5_utils import AnsibleF5Client
|
||||||
from ansible.module_utils.f5_utils import F5ModuleError
|
from ansible.module_utils.f5_utils import F5ModuleError
|
||||||
from units.modules.utils import set_module_args
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from library.bigip_monitor_http import Parameters
|
from library.bigip_monitor_http import Parameters
|
||||||
from library.bigip_monitor_http import ModuleManager
|
from library.bigip_monitor_http import ModuleManager
|
||||||
from library.bigip_monitor_http import ArgumentSpec
|
from library.bigip_monitor_http import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
||||||
|
from test.unit.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from ansible.modules.network.f5.bigip_monitor_http import Parameters
|
from ansible.modules.network.f5.bigip_monitor_http import Parameters
|
||||||
from ansible.modules.network.f5.bigip_monitor_http import ModuleManager
|
from ansible.modules.network.f5.bigip_monitor_http import ModuleManager
|
||||||
from ansible.modules.network.f5.bigip_monitor_http import ArgumentSpec
|
from ansible.modules.network.f5.bigip_monitor_http import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
||||||
|
from units.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# Copyright 2017 F5 Networks Inc.
|
# Copyright (c) 2017 F5 Networks Inc.
|
||||||
#
|
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public Liccense for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
@ -30,22 +16,24 @@ if sys.version_info < (2, 7):
|
||||||
raise SkipTest("F5 Ansible modules require Python >= 2.7")
|
raise SkipTest("F5 Ansible modules require Python >= 2.7")
|
||||||
|
|
||||||
from ansible.compat.tests import unittest
|
from ansible.compat.tests import unittest
|
||||||
from ansible.compat.tests.mock import patch, Mock
|
from ansible.compat.tests.mock import Mock
|
||||||
|
from ansible.compat.tests.mock import patch
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
from ansible.module_utils.f5_utils import AnsibleF5Client
|
||||||
from ansible.module_utils.f5_utils import F5ModuleError
|
from ansible.module_utils.f5_utils import F5ModuleError
|
||||||
from units.modules.utils import set_module_args
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from library.bigip_monitor_https import Parameters
|
from library.bigip_monitor_https import Parameters
|
||||||
from library.bigip_monitor_https import ModuleManager
|
from library.bigip_monitor_https import ModuleManager
|
||||||
from library.bigip_monitor_https import ArgumentSpec
|
from library.bigip_monitor_https import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
||||||
|
from test.unit.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from ansible.modules.network.f5.bigip_monitor_https import Parameters
|
from ansible.modules.network.f5.bigip_monitor_https import Parameters
|
||||||
from ansible.modules.network.f5.bigip_monitor_https import ModuleManager
|
from ansible.modules.network.f5.bigip_monitor_https import ModuleManager
|
||||||
from ansible.modules.network.f5.bigip_monitor_https import ArgumentSpec
|
from ansible.modules.network.f5.bigip_monitor_https import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
||||||
|
from units.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue