routedomain fixes (#33501)
* routedomain fixes Adds partition. Adds name. Makes name and id mutually exclusive. * Fixes upstream errors
This commit is contained in:
parent
dd94cc8229
commit
00bf4ee210
2 changed files with 140 additions and 87 deletions
|
@ -1,21 +1,31 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# Copyright (c) 2017 F5 Networks Inc.
|
# Copyright (c) 2016 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_routedomain
|
module: bigip_routedomain
|
||||||
short_description: Manage route domains on a BIG-IP
|
short_description: Manage route domains on a BIG-IP
|
||||||
description:
|
description:
|
||||||
- Manage route domains on a BIG-IP
|
- Manage route domains on a BIG-IP.
|
||||||
version_added: "2.2"
|
version_added: "2.2"
|
||||||
options:
|
options:
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- The name of the route domain.
|
||||||
|
- When creating a new route domain, if this value is not specified, then the
|
||||||
|
value of C(id) will be used for it.
|
||||||
|
version_added: 2.5
|
||||||
bwc_policy:
|
bwc_policy:
|
||||||
description:
|
description:
|
||||||
- The bandwidth controller for the route domain.
|
- The bandwidth controller for the route domain.
|
||||||
|
@ -34,12 +44,21 @@ options:
|
||||||
id:
|
id:
|
||||||
description:
|
description:
|
||||||
- The unique identifying integer representing the route domain.
|
- The unique identifying integer representing the route domain.
|
||||||
required: true
|
- 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.
|
||||||
parent:
|
parent:
|
||||||
description:
|
description:
|
||||||
Specifies the route domain the system searches when it cannot
|
Specifies the route domain the system searches when it cannot
|
||||||
find a route in the configured domain.
|
find a route in the configured domain.
|
||||||
required: false
|
partition:
|
||||||
|
description:
|
||||||
|
- Partition to create the route domain on. Partitions cannot be updated
|
||||||
|
once they are created.
|
||||||
|
default: Common
|
||||||
|
version_added: 2.5
|
||||||
routing_protocol:
|
routing_protocol:
|
||||||
description:
|
description:
|
||||||
- Dynamic routing protocols for the system to use in the route domain.
|
- Dynamic routing protocols for the system to use in the route domain.
|
||||||
|
@ -58,7 +77,6 @@ options:
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- Whether the route domain should exist or not.
|
- Whether the route domain should exist or not.
|
||||||
required: false
|
|
||||||
default: present
|
default: present
|
||||||
choices:
|
choices:
|
||||||
- present
|
- present
|
||||||
|
@ -83,89 +101,100 @@ author:
|
||||||
- Tim Rupp (@caphrim007)
|
- Tim Rupp (@caphrim007)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = r'''
|
||||||
- name: Create a route domain
|
- name: Create a route domain
|
||||||
bigip_routedomain:
|
bigip_routedomain:
|
||||||
id: "1234"
|
name: foo
|
||||||
password: "secret"
|
id: 1234
|
||||||
server: "lb.mydomain.com"
|
password: secret
|
||||||
state: "present"
|
server: lb.mydomain.com
|
||||||
user: "admin"
|
state: present
|
||||||
|
user: admin
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: Set VLANs on the route domain
|
- name: Set VLANs on the route domain
|
||||||
bigip_routedomain:
|
bigip_routedomain:
|
||||||
id: "1234"
|
name: bar
|
||||||
password: "secret"
|
password: secret
|
||||||
server: "lb.mydomain.com"
|
server: lb.mydomain.com
|
||||||
state: "present"
|
state: present
|
||||||
user: "admin"
|
user: admin
|
||||||
vlans:
|
vlans:
|
||||||
- net1
|
- net1
|
||||||
- foo
|
- foo
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = r'''
|
||||||
id:
|
id:
|
||||||
description: The ID of the route domain that was changed
|
description: The ID of the route domain that was changed
|
||||||
returned: changed
|
returned: changed
|
||||||
type: int
|
type: int
|
||||||
sample: 2
|
sample: 2
|
||||||
description:
|
description:
|
||||||
description: The description of the route domain
|
description: The description of the route domain
|
||||||
returned: changed
|
returned: changed
|
||||||
type: string
|
type: string
|
||||||
sample: "route domain foo"
|
sample: route domain foo
|
||||||
strict:
|
strict:
|
||||||
description: The new strict isolation setting
|
description: The new strict isolation setting
|
||||||
returned: changed
|
returned: changed
|
||||||
type: string
|
type: string
|
||||||
sample: "enabled"
|
sample: enabled
|
||||||
parent:
|
parent:
|
||||||
description: The new parent route domain
|
description: The new parent route domain
|
||||||
returned: changed
|
returned: changed
|
||||||
type: int
|
type: int
|
||||||
sample: 0
|
sample: 0
|
||||||
vlans:
|
vlans:
|
||||||
description: List of new VLANs the route domain is applied to
|
description: List of new VLANs the route domain is applied to
|
||||||
returned: changed
|
returned: changed
|
||||||
type: list
|
type: list
|
||||||
sample: ['/Common/http-tunnel', '/Common/socks-tunnel']
|
sample: ['/Common/http-tunnel', '/Common/socks-tunnel']
|
||||||
routing_protocol:
|
routing_protocol:
|
||||||
description: List of routing protocols applied to the route domain
|
description: List of routing protocols applied to the route domain
|
||||||
returned: changed
|
returned: changed
|
||||||
type: list
|
type: list
|
||||||
sample: ['bfd', 'bgp']
|
sample: ['bfd', 'bgp']
|
||||||
bwc_policy:
|
bwc_policy:
|
||||||
description: The new bandwidth controller
|
description: The new bandwidth controller
|
||||||
returned: changed
|
returned: changed
|
||||||
type: string
|
type: string
|
||||||
sample: /Common/foo
|
sample: /Common/foo
|
||||||
connection_limit:
|
connection_limit:
|
||||||
description: The new connection limit for the route domain
|
description: The new connection limit for the route domain
|
||||||
returned: changed
|
returned: changed
|
||||||
type: int
|
type: int
|
||||||
sample: 100
|
sample: 100
|
||||||
flow_eviction_policy:
|
flow_eviction_policy:
|
||||||
description: The new eviction policy to use with this route domain
|
description: The new eviction policy to use with this route domain
|
||||||
returned: changed
|
returned: changed
|
||||||
type: string
|
type: string
|
||||||
sample: /Common/default-eviction-policy
|
sample: /Common/default-eviction-policy
|
||||||
service_policy:
|
service_policy:
|
||||||
description: The new service policy to use with this route domain
|
description: The new service policy to use with this route domain
|
||||||
returned: changed
|
returned: changed
|
||||||
type: string
|
type: string
|
||||||
sample: /Common-my-service-policy
|
sample: /Common-my-service-policy
|
||||||
'''
|
'''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from f5.bigip import ManagementRoot
|
from f5.bigip import ManagementRoot
|
||||||
from icontrol.session import iControlUnexpectedHTTPError
|
except ImportError:
|
||||||
HAS_F5SDK = True
|
pass # Handled via f5_utils.HAS_F5SDK
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
|
||||||
|
from ansible.module_utils.f5_utils import F5ModuleError
|
||||||
|
from ansible.module_utils.f5_utils import HAS_F5SDK
|
||||||
|
from ansible.module_utils.f5_utils import f5_argument_spec
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_F5SDK = False
|
HAS_F5SDK = False
|
||||||
|
|
||||||
|
|
||||||
PROTOCOLS = [
|
PROTOCOLS = [
|
||||||
'BFD', 'BGP', 'IS-IS', 'OSPFv2', 'OSPFv3', 'PIM', 'RIP', 'RIPng'
|
'BFD', 'BGP', 'IS-IS', 'OSPFv2', 'OSPFv3', 'PIM', 'RIP', 'RIPng'
|
||||||
]
|
]
|
||||||
|
@ -181,14 +210,13 @@ class BigIpRouteDomain(object):
|
||||||
# The params that change in the module
|
# The params that change in the module
|
||||||
self.cparams = dict()
|
self.cparams = dict()
|
||||||
|
|
||||||
kwargs['name'] = str(kwargs['id'])
|
|
||||||
|
|
||||||
# Stores the params that are sent to the module
|
# Stores the params that are sent to the module
|
||||||
self.params = kwargs
|
self.params = kwargs
|
||||||
self.api = ManagementRoot(kwargs['server'],
|
self.api = ManagementRoot(kwargs['server'],
|
||||||
kwargs['user'],
|
kwargs['user'],
|
||||||
kwargs['password'],
|
kwargs['password'],
|
||||||
port=kwargs['server_port'])
|
port=kwargs['server_port'],
|
||||||
|
token=True)
|
||||||
|
|
||||||
def absent(self):
|
def absent(self):
|
||||||
if not self.exists():
|
if not self.exists():
|
||||||
|
@ -197,8 +225,12 @@ class BigIpRouteDomain(object):
|
||||||
if self.params['check_mode']:
|
if self.params['check_mode']:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
if self.params['name'] is None:
|
||||||
|
self.params['name'] = str(self.params['id'])
|
||||||
|
|
||||||
rd = self.api.tm.net.route_domains.route_domain.load(
|
rd = self.api.tm.net.route_domains.route_domain.load(
|
||||||
name=self.params['name']
|
name=self.params['name'],
|
||||||
|
partition=self.params['partition']
|
||||||
)
|
)
|
||||||
rd.delete()
|
rd.delete()
|
||||||
|
|
||||||
|
@ -226,8 +258,13 @@ class BigIpRouteDomain(object):
|
||||||
parameters that are supported by the module.
|
parameters that are supported by the module.
|
||||||
"""
|
"""
|
||||||
p = dict()
|
p = dict()
|
||||||
|
|
||||||
|
if self.params['name'] is None:
|
||||||
|
self.params['name'] = str(self.params['id'])
|
||||||
|
|
||||||
r = self.api.tm.net.route_domains.route_domain.load(
|
r = self.api.tm.net.route_domains.route_domain.load(
|
||||||
name=self.params['name']
|
name=self.params['name'],
|
||||||
|
partition=self.params['partition']
|
||||||
)
|
)
|
||||||
|
|
||||||
p['id'] = int(r.id)
|
p['id'] = int(r.id)
|
||||||
|
@ -271,6 +308,14 @@ class BigIpRouteDomain(object):
|
||||||
params = dict()
|
params = dict()
|
||||||
params['id'] = self.params['id']
|
params['id'] = self.params['id']
|
||||||
params['name'] = self.params['name']
|
params['name'] = self.params['name']
|
||||||
|
params['partition'] = self.params['partition']
|
||||||
|
|
||||||
|
if params['name'] is None:
|
||||||
|
self.params['name'] = str(self.params['id'])
|
||||||
|
elif params['id'] is None:
|
||||||
|
raise F5ModuleError(
|
||||||
|
"The 'id' parameter is required when creating new route domains."
|
||||||
|
)
|
||||||
|
|
||||||
partition = self.params['partition']
|
partition = self.params['partition']
|
||||||
description = self.params['description']
|
description = self.params['description']
|
||||||
|
@ -331,7 +376,8 @@ class BigIpRouteDomain(object):
|
||||||
|
|
||||||
self.api.tm.net.route_domains.route_domain.create(**params)
|
self.api.tm.net.route_domains.route_domain.create(**params)
|
||||||
exists = self.api.tm.net.route_domains.route_domain.exists(
|
exists = self.api.tm.net.route_domains.route_domain.exists(
|
||||||
name=self.params['name']
|
name=self.params['name'],
|
||||||
|
partition=self.params['partition']
|
||||||
)
|
)
|
||||||
|
|
||||||
if exists:
|
if exists:
|
||||||
|
@ -346,6 +392,9 @@ class BigIpRouteDomain(object):
|
||||||
params = dict()
|
params = dict()
|
||||||
current = self.read()
|
current = self.read()
|
||||||
|
|
||||||
|
if self.params['name'] is None:
|
||||||
|
self.params['name'] = str(self.params['id'])
|
||||||
|
|
||||||
check_mode = self.params['check_mode']
|
check_mode = self.params['check_mode']
|
||||||
partition = self.params['partition']
|
partition = self.params['partition']
|
||||||
description = self.params['description']
|
description = self.params['description']
|
||||||
|
@ -443,7 +492,8 @@ class BigIpRouteDomain(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rd = self.api.tm.net.route_domains.route_domain.load(
|
rd = self.api.tm.net.route_domains.route_domain.load(
|
||||||
name=self.params['name']
|
name=self.params['name'],
|
||||||
|
partition=self.params['partition']
|
||||||
)
|
)
|
||||||
rd.update(**params)
|
rd.update(**params)
|
||||||
rd.refresh()
|
rd.refresh()
|
||||||
|
@ -453,11 +503,14 @@ class BigIpRouteDomain(object):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def exists(self):
|
def exists(self):
|
||||||
|
if self.params['name'] is None:
|
||||||
|
self.params['name'] = str(self.params['id'])
|
||||||
return self.api.tm.net.route_domains.route_domain.exists(
|
return self.api.tm.net.route_domains.route_domain.exists(
|
||||||
name=self.params['name']
|
name=self.params['name'],
|
||||||
|
partition=self.params['partition']
|
||||||
)
|
)
|
||||||
|
|
||||||
def flush(self):
|
def exec_module(self):
|
||||||
result = dict()
|
result = dict()
|
||||||
state = self.params['state']
|
state = self.params['state']
|
||||||
|
|
||||||
|
@ -476,35 +529,35 @@ def main():
|
||||||
argument_spec = f5_argument_spec()
|
argument_spec = f5_argument_spec()
|
||||||
|
|
||||||
meta_args = dict(
|
meta_args = dict(
|
||||||
id=dict(required=True, type='int'),
|
name=dict(),
|
||||||
description=dict(required=False, default=None),
|
id=dict(type='int'),
|
||||||
strict=dict(required=False, default=None, choices=STRICTS),
|
description=dict(),
|
||||||
parent=dict(required=False, type='int', default=None),
|
strict=dict(choices=STRICTS),
|
||||||
vlans=dict(required=False, default=None, type='list'),
|
parent=dict(type='int'),
|
||||||
routing_protocol=dict(required=False, default=None, type='list'),
|
partition=dict(default='Common'),
|
||||||
bwc_policy=dict(required=False, type='str', default=None),
|
vlans=dict(type='list'),
|
||||||
connection_limit=dict(required=False, type='int', default=None),
|
routing_protocol=dict(type='list'),
|
||||||
flow_eviction_policy=dict(required=False, type='str', default=None),
|
bwc_policy=dict(),
|
||||||
service_policy=dict(required=False, type='str', default=None)
|
connection_limit=dict(type='int',),
|
||||||
|
flow_eviction_policy=dict(),
|
||||||
|
service_policy=dict()
|
||||||
)
|
)
|
||||||
argument_spec.update(meta_args)
|
argument_spec.update(meta_args)
|
||||||
|
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=argument_spec,
|
argument_spec=argument_spec,
|
||||||
supports_check_mode=True
|
supports_check_mode=True,
|
||||||
|
required_one_of=[['name', 'id']]
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj = BigIpRouteDomain(check_mode=module.check_mode, **module.params)
|
obj = BigIpRouteDomain(check_mode=module.check_mode, **module.params)
|
||||||
result = obj.flush()
|
result = obj.exec_module()
|
||||||
|
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
except F5ModuleError as e:
|
except F5ModuleError as e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
|
|
||||||
from ansible.module_utils.basic import *
|
|
||||||
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
|
|
||||||
from ansible.module_utils.f5_utils import *
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
0
test/units/modules/network/f5/test_bigip_routedomain.py
Normal file
0
test/units/modules/network/f5/test_bigip_routedomain.py
Normal file
Loading…
Reference in a new issue