Various bigiq fixes (#44487)

Fixes usage of the RestClient class. Documentation fixes. Removal
of dependency code.
This commit is contained in:
Tim Rupp 2018-08-21 18:40:19 -04:00 committed by GitHub
parent d39a711aa1
commit 07a011cd6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 68 additions and 112 deletions

View file

@ -186,6 +186,7 @@ try:
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.ipaddress import is_valid_ip
except ImportError:
from ansible.module_utils.network.f5.bigiq import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
@ -193,12 +194,7 @@ except ImportError:
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
try:
import netaddr
HAS_NETADDR = True
except ImportError:
HAS_NETADDR = False
from ansible.module_utils.network.f5.ipaddress import is_valid_ip
class Parameters(AnsibleF5Parameters):
@ -275,11 +271,10 @@ class ModuleParameters(Parameters):
@property
def default_device_reference(self):
try:
if is_valid_ip(self.service_environment):
# An IP address was specified
netaddr.IPAddress(self.service_environment)
filter = "address+eq+'{0}'".format(self.service_environment)
except netaddr.core.AddrFormatError:
else:
# Assume a hostname was specified
filter = "hostname+eq+'{0}'".format(self.service_environment)
@ -731,11 +726,9 @@ def main():
argument_spec=spec.argument_spec,
supports_check_mode=spec.supports_check_mode
)
if not HAS_NETADDR:
module.fail_json(msg="The python netaddr module is required")
try:
client = F5RestClient(module=module)
client = F5RestClient(**module.params)
mm = ModuleManager(module=module, client=client)
results = mm.exec_module()
exit_json(module, results, client)

View file

@ -117,7 +117,7 @@ EXAMPLES = r'''
port: 8080
- address: 5.6.7.8
port: 8080
load_balancer:
inbound_virtual:
name: foo
destination: 2.2.2.2
netmask: 255.255.255.255
@ -174,6 +174,8 @@ servers:
sample: hash/dictionary of values
'''
import time
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import env_fallback
@ -184,6 +186,7 @@ try:
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.ipaddress import is_valid_ip
except ImportError:
from ansible.module_utils.network.f5.bigiq import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
@ -191,15 +194,7 @@ except ImportError:
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
try:
import netaddr
HAS_NETADDR = True
except ImportError:
HAS_NETADDR = False
import time
from ansible.module_utils.network.f5.ipaddress import is_valid_ip
class Parameters(AnsibleF5Parameters):
@ -274,11 +269,10 @@ class ModuleParameters(Parameters):
@property
def default_device_reference(self):
try:
if is_valid_ip(self.service_environment):
# An IP address was specified
netaddr.IPAddress(self.service_environment)
filter = "address+eq+'{0}'".format(self.service_environment)
except netaddr.core.AddrFormatError:
else:
# Assume a hostname was specified
filter = "hostname+eq+'{0}'".format(self.service_environment)
@ -338,7 +332,7 @@ class UsableChanges(Changes):
name='virtual',
destinationAddress=self.inbound_virtual['address'],
mask=self.inbound_virtual['netmask'],
destinationPort=self.inbound_virtual['port']
destinationPort=self.inbound_virtual.get('port', 8080)
),
subcollectionResources=self.profiles
)
@ -376,7 +370,7 @@ class UsableChanges(Changes):
for x in self.servers:
member = dict(
parameters=dict(
port=x['port'],
port=x.get('port', 8000),
nodeReference=dict(
link='#/resources/ltm:node:3e91bd30bbfb/{0}'.format(x['address']),
fullPath='# {0}'.format(x['address'])
@ -678,11 +672,9 @@ def main():
argument_spec=spec.argument_spec,
supports_check_mode=spec.supports_check_mode
)
if not HAS_NETADDR:
module.fail_json(msg="The python netaddr module is required")
try:
client = F5RestClient(module=module)
client = F5RestClient(**module.params)
mm = ModuleManager(module=module, client=client)
results = mm.exec_module()
exit_json(module, results, client)

View file

@ -117,7 +117,7 @@ EXAMPLES = r'''
port: 8080
- address: 5.6.7.8
port: 8080
load_balancer:
inbound_virtual:
name: foo
destination: 2.2.2.2
netmask: 255.255.255.255
@ -174,6 +174,8 @@ servers:
sample: hash/dictionary of values
'''
import time
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import env_fallback
@ -184,6 +186,7 @@ try:
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.ipaddress import is_valid_ip
except ImportError:
from ansible.module_utils.network.f5.bigiq import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
@ -191,15 +194,7 @@ except ImportError:
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
try:
import netaddr
HAS_NETADDR = True
except ImportError:
HAS_NETADDR = False
import time
from ansible.module_utils.network.f5.ipaddress import is_valid_ip
class Parameters(AnsibleF5Parameters):
@ -274,11 +269,10 @@ class ModuleParameters(Parameters):
@property
def default_device_reference(self):
try:
if is_valid_ip(self.service_environment):
# An IP address was specified
netaddr.IPAddress(self.service_environment)
filter = "address+eq+'{0}'".format(self.service_environment)
except netaddr.core.AddrFormatError:
else:
# Assume a hostname was specified
filter = "hostname+eq+'{0}'".format(self.service_environment)
@ -338,7 +332,7 @@ class UsableChanges(Changes):
name='virtual',
destinationAddress=self.inbound_virtual['address'],
mask=self.inbound_virtual['netmask'],
destinationPort=self.inbound_virtual['port']
destinationPort=self.inbound_virtual.get('port', 53)
),
subcollectionResources=self.profiles
)
@ -376,7 +370,7 @@ class UsableChanges(Changes):
for x in self.servers:
member = dict(
parameters=dict(
port=x['port'],
port=x.get('port', 8000),
nodeReference=dict(
link='#/resources/ltm:node:b19842fe713a/{0}'.format(x['address']),
fullPath='# {0}'.format(x['address'])
@ -678,11 +672,9 @@ def main():
argument_spec=spec.argument_spec,
supports_check_mode=spec.supports_check_mode
)
if not HAS_NETADDR:
module.fail_json(msg="The python netaddr module is required")
try:
client = F5RestClient(module=module)
client = F5RestClient(**module.params)
mm = ModuleManager(module=module, client=client)
results = mm.exec_module()
exit_json(module, results, client)

View file

@ -186,6 +186,7 @@ try:
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.ipaddress import is_valid_ip
except ImportError:
from ansible.module_utils.network.f5.bigiq import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
@ -193,12 +194,7 @@ except ImportError:
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
try:
import netaddr
HAS_NETADDR = True
except ImportError:
HAS_NETADDR = False
from ansible.module_utils.network.f5.ipaddress import is_valid_ip
class Parameters(AnsibleF5Parameters):
@ -275,11 +271,9 @@ class ModuleParameters(Parameters):
@property
def default_device_reference(self):
try:
# An IP address was specified
netaddr.IPAddress(self.service_environment)
if is_valid_ip(self.service_environment):
filter = "address+eq+'{0}'".format(self.service_environment)
except netaddr.core.AddrFormatError:
else:
# Assume a hostname was specified
filter = "hostname+eq+'{0}'".format(self.service_environment)
@ -363,7 +357,7 @@ class UsableChanges(Changes):
name='virtual',
destinationAddress=self.inbound_virtual['address'],
mask=self.inbound_virtual['netmask'],
destinationPort=self.inbound_virtual['port']
destinationPort=self.inbound_virtual.get('port', 80)
),
subcollectionResources=self.profiles
)
@ -406,7 +400,7 @@ class UsableChanges(Changes):
for x in self.servers:
member = dict(
parameters=dict(
port=x['port'],
port=x.get('port', 80),
nodeReference=dict(
link='#/resources/ltm:node:9e76a6323321/{0}'.format(x['address']),
fullPath='# {0}'.format(x['address'])
@ -731,11 +725,9 @@ def main():
argument_spec=spec.argument_spec,
supports_check_mode=spec.supports_check_mode
)
if not HAS_NETADDR:
module.fail_json(msg="The python netaddr module is required")
try:
client = F5RestClient(module=module)
client = F5RestClient(**module.params)
mm = ModuleManager(module=module, client=client)
results = mm.exec_module()
exit_json(module, results, client)

View file

@ -107,8 +107,7 @@ options:
per profile.
- If you attempt to assign two RSA, DSA, or ECDSA certificate/key combo,
the device will reject this.
- This list is a complex list that specifies a number of keys. There are
several supported keys.
- This list is a complex list that specifies a number of keys.
- When creating a new profile, if this parameter is not specified, the
default value of C(inherit) will be used.
suboptions:
@ -245,6 +244,7 @@ try:
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.common import fq_name
from library.module_utils.network.f5.ipaddress import is_valid_ip
except ImportError:
from ansible.module_utils.network.f5.bigiq import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
@ -253,12 +253,7 @@ except ImportError:
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
from ansible.module_utils.network.f5.common import fq_name
try:
import netaddr
HAS_NETADDR = True
except ImportError:
HAS_NETADDR = False
from ansible.module_utils.network.f5.ipaddress import is_valid_ip
class Parameters(AnsibleF5Parameters):
@ -335,11 +330,10 @@ class ModuleParameters(Parameters):
@property
def default_device_reference(self):
try:
if is_valid_ip(self.service_environment):
# An IP address was specified
netaddr.IPAddress(self.service_environment)
filter = "address+eq+'{0}'".format(self.service_environment)
except netaddr.core.AddrFormatError:
else:
# Assume a hostname was specified
filter = "hostname+eq+'{0}'".format(self.service_environment)
@ -974,11 +968,9 @@ def main():
argument_spec=spec.argument_spec,
supports_check_mode=spec.supports_check_mode
)
if not HAS_NETADDR:
module.fail_json(msg="The python netaddr module is required")
try:
client = F5RestClient(module=module)
client = F5RestClient(**module.params)
mm = ModuleManager(module=module, client=client)
results = mm.exec_module()
exit_json(module, results, client)

View file

@ -107,8 +107,7 @@ options:
per profile.
- If you attempt to assign two RSA, DSA, or ECDSA certificate/key combo,
the device will reject this.
- This list is a complex list that specifies a number of keys. There are
several supported keys.
- This list is a complex list that specifies a number of keys.
- When creating a new profile, if this parameter is not specified, the
default value of C(inherit) will be used.
suboptions:
@ -250,6 +249,7 @@ try:
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.common import fq_name
from library.module_utils.network.f5.ipaddress import is_valid_ip
except ImportError:
from ansible.module_utils.network.f5.bigiq import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
@ -258,12 +258,7 @@ except ImportError:
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
from ansible.module_utils.network.f5.common import fq_name
try:
import netaddr
HAS_NETADDR = True
except ImportError:
HAS_NETADDR = False
from ansible.module_utils.network.f5.ipaddress import is_valid_ip
class Parameters(AnsibleF5Parameters):
@ -341,11 +336,10 @@ class ModuleParameters(Parameters):
@property
def default_device_reference(self):
try:
if is_valid_ip(self.service_environment):
# An IP address was specified
netaddr.IPAddress(self.service_environment)
filter = "address+eq+'{0}'".format(self.service_environment)
except netaddr.core.AddrFormatError:
else:
# Assume a hostname was specified
filter = "hostname+eq+'{0}'".format(self.service_environment)
@ -999,11 +993,9 @@ def main():
argument_spec=spec.argument_spec,
supports_check_mode=spec.supports_check_mode
)
if not HAS_NETADDR:
module.fail_json(msg="The python netaddr module is required")
try:
client = F5RestClient(module=module)
client = F5RestClient(**module.params)
mm = ModuleManager(module=module, client=client)
results = mm.exec_module()
exit_json(module, results, client)

View file

@ -15,7 +15,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
DOCUMENTATION = r'''
---
module: bigiq_regkey_license_assignment
short_description: Manage regkey license assignment on BIG-IPs from a BIG-IQ.
short_description: Manage regkey license assignment on BIG-IPs from a BIG-IQ
description:
- Manages the assignment of regkey licenses on a BIG-IQ. Assignment means that
the license is assigned to a BIG-IP, or, it needs to be assigned to a BIG-IP.
@ -89,7 +89,7 @@ EXAMPLES = r'''
user: admin
delegate_to: localhost
- name: Register an managed device, by name
- name: Register a managed device, by name
bigiq_regkey_license_assignment:
pool: my-regkey-pool
key: XXXX-XXXX-XXXX-XXXX-XXXX
@ -101,7 +101,7 @@ EXAMPLES = r'''
user: admin
delegate_to: localhost
- name: Register an managed device, by UUID
- name: Register a managed device, by UUID
bigiq_regkey_license_assignment:
pool: my-regkey-pool
key: XXXX-XXXX-XXXX-XXXX-XXXX
@ -119,6 +119,7 @@ RETURN = r'''
'''
import re
import time
from ansible.module_utils.basic import AnsibleModule
@ -129,6 +130,7 @@ try:
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.ipaddress import is_valid_ip
except ImportError:
from ansible.module_utils.network.f5.bigiq import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
@ -136,11 +138,7 @@ except ImportError:
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
try:
import netaddr
HAS_NETADDR = True
except ImportError:
HAS_NETADDR = False
from ansible.module_utils.network.f5.ipaddress import is_valid_ip
class Parameters(AnsibleF5Parameters):
@ -205,11 +203,9 @@ class ModuleParameters(Parameters):
@property
def device_is_address(self):
try:
netaddr.IPAddress(self.device)
if is_valid_ip(self.device):
return True
except (ValueError, netaddr.core.AddrFormatError):
return False
return False
@property
def device_is_id(self):
@ -484,6 +480,10 @@ class ModuleManager(object):
self.remove_from_device()
if self.exists():
raise F5ModuleError("Failed to delete the resource.")
# Artificial sleeping to wait for remote licensing (on BIG-IP) to complete
#
# This should be something that BIG-IQ can do natively in 6.1-ish time.
time.sleep(60)
return True
def create(self):
@ -505,6 +505,11 @@ class ModuleManager(object):
"Failed to license the remote device."
)
self.wait_for_device_to_be_licensed()
# Artificial sleeping to wait for remote licensing (on BIG-IP) to complete
#
# This should be something that BIG-IQ can do natively in 6.1-ish time.
time.sleep(60)
return True
def create_on_device(self):
@ -530,7 +535,7 @@ class ModuleManager(object):
if 'message' in response:
raise F5ModuleError(response['message'])
else:
raise F5ModuleError(resp._content)
raise F5ModuleError(resp.content)
def wait_for_device_to_be_licensed(self):
count = 0
@ -552,7 +557,7 @@ class ModuleManager(object):
if 'message' in response:
raise F5ModuleError(response['message'])
else:
raise F5ModuleError(resp._content)
raise F5ModuleError(resp.content)
if response['status'] == 'LICENSED':
count += 1
else:
@ -611,11 +616,9 @@ def main():
supports_check_mode=spec.supports_check_mode,
required_if=spec.required_if
)
if not HAS_NETADDR:
module.fail_json(msg="The python netaddr module is required")
try:
client = F5RestClient(module=module)
client = F5RestClient(**module.params)
mm = ModuleManager(module=module, client=client)
results = mm.exec_module()
exit_json(module, results, client)

View file

@ -449,7 +449,7 @@ def main():
)
try:
client = F5RestClient(module=module)
client = F5RestClient(**module.params)
mm = ModuleManager(module=module, client=client)
results = mm.exec_module()
exit_json(module, results, client)

View file

@ -100,7 +100,7 @@ class TestManager(unittest.TestCase):
license_key='XXXX-XXXX-XXXX-XXXX-XXXX',
accept_eula=True,
description='this is a description',
password='passsword',
password='password',
server='localhost',
user='admin'
))

View file

@ -112,7 +112,7 @@ class TestManager(unittest.TestCase):
device_password='secret',
managed='no',
state='present',
password='passsword',
password='password',
server='localhost',
user='admin'
))

View file

@ -86,7 +86,7 @@ class TestManager(unittest.TestCase):
set_module_args(dict(
license_key='XXXX-XXXX-XXXX-XXXX-XXXX',
accept_eula=True,
password='passsword',
password='password',
server='localhost',
user='admin'
))