|
|
|
@ -637,35 +637,31 @@ from ansible.module_utils.six import iteritems
|
|
|
|
|
from collections import namedtuple
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
from library.module_utils.network.f5.bigip import HAS_F5SDK
|
|
|
|
|
from library.module_utils.network.f5.bigip import F5Client
|
|
|
|
|
from library.module_utils.network.f5.bigip import F5RestClient
|
|
|
|
|
from library.module_utils.network.f5.common import F5ModuleError
|
|
|
|
|
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 fq_name
|
|
|
|
|
from library.module_utils.network.f5.common import f5_argument_spec
|
|
|
|
|
from library.module_utils.network.f5.common import fail_json
|
|
|
|
|
from library.module_utils.network.f5.common import exit_json
|
|
|
|
|
from library.module_utils.network.f5.common import transform_name
|
|
|
|
|
from library.module_utils.network.f5.ipaddress import is_valid_ip
|
|
|
|
|
from library.module_utils.network.f5.ipaddress import ip_interface
|
|
|
|
|
from library.module_utils.network.f5.ipaddress import validate_ip_v6_address
|
|
|
|
|
try:
|
|
|
|
|
from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
|
|
|
|
except ImportError:
|
|
|
|
|
HAS_F5SDK = False
|
|
|
|
|
except ImportError:
|
|
|
|
|
from ansible.module_utils.network.f5.bigip import HAS_F5SDK
|
|
|
|
|
from ansible.module_utils.network.f5.bigip import F5Client
|
|
|
|
|
from ansible.module_utils.network.f5.bigip import F5RestClient
|
|
|
|
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
|
|
|
|
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 fq_name
|
|
|
|
|
from ansible.module_utils.network.f5.common import f5_argument_spec
|
|
|
|
|
from ansible.module_utils.network.f5.common import fail_json
|
|
|
|
|
from ansible.module_utils.network.f5.common import exit_json
|
|
|
|
|
from ansible.module_utils.network.f5.common import transform_name
|
|
|
|
|
from ansible.module_utils.network.f5.ipaddress import is_valid_ip
|
|
|
|
|
from ansible.module_utils.network.f5.ipaddress import ip_interface
|
|
|
|
|
from ansible.module_utils.network.f5.ipaddress import validate_ip_v6_address
|
|
|
|
|
try:
|
|
|
|
|
from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
|
|
|
|
except ImportError:
|
|
|
|
|
HAS_F5SDK = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Parameters(AnsibleF5Parameters):
|
|
|
|
@ -913,20 +909,85 @@ class Parameters(AnsibleF5Parameters):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def _read_current_message_routing_profiles_from_device(self):
|
|
|
|
|
collection1 = self.client.api.tm.ltm.profile.diameters.get_collection()
|
|
|
|
|
collection2 = self.client.api.tm.ltm.profile.sips.get_collection()
|
|
|
|
|
result = [x.name for x in collection1]
|
|
|
|
|
result += [x.name for x in collection2]
|
|
|
|
|
result = []
|
|
|
|
|
result += self._read_diameter_profiles_from_device()
|
|
|
|
|
result += self._read_sip_profiles_from_device()
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def _read_diameter_profiles_from_device(self):
|
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/ltm/profile/diameter/".format(
|
|
|
|
|
self.client.provider['server'],
|
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
|
)
|
|
|
|
|
resp = self.client.api.get(uri)
|
|
|
|
|
try:
|
|
|
|
|
response = resp.json()
|
|
|
|
|
except ValueError as ex:
|
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
|
|
if 'code' in response and response['code'] == 400:
|
|
|
|
|
if 'message' in response:
|
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
|
else:
|
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
|
result = [x['name'] for x in response['items']]
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def _read_sip_profiles_from_device(self):
|
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/ltm/profile/sip/".format(
|
|
|
|
|
self.client.provider['server'],
|
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
|
)
|
|
|
|
|
resp = self.client.api.get(uri)
|
|
|
|
|
try:
|
|
|
|
|
response = resp.json()
|
|
|
|
|
except ValueError as ex:
|
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
|
|
if 'code' in response and response['code'] == 400:
|
|
|
|
|
if 'message' in response:
|
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
|
else:
|
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
|
result = [x['name'] for x in response['items']]
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def _read_current_fastl4_profiles_from_device(self):
|
|
|
|
|
collection = self.client.api.tm.ltm.profile.fastl4s.get_collection()
|
|
|
|
|
result = [x.name for x in collection]
|
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/ltm/profile/fastl4/".format(
|
|
|
|
|
self.client.provider['server'],
|
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
|
)
|
|
|
|
|
resp = self.client.api.get(uri)
|
|
|
|
|
try:
|
|
|
|
|
response = resp.json()
|
|
|
|
|
except ValueError as ex:
|
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
|
|
if 'code' in response and response['code'] == 400:
|
|
|
|
|
if 'message' in response:
|
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
|
else:
|
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
|
result = [x['name'] for x in response['items']]
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def _read_current_fasthttp_profiles_from_device(self):
|
|
|
|
|
collection = self.client.api.tm.ltm.profile.fasthttps.get_collection()
|
|
|
|
|
result = [x.name for x in collection]
|
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/ltm/profile/fasthttp/".format(
|
|
|
|
|
self.client.provider['server'],
|
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
|
)
|
|
|
|
|
resp = self.client.api.get(uri)
|
|
|
|
|
try:
|
|
|
|
|
response = resp.json()
|
|
|
|
|
except ValueError as ex:
|
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
|
|
if 'code' in response and response['code'] == 400:
|
|
|
|
|
if 'message' in response:
|
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
|
else:
|
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
|
result = [x['name'] for x in response['items']]
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1246,6 +1307,12 @@ class ApiParameters(Parameters):
|
|
|
|
|
return None
|
|
|
|
|
return self._values['security_nat_policy']['policy']
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def irules(self):
|
|
|
|
|
if self._values['irules'] is None:
|
|
|
|
|
return []
|
|
|
|
|
return self._values['irules']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ModuleParameters(Parameters):
|
|
|
|
|
services_map = {
|
|
|
|
@ -2268,25 +2335,104 @@ class VirtualServerValidator(object):
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def read_dhcp_profiles_from_device(self):
|
|
|
|
|
collection = self.client.api.tm.ltm.profile.dhcpv4s.get_collection()
|
|
|
|
|
result = [fq_name(self.want.partition, x.name) for x in collection]
|
|
|
|
|
collection = self.client.api.tm.ltm.profile.dhcpv6s.get_collection()
|
|
|
|
|
result += [fq_name(self.want.partition, x.name) for x in collection]
|
|
|
|
|
result = []
|
|
|
|
|
result += self.read_dhcpv4_profiles_from_device()
|
|
|
|
|
result += self.read_dhcpv6_profiles_from_device()
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def read_dhcpv4_profiles_from_device(self):
|
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/ltm/profile/dhcpv4/".format(
|
|
|
|
|
self.client.provider['server'],
|
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
|
)
|
|
|
|
|
resp = self.client.api.get(uri)
|
|
|
|
|
try:
|
|
|
|
|
response = resp.json()
|
|
|
|
|
except ValueError as ex:
|
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
|
|
if 'code' in response and response['code'] == 400:
|
|
|
|
|
if 'message' in response:
|
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
|
else:
|
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
|
result = [fq_name(self.want.partition, x['name']) for x in response['items']]
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def read_dhcpv6_profiles_from_device(self):
|
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/ltm/profile/dhcpv6/".format(
|
|
|
|
|
self.client.provider['server'],
|
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
|
)
|
|
|
|
|
resp = self.client.api.get(uri)
|
|
|
|
|
try:
|
|
|
|
|
response = resp.json()
|
|
|
|
|
except ValueError as ex:
|
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
|
|
if 'code' in response and response['code'] == 400:
|
|
|
|
|
if 'message' in response:
|
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
|
else:
|
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
|
result = [fq_name(self.want.partition, x['name']) for x in response['items']]
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def read_fastl4_profiles_from_device(self):
|
|
|
|
|
collection = self.client.api.tm.ltm.profile.fastl4s.get_collection()
|
|
|
|
|
result = [fq_name(self.want.partition, x.name) for x in collection]
|
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/ltm/profile/fastl4/".format(
|
|
|
|
|
self.client.provider['server'],
|
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
|
)
|
|
|
|
|
resp = self.client.api.get(uri)
|
|
|
|
|
try:
|
|
|
|
|
response = resp.json()
|
|
|
|
|
except ValueError as ex:
|
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
|
|
if 'code' in response and response['code'] == 400:
|
|
|
|
|
if 'message' in response:
|
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
|
else:
|
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
|
result = [fq_name(self.want.partition, x['name']) for x in response['items']]
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def read_fasthttp_profiles_from_device(self):
|
|
|
|
|
collection = self.client.api.tm.ltm.profile.fasthttps.get_collection()
|
|
|
|
|
result = [fq_name(self.want.partition, x.name) for x in collection]
|
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/ltm/profile/fasthttp/".format(
|
|
|
|
|
self.client.provider['server'],
|
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
|
)
|
|
|
|
|
resp = self.client.api.get(uri)
|
|
|
|
|
try:
|
|
|
|
|
response = resp.json()
|
|
|
|
|
except ValueError as ex:
|
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
|
|
if 'code' in response and response['code'] == 400:
|
|
|
|
|
if 'message' in response:
|
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
|
else:
|
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
|
result = [fq_name(self.want.partition, x['name']) for x in response['items']]
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def read_udp_profiles_from_device(self):
|
|
|
|
|
collection = self.client.api.tm.ltm.profile.udps.get_collection()
|
|
|
|
|
result = [fq_name(self.want.partition, x.name) for x in collection]
|
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/ltm/profile/udp/".format(
|
|
|
|
|
self.client.provider['server'],
|
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
|
)
|
|
|
|
|
resp = self.client.api.get(uri)
|
|
|
|
|
try:
|
|
|
|
|
response = resp.json()
|
|
|
|
|
except ValueError as ex:
|
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
|
|
if 'code' in response and response['code'] == 400:
|
|
|
|
|
if 'message' in response:
|
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
|
else:
|
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
|
result = [fq_name(self.want.partition, x['name']) for x in response['items']]
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -2637,13 +2783,10 @@ class ModuleManager(object):
|
|
|
|
|
result = dict()
|
|
|
|
|
state = self.want.state
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
if state in ['present', 'enabled', 'disabled']:
|
|
|
|
|
changed = self.present()
|
|
|
|
|
elif state == "absent":
|
|
|
|
|
changed = self.absent()
|
|
|
|
|
except iControlUnexpectedHTTPError as e:
|
|
|
|
|
raise F5ModuleError(str(e))
|
|
|
|
|
|
|
|
|
|
reportable = ReportableChanges(params=self.changes.to_return())
|
|
|
|
|
changes = reportable.to_return()
|
|
|
|
@ -2664,7 +2807,9 @@ class ModuleManager(object):
|
|
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
|
self.have = self.read_current_from_device()
|
|
|
|
|
validator = VirtualServerValidator(module=self.module, client=self.client, have=self.have, want=self.want)
|
|
|
|
|
validator = VirtualServerValidator(
|
|
|
|
|
module=self.module, client=self.client, have=self.have, want=self.want
|
|
|
|
|
)
|
|
|
|
|
validator.check_update()
|
|
|
|
|
|
|
|
|
|
if not self.should_update():
|
|
|
|
@ -2719,14 +2864,24 @@ class ModuleManager(object):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def exists(self):
|
|
|
|
|
result = self.client.api.tm.ltm.virtuals.virtual.exists(
|
|
|
|
|
name=self.want.name,
|
|
|
|
|
partition=self.want.partition
|
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/ltm/virtual/{2}".format(
|
|
|
|
|
self.client.provider['server'],
|
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
|
transform_name(self.want.partition, self.want.name)
|
|
|
|
|
)
|
|
|
|
|
return result
|
|
|
|
|
resp = self.client.api.get(uri)
|
|
|
|
|
try:
|
|
|
|
|
response = resp.json()
|
|
|
|
|
except ValueError:
|
|
|
|
|
return False
|
|
|
|
|
if resp.status == 404 or 'code' in response and response['code'] == 404:
|
|
|
|
|
return False
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def create(self):
|
|
|
|
|
validator = VirtualServerValidator(module=self.module, client=self.client, have=self.have, want=self.want)
|
|
|
|
|
validator = VirtualServerValidator(
|
|
|
|
|
module=self.module, client=self.client, have=self.have, want=self.want
|
|
|
|
|
)
|
|
|
|
|
validator.check_create()
|
|
|
|
|
|
|
|
|
|
self._set_changed_options()
|
|
|
|
@ -2737,42 +2892,73 @@ class ModuleManager(object):
|
|
|
|
|
|
|
|
|
|
def update_on_device(self):
|
|
|
|
|
params = self.changes.api_params()
|
|
|
|
|
resource = self.client.api.tm.ltm.virtuals.virtual.load(
|
|
|
|
|
name=self.want.name,
|
|
|
|
|
partition=self.want.partition
|
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/ltm/virtual/{2}".format(
|
|
|
|
|
self.client.provider['server'],
|
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
|
transform_name(self.want.partition, self.want.name)
|
|
|
|
|
)
|
|
|
|
|
resource.modify(**params)
|
|
|
|
|
resp = self.client.api.patch(uri, json=params)
|
|
|
|
|
try:
|
|
|
|
|
response = resp.json()
|
|
|
|
|
except ValueError as ex:
|
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
|
|
if 'code' in response and response['code'] == 400:
|
|
|
|
|
if 'message' in response:
|
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
|
else:
|
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
|
|
|
|
|
|
def read_current_from_device(self):
|
|
|
|
|
result = self.client.api.tm.ltm.virtuals.virtual.load(
|
|
|
|
|
name=self.want.name,
|
|
|
|
|
partition=self.want.partition,
|
|
|
|
|
requests_params=dict(
|
|
|
|
|
params=dict(
|
|
|
|
|
expandSubcollections='true'
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/ltm/virtual/{2}?expandSubcollections=true".format(
|
|
|
|
|
self.client.provider['server'],
|
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
|
transform_name(self.want.partition, self.want.name)
|
|
|
|
|
)
|
|
|
|
|
params = result.attrs
|
|
|
|
|
params.update(dict(kind=result.to_dict().get('kind', None)))
|
|
|
|
|
result = ApiParameters(params=params, client=self.client)
|
|
|
|
|
return result
|
|
|
|
|
resp = self.client.api.get(uri)
|
|
|
|
|
try:
|
|
|
|
|
response = resp.json()
|
|
|
|
|
except ValueError as ex:
|
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
|
|
if 'code' in response and response['code'] == 400:
|
|
|
|
|
if 'message' in response:
|
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
|
else:
|
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
|
|
|
|
|
|
return ApiParameters(params=response, client=self.client)
|
|
|
|
|
|
|
|
|
|
def create_on_device(self):
|
|
|
|
|
params = self.changes.api_params()
|
|
|
|
|
self.client.api.tm.ltm.virtuals.virtual.create(
|
|
|
|
|
name=self.want.name,
|
|
|
|
|
partition=self.want.partition,
|
|
|
|
|
**params
|
|
|
|
|
params['name'] = self.want.name
|
|
|
|
|
params['partition'] = self.want.partition
|
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/ltm/virtual/".format(
|
|
|
|
|
self.client.provider['server'],
|
|
|
|
|
self.client.provider['server_port']
|
|
|
|
|
)
|
|
|
|
|
resp = self.client.api.post(uri, json=params)
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
def remove_from_device(self):
|
|
|
|
|
resource = self.client.api.tm.ltm.virtuals.virtual.load(
|
|
|
|
|
name=self.want.name,
|
|
|
|
|
partition=self.want.partition
|
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/ltm/virtual/{2}".format(
|
|
|
|
|
self.client.provider['server'],
|
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
|
transform_name(self.want.partition, self.want.name)
|
|
|
|
|
)
|
|
|
|
|
if resource:
|
|
|
|
|
resource.delete()
|
|
|
|
|
response = self.client.api.delete(uri)
|
|
|
|
|
if response.status == 200:
|
|
|
|
|
return True
|
|
|
|
|
raise F5ModuleError(response.content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ArgumentSpec(object):
|
|
|
|
@ -2868,18 +3054,16 @@ def main():
|
|
|
|
|
supports_check_mode=spec.supports_check_mode,
|
|
|
|
|
mutually_exclusive=spec.mutually_exclusive
|
|
|
|
|
)
|
|
|
|
|
if not HAS_F5SDK:
|
|
|
|
|
module.fail_json(msg="The python f5-sdk module is required")
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
client = F5Client(**module.params)
|
|
|
|
|
client = F5RestClient(**module.params)
|
|
|
|
|
mm = ModuleManager(module=module, client=client)
|
|
|
|
|
results = mm.exec_module()
|
|
|
|
|
exit_json(module, results, client)
|
|
|
|
|
cleanup_tokens(client)
|
|
|
|
|
module.exit_json(**results)
|
|
|
|
|
except F5ModuleError as ex:
|
|
|
|
|
cleanup_tokens(client)
|
|
|
|
|
module.fail_json(msg=str(ex))
|
|
|
|
|
fail_json(module, ex, client)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|