Skip to content

Commit 3ef775d

Browse files
committed
Merge pull request #828 from sureshanaparti/CLOUDSTACK-8854
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>
2 parents 5d7288b + 309da6a commit 3ef775d

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
import com.vmware.vim25.VirtualDeviceBackingInfo;
8181
import com.vmware.vim25.VirtualDeviceConfigSpec;
8282
import com.vmware.vim25.VirtualDeviceConfigSpecOperation;
83+
import com.vmware.vim25.VirtualUSBController;
8384
import com.vmware.vim25.VirtualDisk;
8485
import com.vmware.vim25.VirtualDiskFlatVer2BackingInfo;
8586
import com.vmware.vim25.VirtualEthernetCard;
@@ -1872,6 +1873,29 @@ protected StartAnswer execute(StartCommand cmd) {
18721873
}
18731874
}
18741875

1876+
//
1877+
// Setup USB devices
1878+
//
1879+
if (guestOsId.startsWith("darwin")) { //Mac OS
1880+
VirtualDevice[] devices = vmMo.getMatchedDevices(new Class<?>[] {VirtualUSBController.class});
1881+
if (devices.length == 0) {
1882+
s_logger.debug("No USB Controller device on VM Start. Add USB Controller device for Mac OS VM " + vmInternalCSName);
1883+
1884+
//For Mac OS X systems, the EHCI+UHCI controller is enabled by default and is required for USB mouse and keyboard access.
1885+
VirtualDevice usbControllerDevice = VmwareHelper.prepareUSBControllerDevice();
1886+
deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
1887+
deviceConfigSpecArray[i].setDevice(usbControllerDevice);
1888+
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.ADD);
1889+
1890+
if (s_logger.isDebugEnabled())
1891+
s_logger.debug("Prepare USB controller at new device " + _gson.toJson(deviceConfigSpecArray[i]));
1892+
1893+
i++;
1894+
} else {
1895+
s_logger.debug("USB Controller device exists on VM Start for Mac OS VM " + vmInternalCSName);
1896+
}
1897+
}
1898+
18751899
//
18761900
// Setup NIC devices
18771901
//

vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import com.vmware.vim25.VMwareDVSPvlanMapEntry;
7878
import com.vmware.vim25.VirtualBusLogicController;
7979
import com.vmware.vim25.VirtualController;
80+
import com.vmware.vim25.VirtualDevice;
8081
import com.vmware.vim25.VirtualDeviceConfigSpec;
8182
import com.vmware.vim25.VirtualDeviceConfigSpecOperation;
8283
import com.vmware.vim25.VirtualIDEController;
@@ -1291,6 +1292,18 @@ public static boolean createBlankVm(VmwareHypervisorHost host, String vmName, St
12911292
}
12921293
}
12931294

1295+
if (guestOsIdentifier.startsWith("darwin")) { //Mac OS
1296+
s_logger.debug("Add USB Controller device for blank Mac OS VM " + vmName);
1297+
1298+
//For Mac OS X systems, the EHCI+UHCI controller is enabled by default and is required for USB mouse and keyboard access.
1299+
VirtualDevice usbControllerDevice = VmwareHelper.prepareUSBControllerDevice();
1300+
VirtualDeviceConfigSpec usbControllerSpec = new VirtualDeviceConfigSpec();
1301+
usbControllerSpec.setDevice(usbControllerDevice);
1302+
usbControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
1303+
1304+
vmConfig.getDeviceChange().add(usbControllerSpec);
1305+
}
1306+
12941307
VirtualMachineFileInfo fileInfo = new VirtualMachineFileInfo();
12951308
DatastoreMO dsMo = new DatastoreMO(host.getContext(), morDs);
12961309
fileInfo.setVmPathName(String.format("[%s]", dsMo.getName()));

vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.vmware.vim25.VirtualDevice;
4747
import com.vmware.vim25.VirtualDeviceBackingInfo;
4848
import com.vmware.vim25.VirtualDeviceConnectInfo;
49+
import com.vmware.vim25.VirtualUSBController;
4950
import com.vmware.vim25.VirtualDisk;
5051
import com.vmware.vim25.VirtualDiskFlatVer1BackingInfo;
5152
import com.vmware.vim25.VirtualDiskFlatVer2BackingInfo;
@@ -651,6 +652,15 @@ public static void setBasicVmConfig(VirtualMachineConfigSpec vmConfig, int cpuCo
651652
vmConfig.setGuestId(guestOsIdentifier);
652653
}
653654

655+
public static VirtualDevice prepareUSBControllerDevice() {
656+
s_logger.debug("Preparing USB controller(EHCI+UHCI) device");
657+
VirtualUSBController usbController = new VirtualUSBController(); //EHCI+UHCI
658+
usbController.setEhciEnabled(true);
659+
usbController.setAutoConnectDevices(true);
660+
661+
return usbController;
662+
}
663+
654664
public static ManagedObjectReference getDiskDeviceDatastore(VirtualDisk diskDevice) throws Exception {
655665
VirtualDeviceBackingInfo backingInfo = diskDevice.getBacking();
656666
assert (backingInfo instanceof VirtualDiskFlatVer2BackingInfo);

0 commit comments

Comments
 (0)