NSX|V3: Fix update_subnet issue
Fix the problem where the change of dns_servers or gateway_ip during update_subnet is not pushed to NSX backend. Change-Id: I79af8d7ac593acad0d129b0252ece82372ab5440
This commit is contained in:
parent
3dad033566
commit
21def80a3a
@ -25,9 +25,9 @@ def build_dhcp_server_config(network, subnet, port, project_name):
|
||||
# Prepare the configutation for a new logical DHCP server.
|
||||
server_ip = "%s/%u" % (port['fixed_ips'][0]['ip_address'],
|
||||
netaddr.IPNetwork(subnet['cidr']).prefixlen)
|
||||
dns_servers = subnet['dns_nameservers']
|
||||
if not dns_servers or not validators.is_attr_set(dns_servers):
|
||||
dns_servers = cfg.CONF.nsx_v3.nameservers
|
||||
dns_nameservers = subnet['dns_nameservers']
|
||||
if not dns_nameservers or not validators.is_attr_set(dns_nameservers):
|
||||
dns_nameservers = cfg.CONF.nsx_v3.nameservers
|
||||
gateway_ip = subnet['gateway_ip']
|
||||
if not validators.is_attr_set(gateway_ip):
|
||||
gateway_ip = None
|
||||
@ -58,7 +58,7 @@ def build_dhcp_server_config(network, subnet, port, project_name):
|
||||
return {'name': name,
|
||||
'dhcp_profile_id': cfg.CONF.nsx_v3.dhcp_profile_uuid,
|
||||
'server_ip': server_ip,
|
||||
'dns_servers': dns_servers,
|
||||
'dns_nameservers': dns_nameservers,
|
||||
'domain_name': cfg.CONF.nsx_v3.dns_domain,
|
||||
'gateway_ip': gateway_ip,
|
||||
'options': options,
|
||||
|
@ -476,43 +476,46 @@ class LogicalDhcpServer(AbstractRESTResource):
|
||||
return 'dhcp/servers'
|
||||
|
||||
def _construct_server(self, body, dhcp_profile_id=None, server_ip=None,
|
||||
name=None, dns_servers=None, domain_name=None,
|
||||
gateway_ip=None, options=None, tags=None):
|
||||
name=None, dns_nameservers=None, domain_name=None,
|
||||
gateway_ip=False, options=None, tags=None):
|
||||
if name:
|
||||
body['display_name'] = name
|
||||
if dhcp_profile_id:
|
||||
body['dhcp_profile_id'] = dhcp_profile_id
|
||||
if server_ip:
|
||||
body['ipv4_dhcp_server']['dhcp_server_ip'] = server_ip
|
||||
if dns_servers:
|
||||
body['ipv4_dhcp_server']['dns_nameservers'] = dns_servers
|
||||
if dns_nameservers is not None:
|
||||
# Note that [] is valid for dns_nameservers, means deleting it.
|
||||
body['ipv4_dhcp_server']['dns_nameservers'] = dns_nameservers
|
||||
if domain_name:
|
||||
body['ipv4_dhcp_server']['domain_name'] = domain_name
|
||||
if gateway_ip:
|
||||
if gateway_ip is not False:
|
||||
# Note that None is valid for gateway_ip, means deleting it.
|
||||
body['ipv4_dhcp_server']['gateway_ip'] = gateway_ip
|
||||
if options:
|
||||
body['ipv4_dhcp_server']['options'] = options
|
||||
if tags:
|
||||
body['tags'] = tags
|
||||
|
||||
def create(self, dhcp_profile_id, server_ip, name=None, dns_servers=None,
|
||||
domain_name=None, gateway_ip=None, options=None, tags=None):
|
||||
def create(self, dhcp_profile_id, server_ip, name=None,
|
||||
dns_nameservers=None, domain_name=None, gateway_ip=False,
|
||||
options=None, tags=None):
|
||||
body = {'ipv4_dhcp_server': {}}
|
||||
self._construct_server(body, dhcp_profile_id, server_ip, name,
|
||||
dns_servers, domain_name, gateway_ip, options,
|
||||
tags)
|
||||
dns_nameservers, domain_name, gateway_ip,
|
||||
options, tags)
|
||||
return self._client.create(body=body)
|
||||
|
||||
@utils.retry_upon_exception_nsxv3(
|
||||
exceptions.StaleRevision,
|
||||
max_attempts=cfg.CONF.nsx_v3.retries)
|
||||
def update(self, uuid, dhcp_profile_id=None, server_ip=None, name=None,
|
||||
dns_servers=None, domain_name=None, gateway_ip=None,
|
||||
dns_nameservers=None, domain_name=None, gateway_ip=False,
|
||||
options=None, tags=None):
|
||||
body = self._client.get(uuid)
|
||||
self._construct_server(body, dhcp_profile_id, server_ip, name,
|
||||
dns_servers, domain_name, gateway_ip, options,
|
||||
tags)
|
||||
dns_nameservers, domain_name, gateway_ip,
|
||||
options, tags)
|
||||
return self._client.update(uuid, body=body)
|
||||
|
||||
def create_binding(self, server_uuid, mac, ip, hostname=None,
|
||||
|
@ -1057,11 +1057,11 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
|
||||
def update_subnet(self, context, subnet_id, subnet):
|
||||
updated_subnet = None
|
||||
if (cfg.CONF.nsx_v3.native_dhcp_metadata and
|
||||
'enable_dhcp' in subnet['subnet']):
|
||||
if cfg.CONF.nsx_v3.native_dhcp_metadata:
|
||||
orig_subnet = self.get_subnet(context, subnet_id)
|
||||
enable_dhcp = subnet['subnet']['enable_dhcp']
|
||||
if orig_subnet['enable_dhcp'] != enable_dhcp:
|
||||
enable_dhcp = subnet['subnet'].get('enable_dhcp')
|
||||
if (enable_dhcp is not None and
|
||||
enable_dhcp != orig_subnet['enable_dhcp']):
|
||||
lock = 'nsxv3_network_' + orig_subnet['network_id']
|
||||
with locking.LockManager.get_lock(lock):
|
||||
network = self._get_network(
|
||||
@ -1092,14 +1092,12 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
# Check if needs to update logical DHCP server for native DHCP.
|
||||
if (cfg.CONF.nsx_v3.native_dhcp_metadata and
|
||||
updated_subnet['enable_dhcp']):
|
||||
dns_servers = subnet['subnet'].get('dns_nameservers')
|
||||
gateway_ip = subnet['subnet'].get('gateway_ip')
|
||||
kwargs = {}
|
||||
if (dns_servers and
|
||||
dns_servers != updated_subnet['dns_nameservers']):
|
||||
kwargs['dns_servers'] = dns_servers
|
||||
if gateway_ip and gateway_ip != updated_subnet['gateway_ip']:
|
||||
kwargs['gateway_ip'] = gateway_ip
|
||||
for key in ('dns_nameservers', 'gateway_ip'):
|
||||
if key in subnet['subnet']:
|
||||
value = subnet['subnet'][key]
|
||||
if value != orig_subnet[key]:
|
||||
kwargs[key] = value
|
||||
if kwargs:
|
||||
dhcp_service = nsx_db.get_nsx_service_binding(
|
||||
context.session, orig_subnet['network_id'],
|
||||
|
Loading…
x
Reference in New Issue
Block a user