2016-08-19 20:07:38 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2017-12-03 06:10:04 +00:00
|
|
|
# Copyright (c) 2016 F5 Networks Inc.
|
2017-10-04 19:16:17 +00:00
|
|
|
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
2016-08-19 20:07:38 +00:00
|
|
|
|
2017-12-03 06:10:04 +00:00
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
|
2017-08-16 03:16:38 +00:00
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
2017-03-14 16:07:22 +00:00
|
|
|
'status': ['preview'],
|
|
|
|
'supported_by': 'community'}
|
|
|
|
|
2017-12-03 06:10:04 +00:00
|
|
|
DOCUMENTATION = r'''
|
2016-08-19 20:07:38 +00:00
|
|
|
---
|
|
|
|
module: bigip_routedomain
|
|
|
|
short_description: Manage route domains on a BIG-IP
|
|
|
|
description:
|
2017-12-03 06:10:04 +00:00
|
|
|
- Manage route domains on a BIG-IP.
|
2018-04-25 02:49:52 +00:00
|
|
|
version_added: 2.2
|
2016-08-19 20:07:38 +00:00
|
|
|
options:
|
2017-12-03 06:10:04 +00:00
|
|
|
name:
|
|
|
|
description:
|
|
|
|
- The name of the route domain.
|
|
|
|
version_added: 2.5
|
2016-08-19 20:07:38 +00:00
|
|
|
bwc_policy:
|
|
|
|
description:
|
|
|
|
- The bandwidth controller for the route domain.
|
|
|
|
connection_limit:
|
|
|
|
description:
|
|
|
|
- The maximum number of concurrent connections allowed for the
|
|
|
|
route domain. Setting this to C(0) turns off connection limits.
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Specifies descriptive text that identifies the route domain.
|
|
|
|
flow_eviction_policy:
|
|
|
|
description:
|
|
|
|
- The eviction policy to use with this route domain. Apply an eviction
|
|
|
|
policy to provide customized responses to flow overflows and slow
|
|
|
|
flows on the route domain.
|
|
|
|
id:
|
|
|
|
description:
|
|
|
|
- The unique identifying integer representing the route domain.
|
2017-12-03 06:10:04 +00:00
|
|
|
- This field is required when creating a new route domain.
|
|
|
|
- In version 2.5, this value is no longer used to reference a route domain when
|
|
|
|
making modifications to it (for instance during update and delete operations).
|
|
|
|
Instead, the C(name) parameter is used. In version 2.6, the C(name) value will
|
|
|
|
become a required parameter.
|
2016-08-19 20:07:38 +00:00
|
|
|
parent:
|
2016-10-12 18:49:12 +00:00
|
|
|
description:
|
2018-04-25 02:49:52 +00:00
|
|
|
- Specifies the route domain the system searches when it cannot
|
|
|
|
find a route in the configured domain.
|
2017-12-03 06:10:04 +00:00
|
|
|
partition:
|
|
|
|
description:
|
|
|
|
- Partition to create the route domain on. Partitions cannot be updated
|
|
|
|
once they are created.
|
|
|
|
default: Common
|
|
|
|
version_added: 2.5
|
2016-08-19 20:07:38 +00:00
|
|
|
routing_protocol:
|
|
|
|
description:
|
2016-10-12 18:49:12 +00:00
|
|
|
- Dynamic routing protocols for the system to use in the route domain.
|
2016-08-19 20:07:38 +00:00
|
|
|
choices:
|
|
|
|
- BFD
|
|
|
|
- BGP
|
|
|
|
- IS-IS
|
|
|
|
- OSPFv2
|
|
|
|
- OSPFv3
|
|
|
|
- PIM
|
|
|
|
- RIP
|
|
|
|
- RIPng
|
|
|
|
service_policy:
|
|
|
|
description:
|
|
|
|
- Service policy to associate with the route domain.
|
|
|
|
state:
|
|
|
|
description:
|
|
|
|
- Whether the route domain should exist or not.
|
|
|
|
default: present
|
|
|
|
choices:
|
|
|
|
- present
|
|
|
|
- absent
|
|
|
|
strict:
|
|
|
|
description:
|
2018-04-25 02:49:52 +00:00
|
|
|
- Specifies whether the system enforces cross-routing restrictions or not.
|
|
|
|
type: bool
|
2016-08-19 20:07:38 +00:00
|
|
|
vlans:
|
|
|
|
description:
|
2018-04-25 02:49:52 +00:00
|
|
|
- VLANs for the system to use in the route domain.
|
2016-08-19 20:07:38 +00:00
|
|
|
extends_documentation_fragment: f5
|
|
|
|
author:
|
|
|
|
- Tim Rupp (@caphrim007)
|
|
|
|
'''
|
|
|
|
|
2017-12-03 06:10:04 +00:00
|
|
|
EXAMPLES = r'''
|
2016-08-19 20:07:38 +00:00
|
|
|
- name: Create a route domain
|
|
|
|
bigip_routedomain:
|
2017-12-03 06:10:04 +00:00
|
|
|
name: foo
|
|
|
|
id: 1234
|
|
|
|
password: secret
|
|
|
|
server: lb.mydomain.com
|
|
|
|
state: present
|
|
|
|
user: admin
|
2016-08-19 20:07:38 +00:00
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
- name: Set VLANs on the route domain
|
|
|
|
bigip_routedomain:
|
2017-12-03 06:10:04 +00:00
|
|
|
name: bar
|
|
|
|
password: secret
|
|
|
|
server: lb.mydomain.com
|
|
|
|
state: present
|
|
|
|
user: admin
|
|
|
|
vlans:
|
|
|
|
- net1
|
|
|
|
- foo
|
2016-08-19 20:07:38 +00:00
|
|
|
delegate_to: localhost
|
|
|
|
'''
|
|
|
|
|
2017-12-03 06:10:04 +00:00
|
|
|
RETURN = r'''
|
2016-08-19 20:07:38 +00:00
|
|
|
id:
|
2018-04-25 02:49:52 +00:00
|
|
|
description: The ID of the route domain that was changed.
|
2017-12-03 06:10:04 +00:00
|
|
|
returned: changed
|
|
|
|
type: int
|
|
|
|
sample: 2
|
2016-08-19 20:07:38 +00:00
|
|
|
description:
|
2018-04-25 02:49:52 +00:00
|
|
|
description: The description of the route domain.
|
2017-12-03 06:10:04 +00:00
|
|
|
returned: changed
|
|
|
|
type: string
|
|
|
|
sample: route domain foo
|
2016-08-19 20:07:38 +00:00
|
|
|
strict:
|
2018-04-25 02:49:52 +00:00
|
|
|
description: The new strict isolation setting.
|
2017-12-03 06:10:04 +00:00
|
|
|
returned: changed
|
|
|
|
type: string
|
|
|
|
sample: enabled
|
2016-08-19 20:07:38 +00:00
|
|
|
parent:
|
2018-04-25 02:49:52 +00:00
|
|
|
description: The new parent route domain.
|
2017-12-03 06:10:04 +00:00
|
|
|
returned: changed
|
|
|
|
type: int
|
|
|
|
sample: 0
|
2016-08-19 20:07:38 +00:00
|
|
|
vlans:
|
2018-04-25 02:49:52 +00:00
|
|
|
description: List of new VLANs the route domain is applied to.
|
2017-12-03 06:10:04 +00:00
|
|
|
returned: changed
|
|
|
|
type: list
|
|
|
|
sample: ['/Common/http-tunnel', '/Common/socks-tunnel']
|
2016-08-19 20:07:38 +00:00
|
|
|
routing_protocol:
|
2018-04-25 02:49:52 +00:00
|
|
|
description: List of routing protocols applied to the route domain.
|
2017-12-03 06:10:04 +00:00
|
|
|
returned: changed
|
|
|
|
type: list
|
|
|
|
sample: ['bfd', 'bgp']
|
2016-08-19 20:07:38 +00:00
|
|
|
bwc_policy:
|
2018-04-25 02:49:52 +00:00
|
|
|
description: The new bandwidth controller.
|
2017-12-03 06:10:04 +00:00
|
|
|
returned: changed
|
|
|
|
type: string
|
|
|
|
sample: /Common/foo
|
2016-08-19 20:07:38 +00:00
|
|
|
connection_limit:
|
2018-04-25 02:49:52 +00:00
|
|
|
description: The new connection limit for the route domain.
|
2017-12-03 06:10:04 +00:00
|
|
|
returned: changed
|
|
|
|
type: int
|
|
|
|
sample: 100
|
2016-08-19 20:07:38 +00:00
|
|
|
flow_eviction_policy:
|
2018-04-25 02:49:52 +00:00
|
|
|
description: The new eviction policy to use with this route domain.
|
2017-12-03 06:10:04 +00:00
|
|
|
returned: changed
|
|
|
|
type: string
|
|
|
|
sample: /Common/default-eviction-policy
|
2016-08-19 20:07:38 +00:00
|
|
|
service_policy:
|
2018-04-25 02:49:52 +00:00
|
|
|
description: The new service policy to use with this route domain.
|
2017-12-03 06:10:04 +00:00
|
|
|
returned: changed
|
|
|
|
type: string
|
|
|
|
sample: /Common-my-service-policy
|
2016-08-19 20:07:38 +00:00
|
|
|
'''
|
|
|
|
|
2017-12-03 06:10:04 +00:00
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
2018-01-20 04:25:47 +00:00
|
|
|
from ansible.module_utils.basic import env_fallback
|
2017-12-03 06:10:04 +00:00
|
|
|
|
|
|
|
try:
|
2018-01-20 04:25:47 +00:00
|
|
|
from library.module_utils.network.f5.bigip import HAS_F5SDK
|
2018-04-25 02:49:52 +00:00
|
|
|
from library.module_utils.network.f5.bigip import F5Client
|
2018-01-20 04:25:47 +00:00
|
|
|
from library.module_utils.network.f5.common import F5ModuleError
|
2018-04-25 02:49:52 +00:00
|
|
|
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
|
2018-01-20 04:25:47 +00:00
|
|
|
from library.module_utils.network.f5.common import f5_argument_spec
|
|
|
|
try:
|
|
|
|
from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
|
|
|
except ImportError:
|
|
|
|
HAS_F5SDK = False
|
2016-08-19 20:07:38 +00:00
|
|
|
except ImportError:
|
2018-01-20 04:25:47 +00:00
|
|
|
from ansible.module_utils.network.f5.bigip import HAS_F5SDK
|
2018-04-25 02:49:52 +00:00
|
|
|
from ansible.module_utils.network.f5.bigip import F5Client
|
2018-01-20 04:25:47 +00:00
|
|
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
2018-04-25 02:49:52 +00:00
|
|
|
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
|
2018-01-20 04:25:47 +00:00
|
|
|
from ansible.module_utils.network.f5.common import f5_argument_spec
|
|
|
|
try:
|
|
|
|
from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
|
|
|
except ImportError:
|
|
|
|
HAS_F5SDK = False
|
2016-08-19 20:07:38 +00:00
|
|
|
|
2017-12-03 06:10:04 +00:00
|
|
|
|
2018-04-25 02:49:52 +00:00
|
|
|
class Parameters(AnsibleF5Parameters):
|
|
|
|
api_map = {
|
|
|
|
'connectionLimit': 'connection_limit',
|
|
|
|
'servicePolicy': 'service_policy',
|
|
|
|
'bwcPolicy': 'bwc_policy',
|
|
|
|
'flowEvictionPolicy': 'flow_eviction_policy',
|
|
|
|
'routingProtocol': 'routing_protocol'
|
|
|
|
}
|
|
|
|
|
|
|
|
api_attributes = [
|
|
|
|
'connectionLimit',
|
|
|
|
'description',
|
|
|
|
'strict',
|
|
|
|
'parent',
|
|
|
|
'servicePolicy',
|
|
|
|
'bwcPolicy',
|
|
|
|
'flowEvictionPolicy',
|
|
|
|
'routingProtocol',
|
|
|
|
'vlans',
|
|
|
|
'id'
|
|
|
|
]
|
|
|
|
|
|
|
|
returnables = [
|
|
|
|
'description',
|
|
|
|
'strict',
|
|
|
|
'parent',
|
|
|
|
'service_policy',
|
|
|
|
'bwc_policy',
|
|
|
|
'flow_eviction_policy',
|
|
|
|
'routing_protocol',
|
|
|
|
'vlans',
|
|
|
|
'connection_limit',
|
|
|
|
'id'
|
|
|
|
]
|
|
|
|
|
|
|
|
updatables = [
|
|
|
|
'description',
|
|
|
|
'strict',
|
|
|
|
'parent',
|
|
|
|
'service_policy',
|
|
|
|
'bwc_policy',
|
|
|
|
'flow_eviction_policy',
|
|
|
|
'routing_protocol',
|
|
|
|
'vlans',
|
|
|
|
'connection_limit',
|
|
|
|
'id'
|
|
|
|
]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def connection_limit(self):
|
|
|
|
if self._values['connection_limit'] is None:
|
|
|
|
return None
|
|
|
|
return int(self._values['connection_limit'])
|
|
|
|
|
|
|
|
@property
|
|
|
|
def id(self):
|
|
|
|
if self._values['id'] is None:
|
|
|
|
return None
|
|
|
|
return int(self._values['id'])
|
|
|
|
|
|
|
|
|
|
|
|
class ApiParameters(Parameters):
|
|
|
|
@property
|
|
|
|
def strict(self):
|
|
|
|
if self._values['strict'] is None:
|
|
|
|
return None
|
|
|
|
if self._values['strict'] == 'enabled':
|
|
|
|
return True
|
|
|
|
return False
|
2016-08-19 20:07:38 +00:00
|
|
|
|
2018-04-25 02:49:52 +00:00
|
|
|
@property
|
|
|
|
def domains(self):
|
|
|
|
domains = self.read_domains_from_device()
|
|
|
|
result = [x.fullPath for x in domains]
|
|
|
|
return result
|
2016-08-19 20:07:38 +00:00
|
|
|
|
2018-04-25 02:49:52 +00:00
|
|
|
def read_domains_from_device(self):
|
|
|
|
collection = self.client.api.tm.net.route_domains.get_collection()
|
|
|
|
return collection
|
|
|
|
|
|
|
|
|
|
|
|
class ModuleParameters(Parameters):
|
|
|
|
@property
|
|
|
|
def bwc_policy(self):
|
|
|
|
if self._values['bwc_policy'] is None:
|
|
|
|
return None
|
|
|
|
return fq_name(self.partition, self._values['bwc_policy'])
|
|
|
|
|
|
|
|
@property
|
|
|
|
def flow_eviction_policy(self):
|
|
|
|
if self._values['flow_eviction_policy'] is None:
|
|
|
|
return None
|
|
|
|
return fq_name(self.partition, self._values['flow_eviction_policy'])
|
|
|
|
|
|
|
|
@property
|
|
|
|
def service_policy(self):
|
|
|
|
if self._values['service_policy'] is None:
|
|
|
|
return None
|
|
|
|
return fq_name(self.partition, self._values['service_policy'])
|
|
|
|
|
|
|
|
@property
|
|
|
|
def parent(self):
|
|
|
|
if self._values['parent'] is None:
|
|
|
|
return None
|
|
|
|
result = fq_name(self.partition, self._values['parent'])
|
|
|
|
return result
|
2016-08-19 20:07:38 +00:00
|
|
|
|
2018-04-25 02:49:52 +00:00
|
|
|
@property
|
|
|
|
def vlans(self):
|
|
|
|
if self._values['vlans'] is None:
|
|
|
|
return None
|
|
|
|
if len(self._values['vlans']) == 1 and self._values['vlans'][0] == '':
|
|
|
|
return ''
|
|
|
|
return [fq_name(self.partition, x) for x in self._values['vlans']]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
if self._values['name'] is None:
|
|
|
|
return str(self.id)
|
|
|
|
return self._values['name']
|
|
|
|
|
|
|
|
@property
|
|
|
|
def routing_protocol(self):
|
|
|
|
if self._values['routing_protocol'] is None:
|
|
|
|
return None
|
|
|
|
if len(self._values['routing_protocol']) == 1 and self._values['routing_protocol'][0] == '':
|
|
|
|
return ''
|
|
|
|
return self._values['routing_protocol']
|
|
|
|
|
|
|
|
|
|
|
|
class Changes(Parameters):
|
|
|
|
def to_return(self):
|
|
|
|
result = {}
|
|
|
|
try:
|
|
|
|
for returnable in self.returnables:
|
|
|
|
result[returnable] = getattr(self, returnable)
|
|
|
|
result = self._filter_params(result)
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
return result
|
2016-08-19 20:07:38 +00:00
|
|
|
|
|
|
|
|
2018-04-25 02:49:52 +00:00
|
|
|
class UsableChanges(Changes):
|
|
|
|
@property
|
|
|
|
def strict(self):
|
|
|
|
if self._values['strict'] is None:
|
|
|
|
return None
|
|
|
|
if self._values['strict']:
|
|
|
|
return 'enabled'
|
|
|
|
return 'disabled'
|
2016-08-19 20:07:38 +00:00
|
|
|
|
|
|
|
|
2018-04-25 02:49:52 +00:00
|
|
|
class ReportableChanges(Changes):
|
|
|
|
@property
|
|
|
|
def strict(self):
|
|
|
|
if self._values['strict'] is None:
|
|
|
|
return None
|
|
|
|
if self._values['strict'] == 'enabled':
|
|
|
|
return 'yes'
|
|
|
|
return 'no'
|
2016-08-19 20:07:38 +00:00
|
|
|
|
2017-12-03 06:10:04 +00:00
|
|
|
|
2018-04-25 02:49:52 +00:00
|
|
|
class Difference(object):
|
|
|
|
def __init__(self, want, have=None):
|
|
|
|
self.want = want
|
|
|
|
self.have = have
|
2016-08-19 20:07:38 +00:00
|
|
|
|
2018-04-25 02:49:52 +00:00
|
|
|
def compare(self, param):
|
|
|
|
try:
|
|
|
|
result = getattr(self, param)
|
|
|
|
return result
|
|
|
|
except AttributeError:
|
|
|
|
return self.__default(param)
|
|
|
|
|
|
|
|
def __default(self, param):
|
|
|
|
attr1 = getattr(self.want, param)
|
|
|
|
try:
|
|
|
|
attr2 = getattr(self.have, param)
|
|
|
|
if attr1 != attr2:
|
|
|
|
return attr1
|
|
|
|
except AttributeError:
|
|
|
|
return attr1
|
|
|
|
|
|
|
|
@property
|
|
|
|
def routing_protocol(self):
|
|
|
|
if self.want.routing_protocol is None:
|
|
|
|
return None
|
|
|
|
if self.want.routing_protocol == '' and self.have.routing_protocol is None:
|
|
|
|
return None
|
|
|
|
if self.want.routing_protocol == '' and len(self.have.routing_protocol) > 0:
|
|
|
|
return []
|
|
|
|
if self.have.routing_protocol is None:
|
|
|
|
return self.want.routing_protocol
|
|
|
|
want = set(self.want.routing_protocol)
|
|
|
|
have = set(self.have.routing_protocol)
|
|
|
|
if want != have:
|
|
|
|
return list(want)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def vlans(self):
|
|
|
|
if self.want.vlans is None:
|
|
|
|
return None
|
|
|
|
if self.want.vlans == '' and self.have.vlans is None:
|
|
|
|
return None
|
|
|
|
if self.want.vlans == '' and len(self.have.vlans) > 0:
|
|
|
|
return []
|
|
|
|
if self.have.vlans is None:
|
|
|
|
return self.want.vlans
|
|
|
|
want = set(self.want.vlans)
|
|
|
|
have = set(self.have.vlans)
|
|
|
|
if want != have:
|
|
|
|
return list(want)
|
|
|
|
|
|
|
|
|
|
|
|
class ModuleManager(object):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
self.module = kwargs.get('module', None)
|
|
|
|
self.client = kwargs.get('client', None)
|
|
|
|
self.want = ModuleParameters(params=self.module.params, client=self.client)
|
|
|
|
self.have = ApiParameters(client=self.client)
|
|
|
|
self.changes = UsableChanges()
|
|
|
|
|
|
|
|
def _set_changed_options(self):
|
|
|
|
changed = {}
|
|
|
|
for key in Parameters.returnables:
|
|
|
|
if getattr(self.want, key) is not None:
|
|
|
|
changed[key] = getattr(self.want, key)
|
|
|
|
if changed:
|
|
|
|
self.changes = UsableChanges(params=changed)
|
|
|
|
|
|
|
|
def _update_changed_options(self):
|
|
|
|
diff = Difference(self.want, self.have)
|
|
|
|
updatables = Parameters.updatables
|
|
|
|
changed = dict()
|
|
|
|
for k in updatables:
|
|
|
|
change = diff.compare(k)
|
|
|
|
if change is None:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
if isinstance(change, dict):
|
|
|
|
changed.update(change)
|
|
|
|
else:
|
|
|
|
changed[k] = change
|
|
|
|
if changed:
|
|
|
|
self.changes = UsableChanges(params=changed)
|
2016-08-19 20:07:38 +00:00
|
|
|
return True
|
2018-04-25 02:49:52 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
def should_update(self):
|
|
|
|
result = self._update_changed_options()
|
|
|
|
if result:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def exec_module(self):
|
|
|
|
changed = False
|
|
|
|
result = dict()
|
|
|
|
state = self.want.state
|
|
|
|
|
|
|
|
try:
|
|
|
|
if state == "present":
|
|
|
|
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()
|
|
|
|
result.update(**changes)
|
|
|
|
result.update(dict(changed=changed))
|
|
|
|
self._announce_deprecations(result)
|
|
|
|
return result
|
|
|
|
|
|
|
|
def _announce_deprecations(self, result):
|
|
|
|
warnings = result.pop('__warnings', [])
|
|
|
|
for warning in warnings:
|
|
|
|
self.client.module.deprecate(
|
|
|
|
msg=warning['msg'],
|
|
|
|
version=warning['version']
|
|
|
|
)
|
2016-08-19 20:07:38 +00:00
|
|
|
|
|
|
|
def present(self):
|
|
|
|
if self.exists():
|
|
|
|
return self.update()
|
|
|
|
else:
|
|
|
|
return self.create()
|
|
|
|
|
2018-04-25 02:49:52 +00:00
|
|
|
def exists(self):
|
|
|
|
result = self.client.api.tm.net.route_domains.route_domain.exists(
|
|
|
|
name=self.want.name,
|
|
|
|
partition=self.want.partition
|
2016-08-19 20:07:38 +00:00
|
|
|
)
|
2018-04-25 02:49:52 +00:00
|
|
|
return result
|
2016-08-19 20:07:38 +00:00
|
|
|
|
2018-04-25 02:49:52 +00:00
|
|
|
def update(self):
|
|
|
|
self.have = self.read_current_from_device()
|
|
|
|
if not self.should_update():
|
|
|
|
return False
|
|
|
|
if self.want.parent and self.want.parent not in self.have.domains:
|
|
|
|
raise F5ModuleError(
|
|
|
|
"The parent route domain was not found."
|
|
|
|
)
|
|
|
|
if self.module.check_mode:
|
|
|
|
return True
|
|
|
|
self.update_on_device()
|
|
|
|
return True
|
2016-08-19 20:07:38 +00:00
|
|
|
|
2018-04-25 02:49:52 +00:00
|
|
|
def remove(self):
|
|
|
|
if self.module.check_mode:
|
|
|
|
return True
|
|
|
|
self.remove_from_device()
|
|
|
|
if self.exists():
|
|
|
|
raise F5ModuleError("Failed to delete the resource.")
|
|
|
|
return True
|
2016-09-14 06:35:15 +00:00
|
|
|
|
2016-08-19 20:07:38 +00:00
|
|
|
def create(self):
|
2018-04-25 02:49:52 +00:00
|
|
|
if self.want.id is None:
|
2017-12-03 06:10:04 +00:00
|
|
|
raise F5ModuleError(
|
|
|
|
"The 'id' parameter is required when creating new route domains."
|
|
|
|
)
|
2018-04-25 02:49:52 +00:00
|
|
|
if self.want.parent and self.want.parent not in self.have.domains:
|
2016-08-19 20:07:38 +00:00
|
|
|
raise F5ModuleError(
|
2018-04-25 02:49:52 +00:00
|
|
|
"The parent route domain was not found."
|
2016-08-19 20:07:38 +00:00
|
|
|
)
|
2018-04-25 02:49:52 +00:00
|
|
|
self._set_changed_options()
|
|
|
|
if self.module.check_mode:
|
|
|
|
return True
|
|
|
|
self.create_on_device()
|
|
|
|
return True
|
2016-08-19 20:07:38 +00:00
|
|
|
|
2018-04-25 02:49:52 +00:00
|
|
|
def create_on_device(self):
|
|
|
|
params = self.changes.api_params()
|
|
|
|
self.client.api.tm.net.route_domains.route_domain.create(
|
|
|
|
name=self.want.name,
|
|
|
|
partition=self.want.partition,
|
|
|
|
**params
|
|
|
|
)
|
2016-08-19 20:07:38 +00:00
|
|
|
|
2018-04-25 02:49:52 +00:00
|
|
|
def update_on_device(self):
|
|
|
|
params = self.changes.api_params()
|
|
|
|
resource = self.client.api.tm.net.route_domains.route_domain.load(
|
|
|
|
name=self.want.name,
|
|
|
|
partition=self.want.partition
|
|
|
|
)
|
|
|
|
resource.modify(**params)
|
2016-08-19 20:07:38 +00:00
|
|
|
|
2018-04-25 02:49:52 +00:00
|
|
|
def absent(self):
|
|
|
|
if self.exists():
|
|
|
|
return self.remove()
|
|
|
|
return False
|
2016-08-19 20:07:38 +00:00
|
|
|
|
2018-04-25 02:49:52 +00:00
|
|
|
def remove_from_device(self):
|
|
|
|
resource = self.client.api.tm.net.route_domains.route_domain.load(
|
|
|
|
name=self.want.name,
|
|
|
|
partition=self.want.partition
|
|
|
|
)
|
|
|
|
if resource:
|
|
|
|
resource.delete()
|
2016-08-19 20:07:38 +00:00
|
|
|
|
2018-04-25 02:49:52 +00:00
|
|
|
def read_current_from_device(self):
|
|
|
|
resource = self.client.api.tm.net.route_domains.route_domain.load(
|
|
|
|
name=self.want.name,
|
|
|
|
partition=self.want.partition
|
|
|
|
)
|
|
|
|
result = resource.attrs
|
|
|
|
return ApiParameters(params=result, client=self.client)
|
|
|
|
|
|
|
|
|
|
|
|
class ArgumentSpec(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.supports_check_mode = True
|
|
|
|
argument_spec = dict(
|
|
|
|
name=dict(),
|
|
|
|
id=dict(type='int'),
|
|
|
|
description=dict(),
|
|
|
|
strict=dict(type='bool'),
|
|
|
|
parent=dict(type='int'),
|
|
|
|
vlans=dict(type='list'),
|
|
|
|
routing_protocol=dict(
|
|
|
|
type='list',
|
|
|
|
choices=['BFD', 'BGP', 'IS-IS', 'OSPFv2', 'OSPFv3', 'PIM', 'RIP', 'RIPng']
|
|
|
|
),
|
|
|
|
bwc_policy=dict(),
|
|
|
|
connection_limit=dict(type='int'),
|
|
|
|
flow_eviction_policy=dict(),
|
|
|
|
service_policy=dict(),
|
|
|
|
partition=dict(
|
|
|
|
default='Common',
|
|
|
|
fallback=(env_fallback, ['F5_PARTITION'])
|
|
|
|
),
|
|
|
|
state=dict(
|
|
|
|
default='present',
|
|
|
|
choices=['present', 'absent']
|
2016-08-19 20:07:38 +00:00
|
|
|
)
|
|
|
|
)
|
2018-04-25 02:49:52 +00:00
|
|
|
self.argument_spec = {}
|
|
|
|
self.argument_spec.update(f5_argument_spec)
|
|
|
|
self.argument_spec.update(argument_spec)
|
|
|
|
self.required_one_of = [
|
|
|
|
['name', 'id']
|
|
|
|
]
|
2016-08-19 20:07:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2018-04-25 02:49:52 +00:00
|
|
|
spec = ArgumentSpec()
|
2016-08-19 20:07:38 +00:00
|
|
|
|
|
|
|
module = AnsibleModule(
|
2018-04-25 02:49:52 +00:00
|
|
|
argument_spec=spec.argument_spec,
|
|
|
|
supports_check_mode=spec.supports_check_mode
|
2016-08-19 20:07:38 +00:00
|
|
|
)
|
2018-04-25 02:49:52 +00:00
|
|
|
if not HAS_F5SDK:
|
|
|
|
module.fail_json(msg="The python f5-sdk module is required")
|
2016-08-19 20:07:38 +00:00
|
|
|
|
|
|
|
try:
|
2018-04-25 02:49:52 +00:00
|
|
|
client = F5Client(**module.params)
|
|
|
|
mm = ModuleManager(module=module, client=client)
|
|
|
|
results = mm.exec_module()
|
|
|
|
cleanup_tokens(client)
|
|
|
|
module.exit_json(**results)
|
|
|
|
except F5ModuleError as ex:
|
|
|
|
cleanup_tokens(client)
|
|
|
|
module.fail_json(msg=str(ex))
|
2016-08-19 20:07:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|