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):