Allow to specify multiple allocation pools when creating a subnet
With this change, multiple allocation pool may be specified when creating a subnet. Allocation pools are defined as a list of dictionaries. For example: openstack.cloud.subnet: name: sub1 network: network1 cidr: 192.168.0.0/24 ip_version: 4 allocation_pools: - start: 192.168.0.10 end: 192.168.0.50 - start: 192.168.0.100 end: 192.168.0.150 Change-Id: I77a06990de082466dc6265a14c379b8bbaf789e8
This commit is contained in:
parent
e42e21f621
commit
28541ee158
@ -68,6 +68,80 @@
|
|||||||
name: "{{ subnet_name }}"
|
name: "{{ subnet_name }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
|
- name: Create subnet {{ subnet_name }} with multiple allocation pools on network {{ network_name }}
|
||||||
|
openstack.cloud.subnet:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
network_name: "{{ network_name }}"
|
||||||
|
enable_dhcp: "{{ enable_subnet_dhcp }}"
|
||||||
|
name: "{{ subnet_name }}"
|
||||||
|
state: present
|
||||||
|
cidr: 192.168.0.0/24
|
||||||
|
gateway_ip: 192.168.0.1
|
||||||
|
allocation_pools:
|
||||||
|
- start: 192.168.0.2
|
||||||
|
end: 192.168.0.4
|
||||||
|
- start: 192.168.0.10
|
||||||
|
end: 192.168.0.12
|
||||||
|
|
||||||
|
- name: Create subnet {{ subnet_name }} on network {{ network_name }} again
|
||||||
|
openstack.cloud.subnet:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
network_name: "{{ network_name }}"
|
||||||
|
enable_dhcp: "{{ enable_subnet_dhcp }}"
|
||||||
|
name: "{{ subnet_name }}"
|
||||||
|
state: present
|
||||||
|
cidr: 192.168.0.0/24
|
||||||
|
gateway_ip: 192.168.0.1
|
||||||
|
allocation_pools:
|
||||||
|
- start: 192.168.0.2
|
||||||
|
end: 192.168.0.4
|
||||||
|
- start: 192.168.0.10
|
||||||
|
end: 192.168.0.12
|
||||||
|
register: idem2
|
||||||
|
|
||||||
|
- name: Update subnet {{ subnet_name }} allocation pools
|
||||||
|
openstack.cloud.subnet:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
network_name: "{{ network_name }}"
|
||||||
|
name: "{{ subnet_name }}"
|
||||||
|
state: present
|
||||||
|
cidr: 192.168.0.0/24
|
||||||
|
gateway_ip: 192.168.0.1
|
||||||
|
allocation_pools:
|
||||||
|
- start: 192.168.0.2
|
||||||
|
end: 192.168.0.8
|
||||||
|
- start: 192.168.0.10
|
||||||
|
end: 192.168.0.16
|
||||||
|
|
||||||
|
- name: Get Subnet Info
|
||||||
|
openstack.cloud.subnets_info:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
name: "{{ subnet_name }}"
|
||||||
|
register: subnet_result
|
||||||
|
|
||||||
|
- name: Verify Subnet Allocation Pools Exist
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- idem2 is not changed
|
||||||
|
- subnet_result.subnets is defined
|
||||||
|
- subnet_result.subnets | length == 1
|
||||||
|
- subnet_result.subnets[0].allocation_pools is defined
|
||||||
|
- subnet_result.subnets[0].allocation_pools | length == 2
|
||||||
|
|
||||||
|
- name: Verify Subnet Allocation Pools
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- (subnet_result.subnets[0].allocation_pools.0.start == '192.168.0.2' and subnet_result.subnets[0].allocation_pools.0.end == '192.168.0.8') or
|
||||||
|
(subnet_result.subnets[0].allocation_pools.0.start == '192.168.0.10' and subnet_result.subnets[0].allocation_pools.0.end == '192.168.0.16')
|
||||||
|
- (subnet_result.subnets[0].allocation_pools.1.start == '192.168.0.2' and subnet_result.subnets[0].allocation_pools.1.end == '192.168.0.8') or
|
||||||
|
(subnet_result.subnets[0].allocation_pools.1.start == '192.168.0.10' and subnet_result.subnets[0].allocation_pools.1.end == '192.168.0.16')
|
||||||
|
|
||||||
|
- name: Delete subnet {{ subnet_name }}
|
||||||
|
openstack.cloud.subnet:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
name: "{{ subnet_name }}"
|
||||||
|
state: absent
|
||||||
|
|
||||||
- name: Delete network {{ network_name }}
|
- name: Delete network {{ network_name }}
|
||||||
openstack.cloud.network:
|
openstack.cloud.network:
|
||||||
cloud: "{{ cloud }}"
|
cloud: "{{ cloud }}"
|
||||||
|
@ -84,6 +84,70 @@
|
|||||||
name: "{{ subnet_name }}"
|
name: "{{ subnet_name }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
|
- name: Create subnet {{ subnet_name }} with multiple allocation pools on network {{ network_name }} from subnet pool {{ subnet_pool_name }}
|
||||||
|
openstack.cloud.subnet:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
network_name: "{{ network_name }}"
|
||||||
|
enable_dhcp: "{{ enable_subnet_dhcp }}"
|
||||||
|
name: "{{ subnet_name }}"
|
||||||
|
state: present
|
||||||
|
cidr: 192.168.42.0/24 # we want specific cidr from subnet pool
|
||||||
|
ip_version: 4
|
||||||
|
subnet_pool: "{{ subnet_pool_name }}"
|
||||||
|
gateway_ip: 192.168.42.1
|
||||||
|
allocation_pools:
|
||||||
|
- start: 192.168.42.2
|
||||||
|
end: 192.168.42.4
|
||||||
|
- start: 192.168.42.6
|
||||||
|
end: 192.168.42.8
|
||||||
|
|
||||||
|
- name: Create subnet {{ subnet_name }} on network {{ network_name }} from subnet pool {{ subnet_pool_name }} again
|
||||||
|
openstack.cloud.subnet:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
network_name: "{{ network_name }}"
|
||||||
|
enable_dhcp: "{{ enable_subnet_dhcp }}"
|
||||||
|
name: "{{ subnet_name }}"
|
||||||
|
state: present
|
||||||
|
cidr: 192.168.42.0/24
|
||||||
|
ip_version: 4
|
||||||
|
subnet_pool: "{{ subnet_pool_name }}"
|
||||||
|
gateway_ip: 192.168.42.1
|
||||||
|
allocation_pools:
|
||||||
|
- start: 192.168.42.2
|
||||||
|
end: 192.168.42.4
|
||||||
|
- start: 192.168.42.6
|
||||||
|
end: 192.168.42.8
|
||||||
|
register: idem2
|
||||||
|
|
||||||
|
- name: Get Subnet Info
|
||||||
|
openstack.cloud.subnets_info:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
name: "{{ subnet_name }}"
|
||||||
|
register: subnet_result
|
||||||
|
|
||||||
|
- name: Verify Subnet Allocation Pools Exist
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- idem2 is not changed
|
||||||
|
- subnet_result.subnets is defined
|
||||||
|
- subnet_result.subnets | length == 1
|
||||||
|
- subnet_result.subnets[0].allocation_pools is defined
|
||||||
|
- subnet_result.subnets[0].allocation_pools | length == 2
|
||||||
|
|
||||||
|
- name: Verify Subnet Allocation Pools
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- (subnet_result.subnets[0].allocation_pools.0.start == '192.168.42.2' and subnet_result.subnets[0].allocation_pools.0.end == '192.168.42.4') or
|
||||||
|
(subnet_result.subnets[0].allocation_pools.0.start == '192.168.42.6' and subnet_result.subnets[0].allocation_pools.0.end == '192.168.42.8')
|
||||||
|
- (subnet_result.subnets[0].allocation_pools.1.start == '192.168.42.2' and subnet_result.subnets[0].allocation_pools.1.end == '192.168.42.4') or
|
||||||
|
(subnet_result.subnets[0].allocation_pools.1.start == '192.168.42.6' and subnet_result.subnets[0].allocation_pools.1.end == '192.168.42.8')
|
||||||
|
|
||||||
|
- name: Delete subnet {{ subnet_name }}
|
||||||
|
openstack.cloud.subnet:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
name: "{{ subnet_name }}"
|
||||||
|
state: absent
|
||||||
|
|
||||||
- name: Delete created subnet pool
|
- name: Delete created subnet pool
|
||||||
openstack.cloud.subnet_pool:
|
openstack.cloud.subnet_pool:
|
||||||
cloud: "{{ cloud }}"
|
cloud: "{{ cloud }}"
|
||||||
|
@ -28,6 +28,12 @@ options:
|
|||||||
- From the subnet pool the last IP that should be assigned to the
|
- From the subnet pool the last IP that should be assigned to the
|
||||||
virtual machines.
|
virtual machines.
|
||||||
type: str
|
type: str
|
||||||
|
allocation_pools:
|
||||||
|
description:
|
||||||
|
- List of allocation pools to assign to the subnet. Each element
|
||||||
|
consists of a 'start' and 'end' value.
|
||||||
|
type: list
|
||||||
|
elements: dict
|
||||||
cidr:
|
cidr:
|
||||||
description:
|
description:
|
||||||
- The CIDR representation of the subnet that should be assigned to
|
- The CIDR representation of the subnet that should be assigned to
|
||||||
@ -299,6 +305,7 @@ class SubnetModule(OpenStackModule):
|
|||||||
dns_nameservers=dict(type='list', elements='str'),
|
dns_nameservers=dict(type='list', elements='str'),
|
||||||
allocation_pool_start=dict(),
|
allocation_pool_start=dict(),
|
||||||
allocation_pool_end=dict(),
|
allocation_pool_end=dict(),
|
||||||
|
allocation_pools=dict(type='list', elements='dict'),
|
||||||
host_routes=dict(type='list', elements='dict'),
|
host_routes=dict(type='list', elements='dict'),
|
||||||
ipv6_ra_mode=dict(choices=ipv6_mode_choices),
|
ipv6_ra_mode=dict(choices=ipv6_mode_choices),
|
||||||
ipv6_address_mode=dict(choices=ipv6_mode_choices),
|
ipv6_address_mode=dict(choices=ipv6_mode_choices),
|
||||||
@ -321,7 +328,9 @@ class SubnetModule(OpenStackModule):
|
|||||||
('cidr', 'use_default_subnet_pool', 'subnet_pool'), True),
|
('cidr', 'use_default_subnet_pool', 'subnet_pool'), True),
|
||||||
],
|
],
|
||||||
mutually_exclusive=[
|
mutually_exclusive=[
|
||||||
('use_default_subnet_pool', 'subnet_pool')
|
('use_default_subnet_pool', 'subnet_pool'),
|
||||||
|
('allocation_pool_start', 'allocation_pools'),
|
||||||
|
('allocation_pool_end', 'allocation_pools')
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -367,7 +376,10 @@ class SubnetModule(OpenStackModule):
|
|||||||
params['project_id'] = project.id
|
params['project_id'] = project.id
|
||||||
if subnet_pool:
|
if subnet_pool:
|
||||||
params['subnet_pool_id'] = subnet_pool.id
|
params['subnet_pool_id'] = subnet_pool.id
|
||||||
|
if self.params['allocation_pool_start']:
|
||||||
params['allocation_pools'] = self._build_pool()
|
params['allocation_pools'] = self._build_pool()
|
||||||
|
else:
|
||||||
|
params['allocation_pools'] = self.params['allocation_pools']
|
||||||
params = self._add_extra_attrs(params)
|
params = self._add_extra_attrs(params)
|
||||||
params = {k: v for k, v in params.items() if v is not None}
|
params = {k: v for k, v in params.items() if v is not None}
|
||||||
return params
|
return params
|
||||||
@ -382,6 +394,10 @@ class SubnetModule(OpenStackModule):
|
|||||||
params['host_routes'].sort(key=lambda r: sorted(r.items()))
|
params['host_routes'].sort(key=lambda r: sorted(r.items()))
|
||||||
subnet['host_routes'].sort(key=lambda r: sorted(r.items()))
|
subnet['host_routes'].sort(key=lambda r: sorted(r.items()))
|
||||||
|
|
||||||
|
if 'allocation_pools' in params:
|
||||||
|
params['allocation_pools'].sort(key=lambda r: sorted(r.items()))
|
||||||
|
subnet['allocation_pools'].sort(key=lambda r: sorted(r.items()))
|
||||||
|
|
||||||
updates = {k: params[k] for k in params if params[k] != subnet[k]}
|
updates = {k: params[k] for k in params if params[k] != subnet[k]}
|
||||||
if self.params['disable_gateway_ip'] and subnet.gateway_ip:
|
if self.params['disable_gateway_ip'] and subnet.gateway_ip:
|
||||||
updates['gateway_ip'] = None
|
updates['gateway_ip'] = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user