summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-01-28 13:11:37 +0000
committerGerrit Code Review <review@openstack.org>2013-01-28 13:11:37 +0000
commited57c4e87f68ea172f8350e9f0b855f30a95170c (patch)
treeee76304555881f2424c8c2f6f53496d485a8d228
parente1ce3878b951ea491548c129453bb84a77205649 (diff)
parentfff46247c058e69fcdf25e6845c34509f4688c30 (diff)
downloadnova-ed57c4e87f68ea172f8350e9f0b855f30a95170c.tar.gz
nova-ed57c4e87f68ea172f8350e9f0b855f30a95170c.tar.xz
nova-ed57c4e87f68ea172f8350e9f0b855f30a95170c.zip
Merge "VMware Compute Driver Networking"
-rw-r--r--nova/tests/test_vmwareapi.py6
-rw-r--r--nova/virt/vmwareapi/driver.py14
-rw-r--r--nova/virt/vmwareapi/fake.py14
-rw-r--r--nova/virt/vmwareapi/network_util.py15
-rw-r--r--nova/virt/vmwareapi/vmops.py57
5 files changed, 92 insertions, 14 deletions
diff --git a/nova/tests/test_vmwareapi.py b/nova/tests/test_vmwareapi.py
index 577d227ce..8db4c80ad 100644
--- a/nova/tests/test_vmwareapi.py
+++ b/nova/tests/test_vmwareapi.py
@@ -155,6 +155,12 @@ class VMwareAPIVMTestCase(test.TestCase):
instances = self.conn.list_instances()
self.assertEquals(len(instances), 1)
+ def test_list_interfaces(self):
+ self._create_vm()
+ interfaces = self.conn.list_interfaces(1)
+ self.assertEquals(len(interfaces), 1)
+ self.assertEquals(interfaces[0], 4000)
+
def test_spawn(self):
self._create_vm()
info = self.conn.get_info({'name': 1})
diff --git a/nova/virt/vmwareapi/driver.py b/nova/virt/vmwareapi/driver.py
index 4000f1f9c..d5a7e5875 100644
--- a/nova/virt/vmwareapi/driver.py
+++ b/nova/virt/vmwareapi/driver.py
@@ -200,6 +200,10 @@ class VMwareESXDriver(driver.ComputeDriver):
"""This method is supported only by libvirt."""
return
+ def inject_network_info(self, instance, network_info):
+ """inject network info for specified instance."""
+ self._vmops.inject_network_info(instance, network_info)
+
def plug_vifs(self, instance, network_info):
"""Plug VIFs into networks."""
self._vmops.plug_vifs(instance, network_info)
@@ -208,6 +212,16 @@ class VMwareESXDriver(driver.ComputeDriver):
"""Unplug VIFs from networks."""
self._vmops.unplug_vifs(instance, network_info)
+ def list_interfaces(self, instance_name):
+ """
+ Return the IDs of all the virtual network interfaces attached to the
+ specified instance, as a list. These IDs are opaque to the caller
+ (they are only useful for giving back to this layer as a parameter to
+ interface_stats). These IDs only need to be unique for a given
+ instance.
+ """
+ return self._vmops.list_interfaces(instance_name)
+
class VMwareAPISession(object):
"""
diff --git a/nova/virt/vmwareapi/fake.py b/nova/virt/vmwareapi/fake.py
index 27e26526f..7fb014075 100644
--- a/nova/virt/vmwareapi/fake.py
+++ b/nova/virt/vmwareapi/fake.py
@@ -172,6 +172,14 @@ class VirtualLsiLogicController(DataObject):
pass
+class VirtualPCNet32(DataObject):
+ """VirtualPCNet32 class."""
+
+ def __init__(self):
+ super(VirtualPCNet32, self).__init__()
+ self.key = 4000
+
+
class VirtualMachine(ManagedObject):
"""Virtual Machine class."""
@@ -192,7 +200,7 @@ class VirtualMachine(ManagedObject):
self.set("config.files.vmPathName", kwargs.get("vmPathName"))
self.set("summary.config.numCpu", kwargs.get("numCpu", 1))
self.set("summary.config.memorySizeMB", kwargs.get("mem", 1))
- self.set("config.hardware.device", kwargs.get("virtual_disk", None))
+ self.set("config.hardware.device", kwargs.get("virtual_device", None))
self.set("config.extraConfig", kwargs.get("extra_config", None))
def reconfig(self, factory, val):
@@ -216,7 +224,9 @@ class VirtualMachine(ManagedObject):
controller = VirtualLsiLogicController()
controller.key = controller_key
- self.set("config.hardware.device", [disk, controller])
+ nic = VirtualPCNet32()
+
+ self.set("config.hardware.device", [disk, controller, nic])
except AttributeError:
# Case of Reconfig of VM to set extra params
self.set("config.extraConfig", val.extraConfig)
diff --git a/nova/virt/vmwareapi/network_util.py b/nova/virt/vmwareapi/network_util.py
index d2bdad0c1..f63d7f723 100644
--- a/nova/virt/vmwareapi/network_util.py
+++ b/nova/virt/vmwareapi/network_util.py
@@ -1,5 +1,6 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
+# Copyright (c) 2012 VMware, Inc.
# Copyright (c) 2011 Citrix Systems, Inc.
# Copyright 2011 OpenStack LLC.
#
@@ -58,7 +59,11 @@ def get_network_with_the_name(session, network_name="vmnet0"):
if props.name == network_name:
network_obj['type'] = 'DistributedVirtualPortgroup'
network_obj['dvpg'] = props.key
- network_obj['dvsw'] = props.distributedVirtualSwitch.value
+ dvs_props = session._call_method(vim_util,
+ "get_dynamic_property",
+ props.distributedVirtualSwitch,
+ "VmwareDistributedVirtualSwitch", "uuid")
+ network_obj['dvsw'] = dvs_props
else:
props = session._call_method(vim_util,
"get_dynamic_property", network,
@@ -102,11 +107,11 @@ def get_vswitch_for_vlan_interface(session, vlan_interface):
def check_if_vlan_interface_exists(session, vlan_interface):
"""Checks if the vlan_inteface exists on the esx host."""
- host_net_system_mor = session._call_method(vim_util, "get_objects",
- "HostSystem", ["configManager.networkSystem"])[0].propSet[0].val
+ host_mor = session._call_method(vim_util, "get_objects",
+ "HostSystem")[0].obj
physical_nics_ret = session._call_method(vim_util,
- "get_dynamic_property", host_net_system_mor,
- "HostNetworkSystem", "networkInfo.pnic")
+ "get_dynamic_property", host_mor,
+ "HostSystem", "config.network.pnic")
# Meaning there are no physical nics on the host
if not physical_nics_ret:
return False
diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py
index 625d6290e..187fc449d 100644
--- a/nova/virt/vmwareapi/vmops.py
+++ b/nova/virt/vmwareapi/vmops.py
@@ -1,5 +1,6 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
+# Copyright (c) 2012 VMware, Inc.
# Copyright (c) 2011 Citrix Systems, Inc.
# Copyright 2011 OpenStack LLC.
#
@@ -39,7 +40,18 @@ from nova.virt.vmwareapi import vm_util
from nova.virt.vmwareapi import vmware_images
+vmware_vif_opts = [
+ cfg.StrOpt('integration_bridge',
+ default='br-int',
+ help='Name of Integration Bridge'),
+ ]
+
+vmware_group = cfg.OptGroup(name='vmware',
+ title='VMware Options')
+
CONF = cfg.CONF
+CONF.register_group(vmware_group)
+CONF.register_opts(vmware_vif_opts, vmware_group)
LOG = logging.getLogger(__name__)
@@ -167,7 +179,8 @@ class VMwareVMOps(object):
vif_infos = []
for (network, mapping) in network_info:
mac_address = mapping['mac']
- network_name = network['bridge']
+ network_name = network['bridge'] or \
+ CONF.vmware.integration_bridge
if mapping.get('should_create_vlan'):
network_ref = vmwarevif.ensure_vlan_bridge(
self._session, network)
@@ -733,9 +746,9 @@ class VMwareVMOps(object):
Set the machine id of the VM for guest tools to pick up and reconfigure
the network interfaces.
"""
- vm_ref = self._get_vm_ref_from_the_name(instance.name)
+ vm_ref = vm_util.get_vm_ref_from_name(self._session, instance['name'])
if vm_ref is None:
- raise exception.InstanceNotFound(instance_id=instance.id)
+ raise exception.InstanceNotFound(instance_id=instance['uuid'])
machine_id_str = ''
for (network, info) in network_info:
@@ -763,16 +776,14 @@ class VMwareVMOps(object):
client_factory, machine_id_str)
LOG.debug(_("Reconfiguring VM instance to set the machine id "
- "with ip - %(ip_addr)s") %
- {'ip_addr': ip_v4['ip']},
+ "with ip - %(ip_addr)s") % {'ip_addr': ip_v4['ip']},
instance=instance)
reconfig_task = self._session._call_method(self._session._get_vim(),
"ReconfigVM_Task", vm_ref,
spec=machine_id_change_spec)
self._session._wait_for_task(instance['uuid'], reconfig_task)
LOG.debug(_("Reconfigured VM instance to set the machine id "
- "with ip - %(ip_addr)s") %
- {'ip_addr': ip_v4['ip']},
+ "with ip - %(ip_addr)s") % {'ip_addr': ip_v4['ip']},
instance=instance)
def _get_datacenter_name_and_ref(self):
@@ -822,6 +833,13 @@ class VMwareVMOps(object):
return vm.obj
return None
+ def inject_network_info(self, instance, network_info):
+ """inject network info for specified instance."""
+ # Set the machine.id parameter of the instance to inject
+ # the NIC configuration inside the VM
+ client_factory = self._session._get_vim().client.factory
+ self._set_machine_id(client_factory, instance, network_info)
+
def plug_vifs(self, instance, network_info):
"""Plug VIFs into networks."""
pass
@@ -829,3 +847,28 @@ class VMwareVMOps(object):
def unplug_vifs(self, instance, network_info):
"""Unplug VIFs from networks."""
pass
+
+ def list_interfaces(self, instance_name):
+ """
+ Return the IDs of all the virtual network interfaces attached to the
+ specified instance, as a list. These IDs are opaque to the caller
+ (they are only useful for giving back to this layer as a parameter to
+ interface_stats). These IDs only need to be unique for a given
+ instance.
+ """
+ vm_ref = vm_util.get_vm_ref_from_name(self._session, instance_name)
+ if vm_ref is None:
+ raise exception.InstanceNotFound(instance_id=instance_name)
+
+ interfaces = []
+ # Get the virtual network interfaces attached to the VM
+ hardware_devices = self._session._call_method(vim_util,
+ "get_dynamic_property", vm_ref,
+ "VirtualMachine", "config.hardware.device")
+
+ for device in hardware_devices:
+ if device.__class__.__name__ in ["VirtualE1000", "VirtualE1000e",
+ "VirtualPCNet32", "VirtualVmxnet"]:
+ interfaces.append(device.key)
+
+ return interfaces