Skip to content

Commit

Permalink
Fix VMware Hyper can't honor hw_vif_model image property.
Browse files Browse the repository at this point in the history
Support setting instance vif model through image property,
change default vif model to e1000. Available vif model options
for VMware Hyperv is "VirtualE1000, VirtualPCNet32, VirtualVmxnet".

DocImpact
Fix bug #1183192

Change-Id: I3a98bc26df7e2252bf043a71acbba2a158e213b8
  • Loading branch information
Yaguang Tang committed Jun 13, 2013
1 parent bdf362b commit 088995f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
3 changes: 3 additions & 0 deletions nova/tests/virt/vmwareapi/test_vmwareapi.py
Expand Up @@ -179,6 +179,9 @@ def _check_vm_record(self):
self.assertEquals(vm.get("summary.config.memorySizeMB"),
self.type_data['memory_mb'])

self.assertEqual(
vm.get("config.hardware.device")[2].device.obj_name,
"ns0:VirtualE1000")
# Check that the VM is running according to Nova
self.assertEquals(vm_info['state'], power_state.RUNNING)

Expand Down
14 changes: 8 additions & 6 deletions nova/virt/vmwareapi/fake.py
Expand Up @@ -136,7 +136,8 @@ def __getattr__(self, attr):

class DataObject(object):
"""Data object base class."""
pass
def __init__(self, obj_name=None):
self.obj_name = obj_name


class VirtualDisk(DataObject):
Expand Down Expand Up @@ -202,6 +203,7 @@ def __init__(self, **kwargs):
self.set("summary.config.memorySizeMB", kwargs.get("mem", 1))
self.set("config.hardware.device", kwargs.get("virtual_device", None))
self.set("config.extraConfig", kwargs.get("extra_config", None))
self.device = kwargs.get("virtual_device")

def reconfig(self, factory, val):
"""
Expand All @@ -224,9 +226,8 @@ def reconfig(self, factory, val):
controller = VirtualLsiLogicController()
controller.key = controller_key

nic = VirtualPCNet32()

self.set("config.hardware.device", [disk, controller, nic])
self.set("config.hardware.device", [disk, controller,
self.device[0]])
except AttributeError:
# Case of Reconfig of VM to set extra params
self.set("config.extraConfig", val.extraConfig)
Expand Down Expand Up @@ -501,7 +502,7 @@ class FakeFactory(object):

def create(self, obj_name):
"""Creates a namespace object."""
return DataObject()
return DataObject(obj_name)


class FakeVim(object):
Expand Down Expand Up @@ -584,7 +585,8 @@ def _create_vm(self, method, *args, **kwargs):
"vmPathName": config_spec.files.vmPathName,
"numCpu": config_spec.numCPUs,
"mem": config_spec.memoryMB,
"extra_config": config_spec.extraConfig}
"extra_config": config_spec.extraConfig,
"virtual_device": config_spec.deviceChange}
virtual_machine = VirtualMachine(**vm_dict)
_create_object("VirtualMachine", virtual_machine)
task_mdo = create_task(method, "success")
Expand Down
8 changes: 6 additions & 2 deletions nova/virt/vmwareapi/vm_util.py
Expand Up @@ -126,8 +126,12 @@ def create_network_spec(client_factory, vif_info):
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')
# Keep compatible with other Hyper vif model parameter.
if vif_info['vif_model'] == "e1000":
vif_info['vif_model'] = "VirtualE1000"

vif = 'ns0:' + vif_info['vif_model']
net_device = client_factory.create(vif)

# NOTE(asomya): Only works on ESXi if the portgroup binding is set to
# ephemeral. Invalid configuration if set to static and the NIC does
Expand Down
8 changes: 6 additions & 2 deletions nova/virt/vmwareapi/vmops.py
Expand Up @@ -155,10 +155,13 @@ def _get_image_properties():
"lsiLogic")
disk_type = image_properties.get("vmware_disktype",
"preallocated")
return vmdk_file_size_in_kb, os_type, adapter_type, disk_type
# Get the network card type from the image properties.
vif_model = image_properties.get("hw_vif_model", "VirtualE1000")
return (vmdk_file_size_in_kb, os_type, adapter_type, disk_type,
vif_model)

(vmdk_file_size_in_kb, os_type, adapter_type,
disk_type) = _get_image_properties()
disk_type, vif_model) = _get_image_properties()

vm_folder_ref = self._get_vmfolder_ref()
res_pool_ref = self._get_res_pool_ref()
Expand All @@ -183,6 +186,7 @@ def _get_vif_infos():
'mac_address': mac_address,
'network_ref': network_ref,
'iface_id': vif['id'],
'vif_model': vif_model
})
return vif_infos

Expand Down

0 comments on commit 088995f

Please sign in to comment.