From 946a627c86f4f056f1752a2cd28debe28a41f898 Mon Sep 17 00:00:00 2001 From: Shih-Hao Li Date: Wed, 9 Nov 2016 11:06:06 -0800 Subject: [PATCH] NSXv3: Fix DHCP upgrade script During neutron upgrade, the new static bindings of existing VMs are not stored in neutron DB. This causes problem when later deleting those VMs. There is no entry in the neutron DB, thus the corresponding static binding in the backend are not deleted. Change-Id: Ideb2b33f7498b9f98a61d034d3fc8097b94eb3e9 --- .../admin/plugins/nsxv3/resources/dhcp_binding.py | 10 +++++++--- .../shell/admin/plugins/nsxv3/resources/utils.py | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/vmware_nsx/shell/admin/plugins/nsxv3/resources/dhcp_binding.py b/vmware_nsx/shell/admin/plugins/nsxv3/resources/dhcp_binding.py index a6bd8f8a18..d82ac420f3 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv3/resources/dhcp_binding.py +++ b/vmware_nsx/shell/admin/plugins/nsxv3/resources/dhcp_binding.py @@ -118,7 +118,8 @@ def nsx_update_dhcp_bindings(resource, event, trigger, **kwargs): lswitch_id = neutron_client.net_id_to_lswitch_id(network_id) bindings = port_bindings.get(lswitch_id, []) bindings.append((port['id'], port['mac_address'], - fixed_ip['ip_address'])) + fixed_ip['ip_address'], + fixed_ip['subnet_id'])) port_bindings[lswitch_id] = bindings break # process only the first IPv4 address @@ -127,14 +128,17 @@ def nsx_update_dhcp_bindings(resource, event, trigger, **kwargs): dhcp_server_id = server_bindings.get(lswitch_id) if not dhcp_server_id: continue - for (port_id, mac, ip) in bindings: + for (port_id, mac, ip, subnet_id) in bindings: hostname = 'host-%s' % ip.replace('.', '-') options = {'option121': {'static_routes': [ {'network': '%s' % cfg.CONF.nsx_v3.native_metadata_route, 'next_hop': ip}]}} - dhcp_server_resource.create_binding( + binding = dhcp_server_resource.create_binding( dhcp_server_id, mac, ip, hostname, cfg.CONF.nsx_v3.dhcp_lease_time, options) + # Add DHCP static binding in neutron DB. + neutron_client.add_dhcp_static_binding( + port_id, subnet_id, ip, dhcp_server_id, binding['id']) LOG.info(_LI("Added DHCP binding (mac: %(mac)s, ip: %(ip)s) " "for neutron port %(port)s"), {'mac': mac, 'ip': ip, 'port': port_id}) diff --git a/vmware_nsx/shell/admin/plugins/nsxv3/resources/utils.py b/vmware_nsx/shell/admin/plugins/nsxv3/resources/utils.py index 8149beed8e..9b0d46f874 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv3/resources/utils.py +++ b/vmware_nsx/shell/admin/plugins/nsxv3/resources/utils.py @@ -66,6 +66,12 @@ class NeutronDbClient(db_base_plugin_v2.NeutronDbPluginV2): self.context.session, network_id, port_id, nsx_constants.SERVICE_DHCP, server_id) + def add_dhcp_static_binding(self, port_id, subnet_id, ip_address, + server_id, binding_id): + return nsx_db.add_neutron_nsx_dhcp_binding( + self.context.session, port_id, subnet_id, ip_address, server_id, + binding_id) + class NsxV3PluginWrapper(plugin.NsxV3Plugin): def __init__(self):