Skip to content

Commit

Permalink
Merge pull request #828 from sureshanaparti/CLOUDSTACK-8854
Browse files Browse the repository at this point in the history
CLOUDSTACK-8854: Apple Mac OS/X VM get created without USB controller in ESXi hypervisorsCLOUDSTACK-8854: Apple Mac OS/X VM get created without USB controller in ESXi hypervisors

Problem Description: CloudStack doesnt add a USB controller to the Apple Mac OS X VMs created in ESXi hypervisors. But, vSphere Client, by default, adds a USB Controller to the Mac OS VMs. Mac OS X machines require USB Controller for USB mouse and keyboard access.

Root Cause: The Guest OS details are specified in the Virtual Machine Configuration Spec for creating the VM (using the SDK API) in the EXSi hypervisor. No USB Controller is added to the Virtual Machine Configuration Spec. As the guest OS Identification details are specified in the VM Configuration Spec, It is assumed that the Create VM SDK API would create the defaults in the VM same as vSphere Client. But, as per the observation, USB Controller is not added to the Guest OS - Mac OS VM created through the SDK API.

Resolution: When the Guest OS is Apple Mac OS, Add the USB Controller (EHCI+UHCI - Mac supported) to the Virtual Machine Configuration Spec before Creating or Starting the VM. For any existing Mac OS VMs, Stop and Start to add the USB Controller. For new VMs with Mac OS, USB Controller is added automatically.

* pr/828:
  CLOUDSTACK-8854: Apple Mac OS/X VM get created without USB controller in ESXi hypervisors

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
  • Loading branch information
rohityadavcloud committed Dec 2, 2016
2 parents 5d7288b + 309da6a commit 3ef775d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import com.vmware.vim25.VirtualDeviceBackingInfo;
import com.vmware.vim25.VirtualDeviceConfigSpec;
import com.vmware.vim25.VirtualDeviceConfigSpecOperation;
import com.vmware.vim25.VirtualUSBController;
import com.vmware.vim25.VirtualDisk;
import com.vmware.vim25.VirtualDiskFlatVer2BackingInfo;
import com.vmware.vim25.VirtualEthernetCard;
Expand Down Expand Up @@ -1872,6 +1873,29 @@ protected StartAnswer execute(StartCommand cmd) {
}
}

//
// Setup USB devices
//
if (guestOsId.startsWith("darwin")) { //Mac OS
VirtualDevice[] devices = vmMo.getMatchedDevices(new Class<?>[] {VirtualUSBController.class});
if (devices.length == 0) {
s_logger.debug("No USB Controller device on VM Start. Add USB Controller device for Mac OS VM " + vmInternalCSName);

//For Mac OS X systems, the EHCI+UHCI controller is enabled by default and is required for USB mouse and keyboard access.
VirtualDevice usbControllerDevice = VmwareHelper.prepareUSBControllerDevice();
deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
deviceConfigSpecArray[i].setDevice(usbControllerDevice);
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.ADD);

if (s_logger.isDebugEnabled())
s_logger.debug("Prepare USB controller at new device " + _gson.toJson(deviceConfigSpecArray[i]));

i++;
} else {
s_logger.debug("USB Controller device exists on VM Start for Mac OS VM " + vmInternalCSName);
}
}

//
// Setup NIC devices
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import com.vmware.vim25.VMwareDVSPvlanMapEntry;
import com.vmware.vim25.VirtualBusLogicController;
import com.vmware.vim25.VirtualController;
import com.vmware.vim25.VirtualDevice;
import com.vmware.vim25.VirtualDeviceConfigSpec;
import com.vmware.vim25.VirtualDeviceConfigSpecOperation;
import com.vmware.vim25.VirtualIDEController;
Expand Down Expand Up @@ -1291,6 +1292,18 @@ public static boolean createBlankVm(VmwareHypervisorHost host, String vmName, St
}
}

if (guestOsIdentifier.startsWith("darwin")) { //Mac OS
s_logger.debug("Add USB Controller device for blank Mac OS VM " + vmName);

//For Mac OS X systems, the EHCI+UHCI controller is enabled by default and is required for USB mouse and keyboard access.
VirtualDevice usbControllerDevice = VmwareHelper.prepareUSBControllerDevice();
VirtualDeviceConfigSpec usbControllerSpec = new VirtualDeviceConfigSpec();
usbControllerSpec.setDevice(usbControllerDevice);
usbControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);

vmConfig.getDeviceChange().add(usbControllerSpec);
}

VirtualMachineFileInfo fileInfo = new VirtualMachineFileInfo();
DatastoreMO dsMo = new DatastoreMO(host.getContext(), morDs);
fileInfo.setVmPathName(String.format("[%s]", dsMo.getName()));
Expand Down
10 changes: 10 additions & 0 deletions vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.vmware.vim25.VirtualDevice;
import com.vmware.vim25.VirtualDeviceBackingInfo;
import com.vmware.vim25.VirtualDeviceConnectInfo;
import com.vmware.vim25.VirtualUSBController;
import com.vmware.vim25.VirtualDisk;
import com.vmware.vim25.VirtualDiskFlatVer1BackingInfo;
import com.vmware.vim25.VirtualDiskFlatVer2BackingInfo;
Expand Down Expand Up @@ -651,6 +652,15 @@ public static void setBasicVmConfig(VirtualMachineConfigSpec vmConfig, int cpuCo
vmConfig.setGuestId(guestOsIdentifier);
}

public static VirtualDevice prepareUSBControllerDevice() {
s_logger.debug("Preparing USB controller(EHCI+UHCI) device");
VirtualUSBController usbController = new VirtualUSBController(); //EHCI+UHCI
usbController.setEhciEnabled(true);
usbController.setAutoConnectDevices(true);

return usbController;
}

public static ManagedObjectReference getDiskDeviceDatastore(VirtualDisk diskDevice) throws Exception {
VirtualDeviceBackingInfo backingInfo = diskDevice.getBacking();
assert (backingInfo instanceof VirtualDiskFlatVer2BackingInfo);
Expand Down

0 comments on commit 3ef775d

Please sign in to comment.