From 1fd6821db0714bf378fec9ff11b2231f29ea1822 Mon Sep 17 00:00:00 2001 From: Tim Rupp Date: Thu, 23 Aug 2018 15:28:08 -0400 Subject: [PATCH] Add parameter and remove netaddr (#44584) This patch adds a description parameter to most fields. It also removes netaddr from the modules. --- .../network/f5/bigip_monitor_external.py | 52 +++++++++++-------- .../modules/network/f5/bigip_monitor_http.py | 40 +++++++------- .../modules/network/f5/bigip_monitor_https.py | 45 ++++++++-------- .../network/f5/bigip_monitor_snmp_dca.py | 8 ++- .../modules/network/f5/bigip_monitor_tcp.py | 39 ++++++++------ .../network/f5/bigip_monitor_tcp_echo.py | 39 ++++++++------ .../network/f5/bigip_monitor_tcp_half_open.py | 47 +++++++++-------- .../modules/network/f5/bigip_monitor_udp.py | 41 ++++++++------- 8 files changed, 176 insertions(+), 135 deletions(-) diff --git a/lib/ansible/modules/network/f5/bigip_monitor_external.py b/lib/ansible/modules/network/f5/bigip_monitor_external.py index 0a514711a9e..efeec55bbff 100644 --- a/lib/ansible/modules/network/f5/bigip_monitor_external.py +++ b/lib/ansible/modules/network/f5/bigip_monitor_external.py @@ -24,12 +24,16 @@ options: description: - Specifies the name of the monitor. required: True + description: + description: + - The description of the monitor. + version_added: 2.7 parent: description: - The parent template of this monitor template. Once this value has been set, it cannot be changed. By default, this value is the C(http) parent on the C(Common) partition. - default: "/Common/external" + default: /Common/external arguments: description: - Specifies any command-line arguments that the script requires. @@ -59,12 +63,14 @@ options: timeout: description: - The number of seconds in which the node or service must respond to - the monitor request. If the target responds within the set time - period, it is considered up. If the target does not respond within - the set time period, it is considered down. You can change this - number to any number you want, however, it should be 3 times the - interval number of seconds plus 1 second. If this parameter is not - provided when creating a new monitor, then the default value will be 16. + the monitor request. + - If the target responds within the set time period, it is considered up. + - If the target does not respond within the set time period, it is considered + down. + - You can change this number to any number you want, however, it should be + 3 times the interval number of seconds plus 1 second. + - If this parameter is not provided when creating a new monitor, then the + default value will be C(16). variables: description: - Specifies any variables that the script requires. @@ -84,6 +90,7 @@ options: extends_documentation_fragment: f5 author: - Tim Rupp (@caphrim007) + - Wojciech Wypior (@wojtek0806) ''' EXAMPLES = r''' @@ -130,6 +137,11 @@ parent: returned: changed type: string sample: external +description: + description: The description of the monitor. + returned: changed + type: str + sample: Important Monitor ip: description: The new IP of IP/port definition. returned: changed @@ -163,6 +175,7 @@ try: from library.module_utils.network.f5.common import fq_name from library.module_utils.network.f5.common import f5_argument_spec from library.module_utils.network.f5.common import compare_dictionary + from library.module_utils.network.f5.ipaddress import is_valid_ip try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -176,17 +189,12 @@ except ImportError: from ansible.module_utils.network.f5.common import fq_name from ansible.module_utils.network.f5.common import f5_argument_spec from ansible.module_utils.network.f5.common import compare_dictionary + from ansible.module_utils.network.f5.ipaddress import is_valid_ip try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: HAS_F5SDK = False -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False - class Parameters(AnsibleF5Parameters): api_map = { @@ -197,17 +205,17 @@ class Parameters(AnsibleF5Parameters): } api_attributes = [ - 'defaultsFrom', 'interval', 'timeout', 'destination', 'run', 'args' + 'defaultsFrom', 'interval', 'timeout', 'destination', 'run', 'args', 'description' ] returnables = [ 'parent', 'ip', 'port', 'interval', 'timeout', 'variables', 'external_program', - 'arguments' + 'arguments', 'description' ] updatables = [ 'destination', 'interval', 'timeout', 'variables', 'external_program', - 'arguments' + 'arguments', 'description' ] def to_return(self): @@ -256,12 +264,11 @@ class Parameters(AnsibleF5Parameters): def ip(self): if self._values['ip'] is None: return None - try: - if self._values['ip'] in ['*', '0.0.0.0']: - return '*' - result = str(netaddr.IPAddress(self._values['ip'])) - return result - except netaddr.core.AddrFormatError: + if self._values['ip'] in ['*', '0.0.0.0']: + return '*' + elif is_valid_ip(self._values['ip']): + return self._values['ip'] + else: raise F5ModuleError( "The provided 'ip' parameter is not an IP address." ) @@ -609,6 +616,7 @@ class ArgumentSpec(object): argument_spec = dict( name=dict(required=True), parent=dict(default='/Common/external'), + description=dict(), arguments=dict(), ip=dict(), port=dict(type='int'), diff --git a/lib/ansible/modules/network/f5/bigip_monitor_http.py b/lib/ansible/modules/network/f5/bigip_monitor_http.py index 09f800a0de0..bf7a20bf43d 100644 --- a/lib/ansible/modules/network/f5/bigip_monitor_http.py +++ b/lib/ansible/modules/network/f5/bigip_monitor_http.py @@ -28,7 +28,11 @@ options: - The parent template of this monitor template. Once this value has been set, it cannot be changed. By default, this value is the C(http) parent on the C(Common) partition. - default: "/Common/http" + default: /Common/http + description: + description: + - The description of the monitor. + version_added: 2.7 send: description: - The send string for the monitor call. When creating a new monitor, if @@ -100,6 +104,7 @@ notes: extends_documentation_fragment: f5 author: - Tim Rupp (@caphrim007) + - Wojciech Wypior (@wojtek0806) ''' EXAMPLES = r''' @@ -140,6 +145,11 @@ parent: returned: changed type: string sample: http +description: + description: The description of the monitor. + returned: changed + type: str + sample: Important_Monitor ip: description: The new IP of IP/port definition. returned: changed @@ -173,6 +183,7 @@ try: from library.module_utils.network.f5.common import cleanup_tokens from library.module_utils.network.f5.common import fq_name from library.module_utils.network.f5.common import f5_argument_spec + from library.module_utils.network.f5.ipaddress import is_valid_ip try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -185,17 +196,12 @@ except ImportError: from ansible.module_utils.network.f5.common import cleanup_tokens from ansible.module_utils.network.f5.common import fq_name from ansible.module_utils.network.f5.common import f5_argument_spec + from ansible.module_utils.network.f5.ipaddress import is_valid_ip try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: HAS_F5SDK = False -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False - class Parameters(AnsibleF5Parameters): api_map = { @@ -207,17 +213,17 @@ class Parameters(AnsibleF5Parameters): api_attributes = [ 'timeUntilUp', 'defaultsFrom', 'interval', 'timeout', 'recv', 'send', - 'destination', 'username', 'password', 'recvDisable' + 'destination', 'username', 'password', 'recvDisable', 'description' ] returnables = [ 'parent', 'send', 'receive', 'ip', 'port', 'interval', 'timeout', - 'time_until_up', 'receive_disable' + 'time_until_up', 'receive_disable', 'description' ] updatables = [ 'destination', 'send', 'receive', 'interval', 'timeout', 'time_until_up', - 'target_username', 'target_password', 'receive_disable' + 'target_username', 'target_password', 'receive_disable', 'description' ] def to_return(self): @@ -266,12 +272,11 @@ class Parameters(AnsibleF5Parameters): def ip(self): if self._values['ip'] is None: return None - try: - if self._values['ip'] in ['*', '0.0.0.0']: - return '*' - result = str(netaddr.IPAddress(self._values['ip'])) - return result - except netaddr.core.AddrFormatError: + if self._values['ip'] in ['*', '0.0.0.0']: + return '*' + elif is_valid_ip(self._values['ip']): + return self._values['ip'] + else: raise F5ModuleError( "The provided 'ip' parameter is not an IP address." ) @@ -545,6 +550,7 @@ class ArgumentSpec(object): argument_spec = dict( name=dict(required=True), parent=dict(default='/Common/http'), + description=dict(), send=dict(), receive=dict(), receive_disable=dict(required=False), @@ -578,8 +584,6 @@ def main(): ) if not HAS_F5SDK: module.fail_json(msg="The python f5-sdk module is required") - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: client = F5Client(**module.params) diff --git a/lib/ansible/modules/network/f5/bigip_monitor_https.py b/lib/ansible/modules/network/f5/bigip_monitor_https.py index 29f354747c0..1b13b2a7867 100644 --- a/lib/ansible/modules/network/f5/bigip_monitor_https.py +++ b/lib/ansible/modules/network/f5/bigip_monitor_https.py @@ -23,12 +23,16 @@ options: description: - Monitor name. required: True + description: + description: + - The description of the monitor. + version_added: 2.7 parent: description: - The parent template of this monitor template. Once this value has been set, it cannot be changed. By default, this value is the C(https) parent on the C(Common) partition. - default: "/Common/https" + default: /Common/https send: description: - The send string for the monitor call. When creating a new monitor, if @@ -99,6 +103,7 @@ notes: extends_documentation_fragment: f5 author: - Tim Rupp (@caphrim007) + - Wojciech Wypior (@wojtek0806) ''' EXAMPLES = r''' @@ -138,6 +143,11 @@ interval: returned: changed type: int sample: 2 +description: + description: The description of the monitor. + returned: changed + type: str + sample: Important Monitor timeout: description: The new timeout in which the remote system must respond to the monitor. returned: changed @@ -161,6 +171,7 @@ try: from library.module_utils.network.f5.common import cleanup_tokens from library.module_utils.network.f5.common import fq_name from library.module_utils.network.f5.common import f5_argument_spec + from library.module_utils.network.f5.ipaddress import is_valid_ip try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -173,17 +184,12 @@ except ImportError: from ansible.module_utils.network.f5.common import cleanup_tokens from ansible.module_utils.network.f5.common import fq_name from ansible.module_utils.network.f5.common import f5_argument_spec + from ansible.module_utils.network.f5.ipaddress import is_valid_ip try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: HAS_F5SDK = False -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False - class Parameters(AnsibleF5Parameters): api_map = { @@ -195,17 +201,17 @@ class Parameters(AnsibleF5Parameters): api_attributes = [ 'timeUntilUp', 'defaultsFrom', 'interval', 'timeout', 'recv', 'send', - 'destination', 'username', 'password', 'recvDisable' + 'destination', 'username', 'password', 'recvDisable', 'description' ] returnables = [ 'parent', 'send', 'receive', 'ip', 'port', 'interval', 'timeout', - 'time_until_up', 'receive_disable' + 'time_until_up', 'receive_disable', 'description' ] updatables = [ 'destination', 'send', 'receive', 'interval', 'timeout', 'time_until_up', - 'target_username', 'target_password', 'receive_disable' + 'target_username', 'target_password', 'receive_disable', 'description' ] def to_return(self): @@ -262,15 +268,13 @@ class Parameters(AnsibleF5Parameters): def ip(self): if self._values['ip'] is None: return None - try: - if self._values['ip'] in ['*', '0.0.0.0']: - return '*' - result = str(netaddr.IPAddress(self._values['ip'])) - return result - except netaddr.core.AddrFormatError: - raise F5ModuleError( - "The provided 'ip' parameter is not an IP address." - ) + elif self._values['ip'] in ['*', '0.0.0.0']: + return '*' + elif is_valid_ip(self._values['ip']): + return self._values['ip'] + raise F5ModuleError( + "The provided 'ip' parameter is not an IP address." + ) @property def port(self): @@ -530,6 +534,7 @@ class ArgumentSpec(object): argument_spec = dict( name=dict(required=True), parent=dict(default='/Common/https'), + description=dict(), send=dict(), receive=dict(), receive_disable=dict(required=False), @@ -563,8 +568,6 @@ def main(): ) if not HAS_F5SDK: module.fail_json(msg="The python f5-sdk module is required") - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: client = F5Client(**module.params) diff --git a/lib/ansible/modules/network/f5/bigip_monitor_snmp_dca.py b/lib/ansible/modules/network/f5/bigip_monitor_snmp_dca.py index ea7f17ff82c..079dee61d77 100644 --- a/lib/ansible/modules/network/f5/bigip_monitor_snmp_dca.py +++ b/lib/ansible/modules/network/f5/bigip_monitor_snmp_dca.py @@ -129,6 +129,7 @@ notes: extends_documentation_fragment: f5 author: - Tim Rupp (@caphrim007) + - Wojciech Wypior (@wojtek0806) ''' EXAMPLES = r''' @@ -157,6 +158,11 @@ parent: returned: changed type: string sample: snmp_dca +description: + description: The description of the monitor. + returned: changed + type: str + sample: Important Monitor interval: description: The new interval in which to run the monitor check. returned: changed @@ -264,7 +270,7 @@ class Parameters(AnsibleF5Parameters): api_attributes = [ 'timeUntilUp', 'defaultsFrom', 'interval', 'timeout', 'destination', 'community', 'version', 'agentType', 'cpuCoefficient', 'cpuThreshold', 'memoryCoefficient', - 'memoryThreshold', 'diskCoefficient', 'diskThreshold' + 'memoryThreshold', 'diskCoefficient', 'diskThreshold', 'description' ] returnables = [ diff --git a/lib/ansible/modules/network/f5/bigip_monitor_tcp.py b/lib/ansible/modules/network/f5/bigip_monitor_tcp.py index d305b580a1e..b9bee763af7 100644 --- a/lib/ansible/modules/network/f5/bigip_monitor_tcp.py +++ b/lib/ansible/modules/network/f5/bigip_monitor_tcp.py @@ -29,6 +29,10 @@ options: been set, it cannot be changed. By default, this value is the C(tcp) parent on the C(Common) partition. default: /Common/tcp + description: + description: + - The description of the monitor. + version_added: 2.7 send: description: - The send string for the monitor call. @@ -90,6 +94,7 @@ notes: extends_documentation_fragment: f5 author: - Tim Rupp (@caphrim007) + - Wojciech Wypior (@wojtek0806) ''' EXAMPLES = r''' @@ -126,6 +131,11 @@ send: returned: changed type: string sample: tcp string to send +description: + description: The description of the monitor. + returned: changed + type: str + sample: Important Monitor receive: description: The new receive string for this monitor. returned: changed @@ -169,6 +179,7 @@ try: from library.module_utils.network.f5.common import cleanup_tokens from library.module_utils.network.f5.common import fq_name from library.module_utils.network.f5.common import f5_argument_spec + from library.module_utils.network.f5.ipaddress import is_valid_ip try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -181,17 +192,12 @@ except ImportError: from ansible.module_utils.network.f5.common import cleanup_tokens from ansible.module_utils.network.f5.common import fq_name from ansible.module_utils.network.f5.common import f5_argument_spec + from ansible.module_utils.network.f5.ipaddress import is_valid_ip try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: HAS_F5SDK = False -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False - class Parameters(AnsibleF5Parameters): api_map = { @@ -202,16 +208,17 @@ class Parameters(AnsibleF5Parameters): api_attributes = [ 'timeUntilUp', 'defaultsFrom', 'interval', 'timeout', 'recv', 'send', - 'destination' + 'destination', 'description' ] returnables = [ 'parent', 'send', 'receive', 'ip', 'port', 'interval', 'timeout', - 'time_until_up' + 'time_until_up', 'description' ] updatables = [ - 'destination', 'send', 'receive', 'interval', 'timeout', 'time_until_up' + 'destination', 'send', 'receive', 'interval', 'timeout', 'time_until_up', + 'description' ] def to_return(self): @@ -254,12 +261,11 @@ class Parameters(AnsibleF5Parameters): def ip(self): if self._values['ip'] is None: return None - try: - if self._values['ip'] in ['*', '0.0.0.0']: - return '*' - result = str(netaddr.IPAddress(self._values['ip'])) - return result - except netaddr.core.AddrFormatError: + if self._values['ip'] in ['*', '0.0.0.0']: + return '*' + if is_valid_ip(self._values['ip']): + return self._values['ip'] + else: raise F5ModuleError( "The provided 'ip' parameter is not an IP address." ) @@ -536,6 +542,7 @@ class ArgumentSpec(object): argument_spec = dict( name=dict(required=True), parent=dict(default='/Common/tcp'), + description=dict(), send=dict(), receive=dict(), ip=dict(), @@ -566,8 +573,6 @@ def main(): ) if not HAS_F5SDK: module.fail_json(msg="The python f5-sdk module is required") - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: client = F5Client(**module.params) diff --git a/lib/ansible/modules/network/f5/bigip_monitor_tcp_echo.py b/lib/ansible/modules/network/f5/bigip_monitor_tcp_echo.py index 9d20ef26e01..ff541771be7 100644 --- a/lib/ansible/modules/network/f5/bigip_monitor_tcp_echo.py +++ b/lib/ansible/modules/network/f5/bigip_monitor_tcp_echo.py @@ -29,6 +29,10 @@ options: been set, it cannot be changed. By default, this value is the C(tcp_echo) parent on the C(Common) partition. default: /Common/tcp_echo + description: + description: + - The description of the monitor. + version_added: 2.7 ip: description: - IP address part of the IP/port definition. If this parameter is not @@ -77,6 +81,7 @@ notes: extends_documentation_fragment: f5 author: - Tim Rupp (@caphrim007) + - Wojciech Wypior (@wojtek0806) ''' EXAMPLES = r''' @@ -111,6 +116,11 @@ ip: returned: changed type: string sample: 10.12.13.14 +description: + description: The description of the monitor. + returned: changed + type: str + sample: Important Monitor interval: description: The new interval in which to run the monitor check. returned: changed @@ -140,6 +150,7 @@ try: from library.module_utils.network.f5.common import AnsibleF5Parameters from library.module_utils.network.f5.common import cleanup_tokens from library.module_utils.network.f5.common import f5_argument_spec + from library.module_utils.network.f5.ipaddress import is_valid_ip try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -151,17 +162,12 @@ except ImportError: from ansible.module_utils.network.f5.common import AnsibleF5Parameters from ansible.module_utils.network.f5.common import cleanup_tokens from ansible.module_utils.network.f5.common import f5_argument_spec + from ansible.module_utils.network.f5.ipaddress import is_valid_ip try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: HAS_F5SDK = False -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False - class Parameters(AnsibleF5Parameters): api_map = { @@ -170,15 +176,16 @@ class Parameters(AnsibleF5Parameters): } api_attributes = [ - 'timeUntilUp', 'defaultsFrom', 'interval', 'timeout', 'destination' + 'timeUntilUp', 'defaultsFrom', 'interval', 'timeout', 'destination', + 'description' ] returnables = [ - 'parent', 'ip', 'interval', 'timeout', 'time_until_up' + 'parent', 'ip', 'interval', 'timeout', 'time_until_up', 'description' ] updatables = [ - 'ip', 'interval', 'timeout', 'time_until_up' + 'ip', 'interval', 'timeout', 'time_until_up', 'description' ] def to_return(self): @@ -211,12 +218,11 @@ class Parameters(AnsibleF5Parameters): def ip(self): if self._values['ip'] is None: return None - try: - if self._values['ip'] in ['*', '0.0.0.0']: - return '*' - result = str(netaddr.IPAddress(self._values['ip'])) - return result - except netaddr.core.AddrFormatError: + if self._values['ip'] in ['*', '0.0.0.0']: + return '*' + elif is_valid_ip(self._values['ip']): + return self._values['ip'] + else: raise F5ModuleError( "The provided 'ip' parameter is not an IP address." ) @@ -469,6 +475,7 @@ class ArgumentSpec(object): argument_spec = dict( name=dict(required=True), parent=dict(default='/Common/tcp_echo'), + description=dict(), ip=dict(), interval=dict(type='int'), timeout=dict(type='int'), @@ -496,8 +503,6 @@ def main(): ) if not HAS_F5SDK: module.fail_json(msg="The python f5-sdk module is required") - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: client = F5Client(**module.params) diff --git a/lib/ansible/modules/network/f5/bigip_monitor_tcp_half_open.py b/lib/ansible/modules/network/f5/bigip_monitor_tcp_half_open.py index 8e3fc172967..9c7bfbd5639 100644 --- a/lib/ansible/modules/network/f5/bigip_monitor_tcp_half_open.py +++ b/lib/ansible/modules/network/f5/bigip_monitor_tcp_half_open.py @@ -28,7 +28,11 @@ options: - The parent template of this monitor template. Once this value has been set, it cannot be changed. By default, this value is the C(tcp_half_open) parent on the C(Common) partition. - default: "/Common/tcp_half_open" + default: /Common/tcp_half_open + description: + description: + - The description of the monitor. + version_added: 2.7 ip: description: - IP address part of the IP/port definition. If this parameter is not @@ -84,6 +88,7 @@ notes: extends_documentation_fragment: f5 author: - Tim Rupp (@caphrim007) + - Wojciech Wypior (@wojtek0806) ''' EXAMPLES = r''' @@ -122,6 +127,11 @@ parent: returned: changed type: string sample: tcp +description: + description: The description of the monitor. + returned: changed + type: str + sample: Important Monitor ip: description: The new IP of IP/port definition. returned: changed @@ -156,6 +166,7 @@ try: from library.module_utils.network.f5.common import AnsibleF5Parameters from library.module_utils.network.f5.common import cleanup_tokens from library.module_utils.network.f5.common import f5_argument_spec + from library.module_utils.network.f5.ipaddress import is_valid_ip try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -167,17 +178,12 @@ except ImportError: from ansible.module_utils.network.f5.common import AnsibleF5Parameters from ansible.module_utils.network.f5.common import cleanup_tokens from ansible.module_utils.network.f5.common import f5_argument_spec + from ansible.module_utils.network.f5.ipaddress import is_valid_ip try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: HAS_F5SDK = False -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False - class Parameters(AnsibleF5Parameters): api_map = { @@ -187,15 +193,17 @@ class Parameters(AnsibleF5Parameters): } api_attributes = [ - 'timeUntilUp', 'defaultsFrom', 'interval', 'timeout', 'destination' + 'timeUntilUp', 'defaultsFrom', 'interval', 'timeout', 'destination', + 'description' ] returnables = [ - 'parent', 'ip', 'port', 'interval', 'timeout', 'time_until_up' + 'parent', 'ip', 'port', 'interval', 'timeout', 'time_until_up', + 'description' ] updatables = [ - 'destination', 'interval', 'timeout', 'time_until_up' + 'destination', 'interval', 'timeout', 'time_until_up', 'description' ] def to_return(self): @@ -244,15 +252,13 @@ class Parameters(AnsibleF5Parameters): def ip(self): if self._values['ip'] is None: return None - try: - if self._values['ip'] in ['*', '0.0.0.0']: - return '*' - result = str(netaddr.IPAddress(self._values['ip'])) - return result - except netaddr.core.AddrFormatError: - raise F5ModuleError( - "The provided 'ip' parameter is not an IP address." - ) + elif self._values['ip'] in ['*', '0.0.0.0']: + return '*' + elif is_valid_ip(self._values['ip']): + return self._values['ip'] + raise F5ModuleError( + "The provided 'ip' parameter is not an IP address." + ) @property def port(self): @@ -514,6 +520,7 @@ class ArgumentSpec(object): argument_spec = dict( name=dict(required=True), parent=dict(default='/Common/tcp_half_open'), + description=dict(), ip=dict(), port=dict(type='int'), interval=dict(type='int'), @@ -542,8 +549,6 @@ def main(): ) if not HAS_F5SDK: module.fail_json(msg="The python f5-sdk module is required") - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: client = F5Client(**module.params) diff --git a/lib/ansible/modules/network/f5/bigip_monitor_udp.py b/lib/ansible/modules/network/f5/bigip_monitor_udp.py index ff5a87ff183..6769dffb71e 100644 --- a/lib/ansible/modules/network/f5/bigip_monitor_udp.py +++ b/lib/ansible/modules/network/f5/bigip_monitor_udp.py @@ -28,7 +28,11 @@ options: - The parent template of this monitor template. Once this value has been set, it cannot be changed. By default, this value is the C(udp) parent on the C(Common) partition. - default: "/Common/udp" + default: /Common/udp + description: + description: + - The description of the monitor. + version_added: 2.7 send: description: - The send string for the monitor call. When creating a new monitor, if @@ -94,6 +98,7 @@ notes: extends_documentation_fragment: f5 author: - Tim Rupp (@caphrim007) + - Wojciech Wypior (@wojtek0806) ''' EXAMPLES = r''' @@ -123,6 +128,11 @@ parent: returned: changed type: string sample: http +description: + description: The description of the monitor. + returned: changed + type: str + sample: Important Monitor ip: description: The new IP of IP/port definition. returned: changed @@ -157,6 +167,7 @@ try: from library.module_utils.network.f5.common import AnsibleF5Parameters from library.module_utils.network.f5.common import cleanup_tokens from library.module_utils.network.f5.common import f5_argument_spec + from library.module_utils.network.f5.ipaddress import is_valid_ip try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -168,17 +179,12 @@ except ImportError: from ansible.module_utils.network.f5.common import AnsibleF5Parameters from ansible.module_utils.network.f5.common import cleanup_tokens from ansible.module_utils.network.f5.common import f5_argument_spec + from ansible.module_utils.network.f5.ipaddress import is_valid_ip try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: HAS_F5SDK = False -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False - class Parameters(AnsibleF5Parameters): api_map = { @@ -189,16 +195,17 @@ class Parameters(AnsibleF5Parameters): api_attributes = [ 'timeUntilUp', 'defaultsFrom', 'interval', 'timeout', 'recv', 'send', - 'destination' + 'destination', 'description' ] returnables = [ 'parent', 'send', 'receive', 'ip', 'port', 'interval', 'timeout', - 'time_until_up' + 'time_until_up', 'description' ] updatables = [ - 'destination', 'send', 'receive', 'interval', 'timeout', 'time_until_up' + 'destination', 'send', 'receive', 'interval', 'timeout', 'time_until_up', + 'description' ] def to_return(self): @@ -247,12 +254,11 @@ class Parameters(AnsibleF5Parameters): def ip(self): if self._values['ip'] is None: return None - try: - if self._values['ip'] in ['*', '0.0.0.0']: - return '*' - result = str(netaddr.IPAddress(self._values['ip'])) - return result - except netaddr.core.AddrFormatError: + if self._values['ip'] in ['*', '0.0.0.0']: + return '*' + elif is_valid_ip(self._values['ip']): + return self._values['ip'] + else: raise F5ModuleError( "The provided 'ip' parameter is not an IP address." ) @@ -518,6 +524,7 @@ class ArgumentSpec(object): argument_spec = dict( name=dict(required=True), parent=dict(default='/Common/udp'), + description=dict(), send=dict(), receive=dict(), receive_disable=dict(required=False), @@ -549,8 +556,6 @@ def main(): ) if not HAS_F5SDK: module.fail_json(msg="The python f5-sdk module is required") - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: client = F5Client(**module.params)