Merge "Add a VIF driver for IOVisor engine"

This commit is contained in:
Jenkins 2013-07-17 16:08:39 +00:00 committed by Gerrit Code Review
commit 8e7b06d4f7
4 changed files with 113 additions and 0 deletions

View File

@ -39,6 +39,9 @@ ovs-ofctl: CommandFilter, ovs-ofctl, root
# nova/network/linux_net.py: 'ivs-ctl', ....
ivs-ctl: CommandFilter, ivs-ctl, root
# nova/virt/libvirt/vif.py: 'ifc_ctl', ...
ifc_ctl: CommandFilter, /opt/pg/bin/0/ifc_ctl, root
# nova/network/linux_net.py: 'ebtables', '-D' ...
# nova/network/linux_net.py: 'ebtables', '-I' ...
ebtables: CommandFilter, ebtables, root

View File

@ -31,6 +31,7 @@ def ensure_string_keys(d):
# Constants for the 'vif_type' field in VIF class
VIF_TYPE_OVS = 'ovs'
VIF_TYPE_IVS = 'ivs'
VIF_TYPE_IOVISOR = 'iovisor'
VIF_TYPE_BRIDGE = 'bridge'
VIF_TYPE_802_QBG = '802.1qbg'
VIF_TYPE_802_QBH = '802.1qbh'

View File

@ -158,6 +158,27 @@ class LibvirtVifTestCase(test.TestCase):
instanceid="ddd-eee-fff")
}
net_iovisor = {
'cidr': '101.168.1.0/24',
'cidr_v6': '101:1db9::/64',
'gateway_v6': '101:1db9::1',
'netmask_v6': '64',
'netmask': '255.255.255.0',
'interface': 'eth0',
'vlan': 99,
'gateway': '101.168.1.1',
'broadcast': '101.168.1.255',
'dns1': '8.8.8.8',
'id': 'network-id-xxx-yyy-zzz'
}
mapping_iovisor = {
'mac': 'ca:fe:de:ad:be:ef',
'vif_uuid': 'vif-xxx-yyy-zzz',
'vif_devname': 'tap-xxx-yyy-zzz',
'vif_type': network_model.VIF_TYPE_IOVISOR,
}
mapping_none = {
'mac': 'ca:fe:de:ad:be:ef',
'gateway_v6': net_bridge['gateway_v6'],
@ -674,6 +695,27 @@ class LibvirtVifTestCase(test.TestCase):
self.assertTrue(profile_id_found)
def test_generic_iovisor_driver(self):
def get_connection():
return fakelibvirt.Connection("qemu:///session",
False)
d = vif.LibvirtGenericVIFDriver(get_connection)
self.flags(firewall_driver="nova.virt.firewall.NoopFirewallDriver")
xml = self._get_instance_xml(d,
self.net_iovisor,
self.mapping_iovisor)
doc = etree.fromstring(xml)
ret = doc.findall('./devices/interface')
self.assertEqual(len(ret), 1)
node = ret[0]
ret = node.findall("filterref")
self.assertEqual(len(ret), 0)
self.assertEqual(node.get("type"), "ethernet")
tap_name = node.find("target").get("dev")
self.assertEqual(tap_name, self.mapping_iovisor['vif_devname'])
mac = node.find("mac").get("address")
self.assertEqual(mac, self.mapping_iovisor['mac'])
def test_generic_8021qbg_driver(self):
def get_connection():
return fakelibvirt.Connection("qemu:///session",

View File

@ -306,6 +306,19 @@ class LibvirtGenericVIFDriver(LibvirtBaseVIFDriver):
return conf
def get_config_iovisor(self, instance, network, mapping, image_meta,
inst_type):
conf = super(LibvirtGenericVIFDriver,
self).get_config(instance,
network,
mapping,
image_meta, inst_type)
dev = self.get_vif_devname(mapping)
designer.set_vif_host_backend_ethernet_config(conf, dev)
return conf
def get_config(self, instance, network, mapping, image_meta, inst_type):
vif_type = mapping.get('vif_type')
@ -343,6 +356,11 @@ class LibvirtGenericVIFDriver(LibvirtBaseVIFDriver):
network, mapping,
image_meta,
inst_type)
elif vif_type == network_model.VIF_TYPE_IOVISOR:
return self.get_config_iovisor(instance,
network, mapping,
image_meta,
inst_type)
else:
raise exception.NovaException(
_("Unexpected vif_type=%s") % vif_type)
@ -480,6 +498,30 @@ class LibvirtGenericVIFDriver(LibvirtBaseVIFDriver):
super(LibvirtGenericVIFDriver,
self).plug(instance, vif)
def plug_iovisor(self, instance, vif):
"""Plug using PLUMgrid IO Visor Driver
Connect a network device to their respective
Virtual Domain in PLUMgrid Platform.
"""
super(LibvirtGenericVIFDriver,
self).plug(instance, vif)
network, mapping = vif
dev = self.get_vif_devname(mapping)
iface_id = mapping['vif_uuid']
linux_net.create_tap_dev(dev)
net_id = network['id']
tenant_id = instance["project_id"]
try:
utils.execute('ifc_ctl', 'gateway', 'add_port', dev,
run_as_root=True)
utils.execute('ifc_ctl', 'gateway', 'ifup', dev,
'access_vm', mapping['label'] + "_" + iface_id,
mapping['mac'], 'pgtag2=%s' % net_id,
'pgtag1=%s' % tenant_id, run_as_root=True)
except exception.ProcessExecutionError:
LOG.exception(_("Failed while plugging vif"), instance=instance)
def plug(self, instance, vif):
network, mapping = vif
vif_type = mapping.get('vif_type')
@ -503,6 +545,8 @@ class LibvirtGenericVIFDriver(LibvirtBaseVIFDriver):
self.plug_802qbh(instance, vif)
elif vif_type == network_model.VIF_TYPE_IVS:
self.plug_ivs(instance, vif)
elif vif_type == network_model.VIF_TYPE_IOVISOR:
self.plug_iovisor(instance, vif)
else:
raise exception.NovaException(
_("Unexpected vif_type=%s") % vif_type)
@ -608,6 +652,27 @@ class LibvirtGenericVIFDriver(LibvirtBaseVIFDriver):
super(LibvirtGenericVIFDriver,
self).unplug(instance, vif)
def unplug_iovisor(self, instance, vif):
"""Unplug using PLUMgrid IO Visor Driver
Delete network device and to their respective
connection to the Virtual Domain in PLUMgrid Platform.
"""
super(LibvirtGenericVIFDriver,
self).unplug(instance, vif)
network, mapping = vif
iface_id = mapping['vif_uuid']
dev = self.get_vif_devname(mapping)
try:
utils.execute('ifc_ctl', 'gateway', 'ifdown',
dev, 'access_vm', mapping['label'] + "_" + iface_id,
mapping['mac'], run_as_root=True)
utils.execute('ifc_ctl', 'gateway', 'del_port', dev,
run_as_root=True)
linux_net.delete_net_dev(dev)
except exception.ProcessExecutionError:
LOG.exception(_("Failed while unplugging vif"), instance=instance)
def unplug(self, instance, vif):
network, mapping = vif
vif_type = mapping.get('vif_type')
@ -631,6 +696,8 @@ class LibvirtGenericVIFDriver(LibvirtBaseVIFDriver):
self.unplug_802qbh(instance, vif)
elif vif_type == network_model.VIF_TYPE_IVS:
self.unplug_ivs(instance, vif)
elif vif_type == network_model.VIF_TYPE_IOVISOR:
self.unplug_iovisor(instance, vif)
else:
raise exception.NovaException(
_("Unexpected vif_type=%s") % vif_type)