summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Wendlandt <dan@nicira.com>2011-07-19 00:26:58 -0700
committerDan Wendlandt <dan@nicira.com>2011-07-19 00:26:58 -0700
commit7e4a23c489946eb5e6a1568d197cab34367d8078 (patch)
treea132db3c1366c91989976f71d1407a656da99f7e
parentdea12df6165c3417efb0a3959462b9080be1bbca (diff)
merge of ovs L2 branch
-rw-r--r--nova/compute/manager.py20
-rw-r--r--nova/network/manager.py2
-rw-r--r--nova/virt/libvirt.xml.template4
-rw-r--r--nova/virt/libvirt/connection.py23
-rw-r--r--nova/virt/libvirt/vif.py41
-rw-r--r--nova/virt/xenapi_conn.py2
6 files changed, 76 insertions, 16 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 753240614..863e6bc18 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -293,7 +293,7 @@ class ComputeManager(manager.SchedulerDependentManager):
network_info = self.network_api.allocate_for_instance(context,
instance, vpn=is_vpn)
LOG.debug(_("instance network_info: |%s|"), network_info)
- self.driver.setup_vif_network(context, instance, network_info)
+ self.driver.setup_vif_network(context, instance)
else:
# TODO(tr3buchet) not really sure how this should be handled.
# virt requires network_info to be passed in but stub_network
@@ -348,7 +348,10 @@ class ComputeManager(manager.SchedulerDependentManager):
{'action_str': action_str, 'instance_id': instance_id},
context=context)
+ network_info = None
if not FLAGS.stub_network:
+ network_info = self.network_api.get_instance_nw_info(context,
+ instance)
self.network_api.deallocate_for_instance(context, instance)
volumes = instance.get('volumes') or []
@@ -360,7 +363,7 @@ class ComputeManager(manager.SchedulerDependentManager):
self.db.instance_destroy(context, instance_id)
raise exception.Error(_('trying to destroy already destroyed'
' instance: %s') % instance_id)
- self.driver.destroy(instance)
+ self.driver.destroy(instance,network_info)
if action_str == 'Terminating':
terminate_volumes(self.db, context, instance_id)
@@ -406,7 +409,9 @@ class ComputeManager(manager.SchedulerDependentManager):
self._update_state(context, instance_id, power_state.BUILDING)
- self.driver.destroy(instance_ref)
+ network_info = self.network_api.get_instance_nw_info(context,
+ instance_ref)
+ self.driver.destroy(instance_ref,network_info)
image_ref = kwargs.get('image_ref')
instance_ref.image_ref = image_ref
instance_ref.injected_files = kwargs.get('injected_files', [])
@@ -666,7 +671,10 @@ class ComputeManager(manager.SchedulerDependentManager):
"""Destroys the source instance."""
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
- self.driver.destroy(instance_ref)
+
+ network_info = self.network_api.get_instance_nw_info(context,
+ instance_ref)
+ self.driver.destroy(instance_ref,network_info)
usage_info = utils.usage_from_instance(instance_ref)
notifier_api.notify('compute.%s' % self.host,
'compute.instance.resize.confirm',
@@ -685,7 +693,9 @@ class ComputeManager(manager.SchedulerDependentManager):
instance_ref = self.db.instance_get(context, instance_id)
migration_ref = self.db.migration_get(context, migration_id)
- self.driver.destroy(instance_ref)
+ network_info = self.network_api.get_instance_nw_info(context,
+ instance_ref)
+ self.driver.destroy(instance_ref,network_info)
topic = self.db.queue_get_for(context, FLAGS.compute_topic,
instance_ref['host'])
rpc.cast(context, topic,
diff --git a/nova/network/manager.py b/nova/network/manager.py
index 0689759d7..b64afae5c 100644
--- a/nova/network/manager.py
+++ b/nova/network/manager.py
@@ -351,6 +351,8 @@ class NetworkManager(manager.SchedulerDependentManager):
networks = self.db.network_get_all(context)
# return only networks which are not vlan networks and have host set
+ for n in networks:
+ print "net: host = %s vlan = %s" % (n['host'],n['vlan'])
return [network for network in networks if
not network['vlan'] and network['host']]
diff --git a/nova/virt/libvirt.xml.template b/nova/virt/libvirt.xml.template
index ea27e5fd7..efcb96d15 100644
--- a/nova/virt/libvirt.xml.template
+++ b/nova/virt/libvirt.xml.template
@@ -92,13 +92,13 @@
#end if
#for $nic in $nics
- #if $vif_type='ethernet'
+ #if $vif_type=='ethernet'
<interface type='ethernet'>
<target dev='${nic.name}' />
<mac address='${nic.mac_address}' />
<script path='${nic.script}' />
</interface>
- #else if $vif_type='802.1Qbh'
+ #else if $vif_type=='802.1Qbh'
<interface type='direct'>
<mac address=${nic.mac_address}/>
<source dev=${nic.device_name} mode='private'/>
diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py
index 15ad85176..36a6d62fe 100644
--- a/nova/virt/libvirt/connection.py
+++ b/nova/virt/libvirt/connection.py
@@ -261,11 +261,13 @@ class LibvirtConnection(driver.ComputeDriver):
def setup_vif_network(self, ctxt, instance_id):
"""Set up VIF networking on the host."""
- networks = db.network_get_all_by_instance(ctxt, instance_id)
- for network in networks:
- self.vif_driver.plug(network)
+ # FIXME: this is dying because DB has no networks for instances
+ #networks = db.network_get_all_by_instance(ctxt, instance_id)
+ #for network in networks:
+ # self.vif_driver.plug(network)
+ pass
- def destroy(self, instance, cleanup=True):
+ def destroy(self, instance, network_info, cleanup=True):
instance_name = instance['name']
try:
@@ -309,6 +311,14 @@ class LibvirtConnection(driver.ComputeDriver):
locals())
raise
+ try:
+ for (network, mapping) in network_info:
+ self.vif_driver.unplug(instance, network, mapping)
+ except:
+ LOG.warning("Failed while unplugging vif of instance '%s'" % \
+ instance['name'])
+ raise
+
def _wait_for_destroy():
"""Called at an interval until the VM is gone."""
instance_name = instance['name']
@@ -890,9 +900,12 @@ class LibvirtConnection(driver.ComputeDriver):
address = mapping['ips'][0]['ip']
netmask = mapping['ips'][0]['netmask']
address_v6 = None
+ gateway_v6 = None
+ netmask_v6 = None
if FLAGS.use_ipv6:
address_v6 = mapping['ip6s'][0]['ip']
netmask_v6 = mapping['ip6s'][0]['netmask']
+ gateway_v6 = mapping['gateway6']
net_info = {'name': 'eth%d' % ifc_num,
'address': address,
'netmask': netmask,
@@ -900,7 +913,7 @@ class LibvirtConnection(driver.ComputeDriver):
'broadcast': mapping['broadcast'],
'dns': mapping['dns'],
'address_v6': address_v6,
- 'gateway6': mapping['gateway6'],
+ 'gateway6': gateway_v6,
'netmask_v6': netmask_v6}
nets.append(net_info)
diff --git a/nova/virt/libvirt/vif.py b/nova/virt/libvirt/vif.py
index 50c2d444c..8ce1f1f7e 100644
--- a/nova/virt/libvirt/vif.py
+++ b/nova/virt/libvirt/vif.py
@@ -1,6 +1,7 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (C) 2011 Midokura KK
+# Copyright (C) 2011 Nicira, Inc
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -20,6 +21,7 @@
from nova import flags
from nova.network import linux_net
from nova.virt.libvirt import netutils
+from nova import utils
from nova.virt.vif import VIFDriver
FLAGS = flags.FLAGS
@@ -74,7 +76,7 @@ class LibvirtBridge(LibvirtVIF):
return result
-
+
class LibvirtBridgeDriver(VIFDriver, LibvirtBridge):
"""VIF driver for Linux bridge."""
@@ -83,7 +85,7 @@ class LibvirtBridgeDriver(VIFDriver, LibvirtBridge):
linux_net.ensure_bridge(network['bridge'],
network['bridge_interface'])
- def unplug(self, network):
+ def unplug(self, instance, network, mapping):
pass
@@ -95,5 +97,38 @@ class LibvirtVlanBridgeDriver(VIFDriver, LibvirtBridge):
linux_net.ensure_vlan_bridge(network['vlan'], network['bridge'],
network['bridge_interface'])
- def unplug(self, network):
+ def unplug(self, instance, network, mapping):
pass
+
+class LibvirtOpenVswitchDriver(VIFDriver):
+ """VIF driver for Open vSwitch."""
+
+ def get_configurations(self, instance, network, mapping):
+ vif_id = str(instance['id']) + "-" + str(network['id'])
+ dev = "tap-%s" % vif_id
+ utils.execute('sudo','ip','tuntap','add', dev, 'mode','tap')
+ utils.execute('sudo','ip','link','set', dev, 'up')
+ utils.execute('sudo', 'ovs-vsctl','--', '--may-exist', 'add-port',
+ FLAGS.flat_network_bridge, dev,
+ '--', 'set', 'Interface', dev, "external-ids:iface-id=%s" % vif_id,
+ '--', 'set', 'Interface', dev, "external-ids:iface-status=active",
+ '--', 'set', 'Interface', dev, "external-ids:attached-mac=%s" % \
+ mapping['mac'])
+
+ result = {
+ 'script': '',
+ 'name': dev,
+ 'mac_address' : mapping['mac']
+ }
+ print "using result = %s" % str(result)
+ return result
+
+
+ def plug(self, network):
+ pass
+
+ def unplug(self, instance, network, mapping):
+ vif_id = str(instance['id']) + "-" + str(network['id'])
+ dev = "tap-%s" % vif_id
+ utils.execute('sudo', 'ovs-vsctl','del-port', FLAGS.flat_network_bridge, dev)
+ utils.execute('sudo','ip','link','delete', dev)
diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py
index cd4dc1b60..09914bc1c 100644
--- a/nova/virt/xenapi_conn.py
+++ b/nova/virt/xenapi_conn.py
@@ -224,7 +224,7 @@ class XenAPIConnection(driver.ComputeDriver):
"""
self._vmops.inject_file(instance, b64_path, b64_contents)
- def destroy(self, instance):
+ def destroy(self, instance, network_info):
"""Destroy VM instance"""
self._vmops.destroy(instance)