From 709cc0c154ae3522033ad2bf79518c71aa9aabc5 Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Sun, 31 Jul 2016 02:17:31 -0700 Subject: [PATCH] DVS: provide a dhcp_driver class for plugin Enable the plugin to override the base DHCP DeviceManager. This patch does the following: 1. provide a class that overrides the default. This is required so that we can override the device_manager class 2. Introduces two new configuration variables: - dhcp_override_mac - enables the driver to override the neutron port mac address. This should be used when the DHCP agent is running on a VM that is connected to the DVS. This can save the admin the bother of setting 'forged transmits' to enable. This should be the MAC address of the VM - dvs_integration_bridge - the name of the bridge to plug the interface. This may be a dedicated bride that is connected to the DVS This enables one to use the simple DVS plugin and actaully get a DHCP address. NOTE: a port group that can see all of the tags should be configured. This is the port group that the dvs_integration_bridge should be attached to. DocImpact Change-Id: I6b0742b363e551e09a8c44fd59c698a90d180efd Depends-on: cee3664a77487750c2c5f68f1df97f3d80362e17 --- devstack/lib/vmware_dvs | 1 + vmware_nsx/plugins/dvs/dhcp.py | 73 ++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 vmware_nsx/plugins/dvs/dhcp.py diff --git a/devstack/lib/vmware_dvs b/devstack/lib/vmware_dvs index 87317a31c0..c0ed655fe9 100644 --- a/devstack/lib/vmware_dvs +++ b/devstack/lib/vmware_dvs @@ -81,6 +81,7 @@ function neutron_plugin_configure_dhcp_agent { iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata True iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network True iniset $Q_DHCP_CONF_FILE DEFAULT ovs_integration_bridge $OVS_BRIDGE + iniset $Q_DHCP_CONF_FILE DEFAULT dhcp_driver "vmware_nsx.plugins.dvs.dhcp.Dnsmasq" } function neutron_plugin_configure_l3_agent { diff --git a/vmware_nsx/plugins/dvs/dhcp.py b/vmware_nsx/plugins/dvs/dhcp.py new file mode 100644 index 0000000000..4e3ef1fae2 --- /dev/null +++ b/vmware_nsx/plugins/dvs/dhcp.py @@ -0,0 +1,73 @@ +# Copyright 2012 OpenStack Foundation +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from oslo_config import cfg +from oslo_log import log as logging + +from neutron.agent.common import ovs_lib +from neutron.agent.linux import dhcp + +LOG = logging.getLogger(__name__) + +OPTS = [ + cfg.StrOpt('dvs_integration_bridge', + default='br-dvs', + help=_('Name of Open vSwitch bridge to use for DVS networks')), + cfg.StrOpt('dhcp_override_mac', + help=_('Override the MAC address of the DHCP interface')), +] + +cfg.CONF.register_opts(OPTS) + + +class DeviceManager(dhcp.DeviceManager): + + def plug(self, network, port, interface_name): + mac_address = (cfg.CONF.dhcp_override_mac + if cfg.CONF.dhcp_override_mac + else port.mac_address) + self.driver.plug(network.id, + port.id, + interface_name, + mac_address, + namespace=network.namespace, + mtu=network.get('mtu'), + bridge=cfg.CONF.dvs_integration_bridge) + vlan_tag = getattr(network, 'provider:segmentation_id', + None) + # Treat vlans + if vlan_tag and vlan_tag != 0: + br_dvs = ovs_lib.OVSBridge(self.conf.dvs_integration_bridge) + # When ovs_use_veth is set to True, the DEV_NAME_PREFIX + # will be changed from 'tap' to 'ns-' in + # OVSInterfaceDriver + dvs_port_name = interface_name.replace('ns-', 'tap') + br_dvs.set_db_attribute("Port", dvs_port_name, "tag", vlan_tag) + + def unplug(self, device_name, network): + self.driver.unplug( + device_name, bridge=cfg.CONF.dvs_integration_bridge, + namespace=network.namespace) + + +class Dnsmasq(dhcp.Dnsmasq): + + def __init__(self, conf, network, process_monitor, + version=None, plugin=None): + super(Dnsmasq, self).__init__(conf, network, process_monitor, + version=version, plugin=plugin) + # Using the DeviceManager that enables us to directly plug the OVS + LOG.debug("Using the DVS DeviceManager") + self.device_manager = DeviceManager(conf, plugin)