=== modified file 'nova/virt/vmwareapi/network_utils.py' --- nova/virt/vmwareapi/network_utils.py 2011-03-24 16:38:31 +0000 +++ nova/virt/vmwareapi/network_utils.py 2011-06-08 23:21:55 +0000 @@ -35,20 +35,44 @@ """ hostsystems = session._call_method(vim_util, "get_objects", "HostSystem", ["network"]) + vm_networks_ret = hostsystems[0].propSet[0].val + # Meaning there are no networks on the host. suds responds with a "" # in the parent property field rather than a [] in the # ManagedObjectRefernce property field of the parent if not vm_networks_ret: return None vm_networks = vm_networks_ret.ManagedObjectReference + networks = session._call_method(vim_util, "get_properties_for_a_collection_of_objects", "Network", vm_networks, ["summary.name"]) - for network in networks: - if network.propSet[0].val == network_name: - return network.obj - return None + + network_obj = {} + for network in vm_networks: + # Get network properties + if network._type == 'DistributedVirtualPortgroup': + props = session._call_method(vim_util, + "get_dynamic_property",network, + "DistributedVirtualPortgroup","config") + if props.name == network_name: + network_obj['type'] = 'DistributedVirtualPortgroup' + network_obj['dvpg'] = props.key + network_obj['dvsw'] = props.distributedVirtualSwitch.value + else: + props = session._call_method(vim_util, + "get_dynamic_property",network, + "Network","summary.name") + + if props == network_name: + network_obj['type'] = 'Network' + network_obj['name'] = network_name + + if (len(network_obj) > 0): + return network_obj + else: + return None def get_vswitch_for_vlan_interface(session, vlan_interface): === modified file 'nova/virt/vmwareapi/vm_util.py' --- nova/virt/vmwareapi/vm_util.py 2011-03-24 16:38:31 +0000 +++ nova/virt/vmwareapi/vm_util.py 2011-06-08 23:22:06 +0000 @@ -17,7 +17,8 @@ """ The VMware API VM utility module to build SOAP object specs. """ - +from nova import log as logging +LOG = logging.getLogger("nova.virt.vmwareapi.vm_util") def build_datastore_path(datastore_name, path): """Build the datastore compliant path.""" @@ -40,12 +41,11 @@ def get_vm_create_spec(client_factory, instance, data_store_name, network_name="vmnet0", - os_type="otherGuest"): + os_type="otherGuest", network_ref=None): """Builds the VM Create spec.""" config_spec = client_factory.create('ns0:VirtualMachineConfigSpec') config_spec.name = instance.name config_spec.guestId = os_type - vm_file_info = client_factory.create('ns0:VirtualMachineFileInfo') vm_file_info.vmPathName = "[" + data_store_name + "]" config_spec.files = vm_file_info @@ -62,7 +62,7 @@ config_spec.memoryMB = int(instance.memory_mb) nic_spec = create_network_spec(client_factory, - network_name, instance.mac_address) + network_name, instance.mac_address, network_ref) device_config_spec = [nic_spec] @@ -89,7 +89,7 @@ return virtual_device_config -def create_network_spec(client_factory, network_name, mac_address): +def create_network_spec(client_factory, network_name, mac_address,network_ref=None): """ Builds a config spec for the addition of a new network adapter to the VM. @@ -97,13 +97,23 @@ network_spec = \ client_factory.create('ns0:VirtualDeviceConfigSpec') network_spec.operation = "add" - + # Get the recommended card type for the VM based on the guest OS of the VM net_device = client_factory.create('ns0:VirtualPCNet32') - backing = \ - client_factory.create('ns0:VirtualEthernetCardNetworkBackingInfo') - backing.deviceName = network_name + backing = None + if (network_ref['type'] == "DistributedVirtualPortgroup"): + backing = \ + client_factory.create('ns0:VirtualEthernetCardDistributedVirtualPortBackingInfo') + portgroup = \ + client_factory.create('ns0:DistributedVirtualSwitchPortConnection') + portgroup.switchUuid = network_ref['dvsw'] + portgroup.portgroupKey = network_ref['dvpg'] + backing.port = portgroup + else: + backing = \ + client_factory.create('ns0:VirtualEthernetCardNetworkBackingInfo') + backing.deviceName = network_name connectable_spec = \ client_factory.create('ns0:VirtualDeviceConnectInfo') @@ -123,6 +133,7 @@ net_device.wakeOnLanEnabled = True network_spec.device = net_device + return network_spec === modified file 'nova/virt/vmwareapi/vmops.py' --- nova/virt/vmwareapi/vmops.py 2011-04-26 22:48:28 +0000 +++ nova/virt/vmwareapi/vmops.py 2011-06-08 23:22:01 +0000 @@ -116,8 +116,9 @@ net_name) if network_ref is None: raise exception.NetworkNotFoundForBridge(bridge=net_name) - - _check_if_network_bridge_exists() + return network_ref + + network_obj = _check_if_network_bridge_exists() def _get_datastore_ref(): """Get the datastore list and choose the first local storage."""