From c5c14a95355cef408e8dcfeb04b9d796be2af564 Mon Sep 17 00:00:00 2001 From: Dan Wendlandt Date: Thu, 21 Jul 2011 18:54:00 -0700 Subject: remove debugging --- nova/virt/xenapi/vif.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/nova/virt/xenapi/vif.py b/nova/virt/xenapi/vif.py index cc5aa38f5..3604ef8a9 100644 --- a/nova/virt/xenapi/vif.py +++ b/nova/virt/xenapi/vif.py @@ -35,7 +35,6 @@ class XenAPIBridgeDriver(VIFDriver): def get_vif_rec(self, xenapi_session, vm_ref, instance, device, network, network_mapping): - print "bridge = '%s'" % network['bridge'] network_ref = NetworkHelper.find_network_with_bridge(xenapi_session, network['bridge']) rxtx_cap = network_mapping.pop('rxtx_cap') @@ -60,13 +59,11 @@ class XenAPIBridgeDriver(VIFDriver): bridge = network['bridge'] bridge_interface = network['bridge_interface'] - print "in plug with bridge = %s and bridge_interface = %s" % (bridge,bridge_interface) # Check whether bridge already exists # Retrieve network whose name_label is "bridge" network_ref = network_utils.NetworkHelper.find_network_with_name_label( xenapi_session, bridge) - print "got network_ref = %s" % network_ref if network_ref is None: # If bridge does not exists # 1 - create network @@ -87,7 +84,6 @@ class XenAPIBridgeDriver(VIFDriver): raise Exception( _('Found no PIF for device %s') % bridge_interface) # 3 - create vlan for network - print "creating vlan %s" % str(vlan_num) for pif_ref in pifs.keys(): xenapi_session.call_xenapi('VLAN.create', pif_ref, @@ -107,9 +103,6 @@ class XenAPIBridgeDriver(VIFDriver): raise Exception(_("PIF %(pif_rec['uuid'])s for network " "%(bridge)s has VLAN id %(pif_vlan)d. " "Expected %(vlan_num)d") % locals()) - print "vlan is good" - - print "all done" def unplug(self, instance, network, mapping): pass -- cgit From d78d188d41e580ef0e2b4f0116bb0402ce83930f Mon Sep 17 00:00:00 2001 From: Dan Wendlandt Date: Thu, 21 Jul 2011 21:36:26 -0700 Subject: refactor xenapi vif plug to combine plug + get_vif_rec, tested and fixed XenAPIBridgeDriver --- nova/virt/libvirt/vif.py | 13 ++++---- nova/virt/xenapi/vif.py | 75 +++++++++++++++++++++++------------------------ nova/virt/xenapi/vmops.py | 2 +- 3 files changed, 46 insertions(+), 44 deletions(-) diff --git a/nova/virt/libvirt/vif.py b/nova/virt/libvirt/vif.py index bf3579608..07c3973d4 100644 --- a/nova/virt/libvirt/vif.py +++ b/nova/virt/libvirt/vif.py @@ -98,14 +98,17 @@ class LibvirtOpenVswitchDriver(VIFDriver): def plug(self, instance, network, mapping): vif_id = str(instance['id']) + "-" + str(network['id']) dev = "tap-%s" % vif_id + iface_id = "nova-" + 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.libvirt_ovs_integration_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']) + FLAGS.libvirt_ovs_integration_bridge, dev, + '--', 'set', 'Interface', dev, + "external-ids:iface-id=%s" % iface_id, + '--', 'set', 'Interface', dev, + "external-ids:iface-status=active", + '--', 'set', 'Interface', dev, + "external-ids:attached-mac=%s" % mapping['mac']) result = { 'script': '', diff --git a/nova/virt/xenapi/vif.py b/nova/virt/xenapi/vif.py index beee2390d..0557d63af 100644 --- a/nova/virt/xenapi/vif.py +++ b/nova/virt/xenapi/vif.py @@ -26,18 +26,21 @@ from nova.virt.xenapi.network_utils import NetworkHelper FLAGS = flags.FLAGS flags.DEFINE_string('xenapi_ovs_integration_bridge', 'xapi1', - 'Name of Integration Bridge used by Open vSwitch') + 'Name of Integration Bridge used by Open vSwitch') LOG = logging.getLogger("nova.virt.xenapi.vif") class XenAPIBridgeDriver(VIFDriver): - """Combined VIF and Bridge class for XenAPI.""" + """VIF Driver for XenAPI that uses XenAPI to create Networks.""" - def get_vif_rec(self, xenapi_session, vm_ref, instance, device, network, + def plug(self, xenapi_session, vm_ref, instance, device, network, network_mapping): - network_ref = NetworkHelper.find_network_with_bridge(xenapi_session, - network['bridge']) + if network['vlan']: + network_ref = self.ensure_vlan_bridge(xenapi_session, network) + else: + network_ref = NetworkHelper.find_network_with_bridge( + xenapi_session, network['bridge']) rxtx_cap = network_mapping.pop('rxtx_cap') vif_rec = {} vif_rec['device'] = str(device) @@ -51,60 +54,60 @@ class XenAPIBridgeDriver(VIFDriver): {"kbps": str(rxtx_cap * 1024)} if rxtx_cap else {} return vif_rec - def plug(self, xenapi_session, instance, network, mapping): - """Ensure that the bridge exists, if using VLANs""" + def ensure_vlan_bridge(self, xenapi_session, network): + """Ensure that a VLAN bridge exists""" vlan_num = network['vlan'] - if vlan_num is None: - return # no plugging done for non-VLAN networks bridge = network['bridge'] bridge_interface = network['bridge_interface'] - # Check whether bridge already exists # Retrieve network whose name_label is "bridge" - network_ref = network_utils.NetworkHelper.find_network_with_name_label( - xenapi_session, bridge) - + network_ref = NetworkHelper.find_network_with_name_label( + xenapi_session, bridge) if network_ref is None: # If bridge does not exists # 1 - create network description = 'network for nova bridge %s' % bridge network_rec = {'name_label': bridge, - 'name_description': description, - 'other_config': {}} + 'name_description': description, + 'other_config': {}} network_ref = xenapi_session.call_xenapi('network.create', - network_rec) + network_rec) # 2 - find PIF for VLAN NOTE(salvatore-orlando): using double # quotes inside single quotes as xapi filter only support # tokens in double quotes expr = 'field "device" = "%s" and \ field "VLAN" = "-1"' % bridge_interface pifs = xenapi_session.call_xenapi('PIF.get_all_records_where', - expr) + expr) pif_ref = None # Multiple PIF are ok: we are dealing with a pool if len(pifs) == 0: - raise Exception(_('Found no PIF for device %s') % - bridge_interface) - - # 3 - create vlan for network + raise Exception(_('Found no PIF for device %s') % \ + bridge_interface) for pif_ref in pifs.keys(): - xenapi_session.call_xenapi('VLAN.create', pif_ref, - str(vlan_num), network_ref) + xenapi_session.call_xenapi('VLAN.create', + pif_ref, + str(vlan_num), + network_ref) else: # Check VLAN tag is appropriate network_rec = xenapi_session.call_xenapi('network.get_record', - network_ref) + network_ref) # Retrieve PIFs from network for pif_ref in network_rec['PIFs']: # Retrieve VLAN from PIF - pif_rec = xenapi_session.call_xenapi('PIF.get_record', pif_ref) + pif_rec = xenapi_session.call_xenapi('PIF.get_record', + pif_ref) pif_vlan = int(pif_rec['VLAN']) # Raise an exception if VLAN != vlan_num if pif_vlan != vlan_num: - raise Exception(_("PIF %(pif_rec['uuid'])s for network " - "%(bridge)s has VLAN id %(pif_vlan)d. " - "Expected %(vlan_num)d") % locals()) + raise Exception(_( + "PIF %(pif_rec['uuid'])s for network " + "%(bridge)s has VLAN id %(pif_vlan)d. " + "Expected %(vlan_num)d") % locals()) + + return network_ref def unplug(self, instance, network, mapping): pass @@ -113,18 +116,19 @@ class XenAPIBridgeDriver(VIFDriver): class XenAPIOpenVswitchDriver(VIFDriver): """VIF driver for Open vSwitch with XenAPI.""" - def get_vif_rec(self, xenapi_session, vm_ref, instance, device, network, + def plug(self, xenapi_session, vm_ref, instance, device, network, network_mapping): - # with OVS model, always plug into OVS integration bridge - network_ref = NetworkHelper.find_network_with_bridge( - xenapi_session, FLAGS.xenapi_ovs_integration_bridge) + # with OVS model, always plug into an OVS integration bridge + # that is already created + network_ref = NetworkHelper.find_network_with_bridge(xenapi_session, + FLAGS.xenapi_ovs_integration_bridge) vif_rec = {} vif_rec['device'] = str(device) vif_rec['network'] = network_ref vif_rec['VM'] = vm_ref vif_rec['MAC'] = network_mapping['mac'] vif_rec['MTU'] = '1500' - vif_id = str(instance['id']) + "-" + str(network['id']) + vif_id = "nova-" + str(instance['id']) + "-" + str(network['id']) vif_rec['qos_algorithm_type'] = "" vif_rec['qos_algorithm_params'] = {} # OVS on the hypervisor monitors this key and uses it to @@ -132,10 +136,5 @@ class XenAPIOpenVswitchDriver(VIFDriver): vif_rec['other_config'] = {"nicira-iface-id": vif_id} return vif_rec - def plug(self, xenapi_session, instance, network, mapping): - # nothing to do, as this driver assumes that integration bridge - # was created by administrator - pass - def unplug(self, instance, network, mapping): pass diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 4fa59b6b7..bc47ac494 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -1088,7 +1088,7 @@ class VMOps(object): self._session.get_xenapi().VM.get_record(vm_ref) for device, (network, info) in enumerate(network_info): - vif_rec = self.vif_driver.get_vif_rec(self._session, + vif_rec = self.vif_driver.plug(self._session, vm_ref, instance, device, network, info) network_ref = vif_rec['network'] LOG.debug(_('Creating VIF for VM %(vm_ref)s,' \ -- cgit From ff9b31734f15fec0a5b1f9de96dadbda6475a3b4 Mon Sep 17 00:00:00 2001 From: Dan Wendlandt Date: Thu, 21 Jul 2011 21:57:03 -0700 Subject: for libvirt OVS driver, do not make device if it exists already --- nova/virt/libvirt/vif.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/nova/virt/libvirt/vif.py b/nova/virt/libvirt/vif.py index 07c3973d4..02bbcc194 100644 --- a/nova/virt/libvirt/vif.py +++ b/nova/virt/libvirt/vif.py @@ -98,17 +98,18 @@ class LibvirtOpenVswitchDriver(VIFDriver): def plug(self, instance, network, mapping): vif_id = str(instance['id']) + "-" + str(network['id']) dev = "tap-%s" % vif_id - iface_id = "nova-" + vif_id - utils.execute('sudo', 'ip', 'tuntap', 'add', dev, 'mode', 'tap') - utils.execute('sudo', 'ip', 'link', 'set', dev, 'up') + if not linux_net._device_exists(dev): + iface_id = "nova-" + 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.libvirt_ovs_integration_bridge, dev, - '--', 'set', 'Interface', dev, - "external-ids:iface-id=%s" % iface_id, - '--', 'set', 'Interface', dev, - "external-ids:iface-status=active", - '--', 'set', 'Interface', dev, - "external-ids:attached-mac=%s" % mapping['mac']) + FLAGS.libvirt_ovs_integration_bridge, dev, + '--', 'set', 'Interface', dev, + "external-ids:iface-id=%s" % iface_id, + '--', 'set', 'Interface', dev, + "external-ids:iface-status=active", + '--', 'set', 'Interface', dev, + "external-ids:attached-mac=%s" % mapping['mac']) result = { 'script': '', -- cgit From 162563d48d5b5b4626c20de7fd93dd17ea31f123 Mon Sep 17 00:00:00 2001 From: Dan Wendlandt Date: Thu, 21 Jul 2011 22:17:37 -0700 Subject: use new 'create_vlan' field in XenAPIBridgeDriver --- nova/virt/xenapi/vif.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/virt/xenapi/vif.py b/nova/virt/xenapi/vif.py index 0557d63af..f5fb789ff 100644 --- a/nova/virt/xenapi/vif.py +++ b/nova/virt/xenapi/vif.py @@ -36,7 +36,7 @@ class XenAPIBridgeDriver(VIFDriver): def plug(self, xenapi_session, vm_ref, instance, device, network, network_mapping): - if network['vlan']: + if network_mapping.get('create_vlan'): network_ref = self.ensure_vlan_bridge(xenapi_session, network) else: network_ref = NetworkHelper.find_network_with_bridge( -- cgit