Merge "Only apply necessary changes to subnets"
This commit is contained in:
commit
4490e008c4
@ -37,6 +37,7 @@
|
|||||||
name: "{{ subnet_name }}"
|
name: "{{ subnet_name }}"
|
||||||
state: present
|
state: present
|
||||||
cidr: 192.168.0.0/24
|
cidr: 192.168.0.0/24
|
||||||
|
gateway_ip: 192.168.0.1
|
||||||
allocation_pool_start: 192.168.0.2
|
allocation_pool_start: 192.168.0.2
|
||||||
allocation_pool_end: 192.168.0.8
|
allocation_pool_end: 192.168.0.8
|
||||||
|
|
||||||
|
@ -221,35 +221,37 @@ class SubnetModule(OpenStackModule):
|
|||||||
no_gateway_ip = self.params['no_gateway_ip']
|
no_gateway_ip = self.params['no_gateway_ip']
|
||||||
dns = self.params['dns_nameservers']
|
dns = self.params['dns_nameservers']
|
||||||
host_routes = self.params['host_routes']
|
host_routes = self.params['host_routes']
|
||||||
curr_pool = dict(start=pool_start, end=pool_end)
|
if pool_start and pool_end:
|
||||||
|
pool = dict(start=pool_start, end=pool_end)
|
||||||
|
else:
|
||||||
|
pool = None
|
||||||
|
|
||||||
|
changes = dict()
|
||||||
if subnet['enable_dhcp'] != enable_dhcp:
|
if subnet['enable_dhcp'] != enable_dhcp:
|
||||||
return True
|
changes['enable_dhcp'] = enable_dhcp
|
||||||
if subnet_name and subnet['name'] != subnet_name:
|
if subnet_name and subnet['name'] != subnet_name:
|
||||||
return True
|
changes['subnet_name'] = subnet_name
|
||||||
if not subnet['allocation_pools'] and pool_start and pool_end:
|
if pool and (not subnet['allocation_pools'] or subnet['allocation_pools'] != [pool]):
|
||||||
return True
|
changes['allocation_pools'] = [pool]
|
||||||
if subnet['allocation_pools'] != [curr_pool]:
|
|
||||||
return True
|
|
||||||
if gateway_ip and subnet['gateway_ip'] != gateway_ip:
|
if gateway_ip and subnet['gateway_ip'] != gateway_ip:
|
||||||
return True
|
changes['gateway_ip'] = gateway_ip
|
||||||
if dns and sorted(subnet['dns_nameservers']) != sorted(dns):
|
if dns and sorted(subnet['dns_nameservers']) != sorted(dns):
|
||||||
return True
|
changes['dns_nameservers'] = dns
|
||||||
if host_routes:
|
if host_routes:
|
||||||
curr_hr = sorted(subnet['host_routes'], key=lambda t: t.keys())
|
curr_hr = sorted(subnet['host_routes'], key=lambda t: t.keys())
|
||||||
new_hr = sorted(host_routes, key=lambda t: t.keys())
|
new_hr = sorted(host_routes, key=lambda t: t.keys())
|
||||||
if curr_hr != new_hr:
|
if curr_hr != new_hr:
|
||||||
return True
|
changes['host_routes'] = host_routes
|
||||||
if no_gateway_ip and subnet['gateway_ip']:
|
if no_gateway_ip and subnet['gateway_ip']:
|
||||||
return True
|
changes['disable_gateway_ip'] = no_gateway_ip
|
||||||
return False
|
return changes
|
||||||
|
|
||||||
def _system_state_change(self, subnet, filters=None):
|
def _system_state_change(self, subnet, filters=None):
|
||||||
state = self.params['state']
|
state = self.params['state']
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
if not subnet:
|
if not subnet:
|
||||||
return True
|
return True
|
||||||
return self._needs_update(subnet, filters)
|
return bool(self._needs_update(subnet, filters))
|
||||||
if state == 'absent' and subnet:
|
if state == 'absent' and subnet:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
@ -334,15 +336,9 @@ class SubnetModule(OpenStackModule):
|
|||||||
subnet = self.conn.create_subnet(network_name, **kwargs)
|
subnet = self.conn.create_subnet(network_name, **kwargs)
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
if self._needs_update(subnet, filters):
|
changes = self._needs_update(subnet, filters)
|
||||||
subnet = self.conn.update_subnet(subnet['id'],
|
if changes:
|
||||||
subnet_name=subnet_name,
|
subnet = self.conn.update_subnet(subnet['id'], **changes)
|
||||||
enable_dhcp=enable_dhcp,
|
|
||||||
gateway_ip=gateway_ip,
|
|
||||||
disable_gateway_ip=no_gateway_ip,
|
|
||||||
dns_nameservers=dns,
|
|
||||||
allocation_pools=pool,
|
|
||||||
host_routes=host_routes)
|
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
changed = False
|
changed = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user