Repository: cloudstack
Updated Branches:
  refs/heads/master e8de07a1a -> e091e82a7


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


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/309da6a5
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/309da6a5
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/309da6a5

Branch: refs/heads/master
Commit: 309da6a57f202322b71dca98b5695dfb278447a8
Parents: 5d7288b
Author: Suresh Kumar Anaparti <sureshkumar.anapa...@citrix.com>
Authored: Tue Sep 15 15:35:38 2015 +0530
Committer: Suresh Kumar Anaparti <suresh.anapa...@accelerite.com>
Committed: Thu Dec 1 14:32:18 2016 +0530

----------------------------------------------------------------------
 .../vmware/resource/VmwareResource.java         | 24 ++++++++++++++++++++
 .../vmware/mo/HypervisorHostHelper.java         | 13 +++++++++++
 .../hypervisor/vmware/util/VmwareHelper.java    | 10 ++++++++
 3 files changed, 47 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/309da6a5/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
 
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index 1ec859b..2c4b605 100644
--- 
a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ 
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -80,6 +80,7 @@ import com.vmware.vim25.VirtualDevice;
 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;
@@ -1873,6 +1874,29 @@ public class VmwareResource implements 
StoragePoolResource, ServerResource, Vmwa
             }
 
             //
+            // 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
             //
             VirtualDevice nic;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/309da6a5/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java
----------------------------------------------------------------------
diff --git 
a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java 
b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java
index fc27d1f..fb63b12 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java
@@ -77,6 +77,7 @@ import com.vmware.vim25.VMwareDVSPvlanConfigSpec;
 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;
@@ -1291,6 +1292,18 @@ public class HypervisorHostHelper {
             }
         }
 
+        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()));

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/309da6a5/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java 
b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
index 84e9dad..65dfe7b 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
@@ -46,6 +46,7 @@ import 
com.vmware.vim25.VirtualCdromRemotePassthroughBackingInfo;
 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;
@@ -651,6 +652,15 @@ public class VmwareHelper {
         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);

Reply via email to