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
This commit is contained in:
parent
921ff894a3
commit
946a627c86
@ -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})
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user