You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by an...@apache.org on 2013/08/27 22:13:54 UTC

[01/12] git commit: updated refs/heads/4.2 to 41d2fb3

Updated Branches:
  refs/heads/4.2 587860797 -> 41d2fb3d1


CloudStack CLOUDSTACK-4484
Vmware - Not able to fetch userdata from guest Vms using http://<router-address>/latest/user-data
(cherry picked from commit 697cc2e397a8d6ff0d293587877dfb3033d87c26)

Signed-off-by: animesh <an...@apache.org>


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

Branch: refs/heads/4.2
Commit: 5524e61f4bf5034fe063680e7bfe2444796a1ec6
Parents: 5878607
Author: frank <fr...@citrix.com>
Authored: Mon Aug 26 17:53:06 2013 -0700
Committer: animesh <an...@apache.org>
Committed: Tue Aug 27 12:52:54 2013 -0700

----------------------------------------------------------------------
 server/src/com/cloud/api/ApiServlet.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5524e61f/server/src/com/cloud/api/ApiServlet.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiServlet.java b/server/src/com/cloud/api/ApiServlet.java
index ca6f4b4..98c460a 100755
--- a/server/src/com/cloud/api/ApiServlet.java
+++ b/server/src/com/cloud/api/ApiServlet.java
@@ -79,7 +79,7 @@ public class ApiServlet extends HttpServlet {
         String[] paramsInQueryString = req.getQueryString().split("&");
         if (paramsInQueryString != null) {
             for (String param : paramsInQueryString) {
-                String[] paramTokens = param.split("=");
+                String[] paramTokens = param.split("=", 2);
                 if (paramTokens != null && paramTokens.length == 2) {
                     String name = paramTokens[0];
                     String value = paramTokens[1];


[09/12] git commit: updated refs/heads/4.2 to 41d2fb3

Posted by an...@apache.org.
CLOUDSTACK-4443 [VMWARE]Failed to deploy VM's on VMWARE Standard vSwitch Legacy Zone after upgrade

While upgrading to 4.2 to support existing clusters working over standard vswitch or nexus dvswitch should be supported as is. To ensure this while upgrading to 4.2, existing cluster's vswitch configuration needs to be persisted to database. If zone level traffic label is empty then default vswitch name would be used.

Signed-off-by: Sateesh Chodapuneedi <sa...@apache.org>
(cherry picked from commit 808183fdcc24fd6417d7bb806ee58a84b84868f4)

Signed-off-by: animesh <an...@apache.org>


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

Branch: refs/heads/4.2
Commit: a48e6685a125344d0b683a28eadfa2147f59cca8
Parents: bba9801
Author: Sateesh Chodapuneedi <sa...@apache.org>
Authored: Tue Aug 27 16:54:29 2013 +0530
Committer: animesh <an...@apache.org>
Committed: Tue Aug 27 12:56:08 2013 -0700

----------------------------------------------------------------------
 .../com/cloud/upgrade/dao/Upgrade410to420.java  | 47 ++++++++++++++++++++
 1 file changed, 47 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a48e6685/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
index 81f11f0..5db6420 100755
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -39,6 +39,7 @@ import org.apache.log4j.Logger;
 
 import com.cloud.deploy.DeploymentPlanner;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.network.Networks.TrafficType;
 import com.cloud.network.vpc.NetworkACL;
 import com.cloud.utils.Pair;
 import com.cloud.utils.exception.CloudRuntimeException;
@@ -147,6 +148,10 @@ public class Upgrade410to420 implements DbUpgrade {
         boolean nexusEnabled = false;
         String publicVswitchType = VMWARE_STANDARD_VSWITCH;
         String guestVswitchType = VMWARE_STANDARD_VSWITCH;
+        String defaultPublicVswitchName = "vSwitch0";
+        String defaultGuestVswitchName = "vSwitch0";
+        String publicVswitchName = null;
+        String guestVswitchName = null;
         Map<Long, List<Pair<String, String>>> detailsMap = new HashMap<Long, List<Pair<String, String>>>();
         List<Pair<String, String>> detailsList;
 
@@ -163,13 +168,27 @@ public class Upgrade410to420 implements DbUpgrade {
                             nexusEnabled = true;
                         }
                     }
+                    // Set default values if cloud level setting is turned on for nexus 1000v.
                     if (nexusEnabled) {
                         publicVswitchType = NEXUS_1000V_DVSWITCH;
                         guestVswitchType = NEXUS_1000V_DVSWITCH;
+                        defaultPublicVswitchName = "publicEthernetPortProfile";
+                        defaultGuestVswitchName = "guestEthernetPortProfile";
+                    }
+                    // Read zone level settings from zone wide traffic labels for guest traffic and public traffic
+                    guestVswitchName = getDefaultTrafficLabel(conn, TrafficType.Guest.toString());
+                    publicVswitchName = getDefaultTrafficLabel(conn, TrafficType.Public.toString());
+                    if (guestVswitchName == null) {
+                        guestVswitchName = defaultGuestVswitchName;
+                    }
+                    if (publicVswitchName == null) {
+                        publicVswitchName = defaultPublicVswitchName;
                     }
                     detailsList = new ArrayList<Pair<String, String>>();
                     detailsList.add(new Pair<String, String>(ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC, guestVswitchType));
+                    detailsList.add(new Pair<String, String>(ApiConstants.VSWITCH_NAME_GUEST_TRAFFIC, guestVswitchName));
                     detailsList.add(new Pair<String, String>(ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC, publicVswitchType));
+                    detailsList.add(new Pair<String, String>(ApiConstants.VSWITCH_NAME_PUBLIC_TRAFFIC, publicVswitchName));
                     detailsMap.put(clusterId, detailsList);
 
                     updateClusterDetails(conn, detailsMap);
@@ -237,6 +256,34 @@ public class Upgrade410to420 implements DbUpgrade {
         }
     }
 
+    private String getDefaultTrafficLabel(Connection conn, String trafficType) {
+        ResultSet rs = null;
+        PreparedStatement pstmt = null;
+        try {
+            pstmt = conn.prepareStatement("select vmware_network_label from physical_network_traffic_types where vmware_network_label is not NULL and traffic_type='" + trafficType + "';");
+            rs = pstmt.executeQuery();
+
+            while (rs.next()) {
+                String label = rs.getString("vmware_network_label");
+                // Handle case of label specified as [vswitch_name,vlan_id]
+                return label.split(",")[0];
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable read default traffic label for " + trafficType + ". ", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+        return null;
+    }
+
     private String getConfigurationParameter(Connection conn, String category, String paramName) {
         ResultSet rs = null;
         PreparedStatement pstmt = null;


[02/12] git commit: updated refs/heads/4.2 to 41d2fb3

Posted by an...@apache.org.
CLOUDSTACK-3237: add disk chain sync logic to handle out-of-band chain changes that could happen in storage live migration and VM snapshot operations


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

Branch: refs/heads/4.2
Commit: 21f631f13d997182867941fe8cdf680293b71eb9
Parents: 5524e61
Author: Kelven Yang <ke...@gmail.com>
Authored: Mon Aug 26 17:45:54 2013 -0700
Committer: animesh <an...@apache.org>
Committed: Tue Aug 27 12:53:20 2013 -0700

----------------------------------------------------------------------
 api/src/com/cloud/agent/api/to/VolumeTO.java    |   4 +
 .../vmware/resource/VmwareResource.java         | 703 ++++++++++++-------
 server/src/com/cloud/storage/VolumeManager.java |   2 +
 .../com/cloud/storage/VolumeManagerImpl.java    |  18 +
 .../com/cloud/vm/VirtualMachineManagerImpl.java |  17 +
 .../vmware/mo/VirtualMachineDiskInfo.java       |  42 ++
 .../mo/VirtualMachineDiskInfoBuilder.java       |  97 +++
 .../hypervisor/vmware/mo/VirtualMachineMO.java  |  27 +-
 8 files changed, 658 insertions(+), 252 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/21f631f1/api/src/com/cloud/agent/api/to/VolumeTO.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/to/VolumeTO.java b/api/src/com/cloud/agent/api/to/VolumeTO.java
index a5681a0..fb08384 100644
--- a/api/src/com/cloud/agent/api/to/VolumeTO.java
+++ b/api/src/com/cloud/agent/api/to/VolumeTO.java
@@ -126,6 +126,10 @@ public class VolumeTO implements InternalIdentity {
     public String getChainInfo() {
         return chainInfo;
     }
+    
+    public void setChainInfo(String chainInfo) {
+    	this.chainInfo = chainInfo;
+    }
 
     public String getOsType() {
         return guestOsType;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/21f631f1/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 87e2e93..b612ac7 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -213,6 +213,7 @@ import com.cloud.hypervisor.vmware.mo.ClusterMO;
 import com.cloud.hypervisor.vmware.mo.CustomFieldConstants;
 import com.cloud.hypervisor.vmware.mo.CustomFieldsManagerMO;
 import com.cloud.hypervisor.vmware.mo.DatacenterMO;
+import com.cloud.hypervisor.vmware.mo.DatastoreFile;
 import com.cloud.hypervisor.vmware.mo.DatastoreMO;
 import com.cloud.hypervisor.vmware.mo.DiskControllerType;
 import com.cloud.hypervisor.vmware.mo.FeatureKeyConstants;
@@ -223,6 +224,8 @@ import com.cloud.hypervisor.vmware.mo.HostStorageSystemMO;
 import com.cloud.hypervisor.vmware.mo.HypervisorHostHelper;
 import com.cloud.hypervisor.vmware.mo.NetworkDetails;
 import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType;
+import com.cloud.hypervisor.vmware.mo.VirtualMachineDiskInfo;
+import com.cloud.hypervisor.vmware.mo.VirtualMachineDiskInfoBuilder;
 import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
 import com.cloud.hypervisor.vmware.mo.VirtualSwitchType;
 import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost;
@@ -282,8 +285,6 @@ import com.vmware.vim25.DistributedVirtualSwitchPortCriteria;
 import com.vmware.vim25.DynamicProperty;
 import com.vmware.vim25.GuestInfo;
 import com.vmware.vim25.HostCapability;
-import com.vmware.vim25.HostFirewallInfo;
-import com.vmware.vim25.HostFirewallRuleset;
 import com.vmware.vim25.HostHostBusAdapter;
 import com.vmware.vim25.HostInternetScsiHba;
 import com.vmware.vim25.HostInternetScsiHbaAuthenticationProperties;
@@ -1131,11 +1132,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
             s_logger.error("Unexpected exception: " + e.toString(), e);
             return new Answer(cmd, false, "VPCLoadBalancerConfigCommand failed due to " + VmwareHelper.getExceptionMessage(e));
         }
-
-
     }
 
-
     protected Answer execute(final LoadBalancerConfigCommand cmd) {
 
         if ( cmd.getVpcId() != null ) {
@@ -1834,7 +1832,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
             if (!result_gateway.first()) {
                 throw new InternalErrorException("Unable to configure source NAT for public IP address.");
             }
-
         }
     }
 
@@ -2334,6 +2331,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
         }
         return new CheckS2SVpnConnectionsAnswer(cmd, true, result.second());
     }
+    
     protected Answer execute(CheckRouterCommand cmd) {
         if (s_logger.isDebugEnabled()) {
             s_logger.debug("Executing resource CheckRouterCommand: " + _gson.toJson(cmd));
@@ -2562,6 +2560,15 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
 
         return validatedDisks.toArray(new DiskTO[0]);
     }
+    
+    private static DiskTO getIsoDiskTO(DiskTO[] disks) {
+        for (DiskTO vol : disks) {
+            if (vol.getType() == Volume.Type.ISO) {
+                return vol;
+            }
+        }
+        return null;
+    }
 
     protected ScaleVmAnswer execute(ScaleVmCommand cmd) {
 
@@ -2611,23 +2618,16 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
     }
 
     protected StartAnswer execute(StartCommand cmd) {
-
         if (s_logger.isInfoEnabled()) {
             s_logger.info("Executing resource StartCommand: " + _gson.toJson(cmd));
         }
-
+        
         VirtualMachineTO vmSpec = cmd.getVirtualMachine();
-        String vmInternalCSName = null;
-        String vmNameOnVcenter = null;
-        if (vmSpec.getHostName() != null) {
-            vmInternalCSName = vmSpec.getName();
-            if (_instanceNameFlag == true)
-                vmNameOnVcenter = vmSpec.getHostName();
-            else
-                vmNameOnVcenter = vmSpec.getName();
-        } else {
-            vmNameOnVcenter = vmInternalCSName = vmSpec.getName();
-        }
+        
+        Pair<String, String> names = composeVmNames(vmSpec);
+        String vmInternalCSName = names.first();
+        String vmNameOnVcenter = names.second();
+        
         // Thus, vmInternalCSName always holds i-x-y, the cloudstack generated internal VM name.
         State state = State.Stopped;
         VmwareContext context = getServiceContext();
@@ -2639,10 +2639,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
                 _vms.put(vmInternalCSName, State.Starting);
             }
 
-            VirtualEthernetCardType nicDeviceType = VirtualEthernetCardType.valueOf(vmSpec.getDetails().get(VmDetailConstants.NIC_ADAPTER));
-            if(s_logger.isDebugEnabled())
-                s_logger.debug("VM " + vmInternalCSName + " will be started with NIC device type: " + nicDeviceType);
-
             VmwareHypervisorHost hyperHost = getHyperHost(context);
             DiskTO[] disks = validateDisks(vmSpec.getDisks());
             assert (disks.length > 0);
@@ -2663,12 +2659,15 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
             }
             
             DatacenterMO dcMo = new DatacenterMO(hyperHost.getContext(), hyperHost.getHyperHostDatacenter());
-
+            VirtualMachineDiskInfoBuilder diskInfoBuilder = null;
             VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName);
             if (vmMo != null) {
                 s_logger.info("VM " + vmInternalCSName + " already exists, tear down devices for reconfiguration");
                 if (getVmState(vmMo) != State.Stopped)
                     vmMo.safePowerOff(_shutdown_waitMs);
+             
+                // retrieve disk information before we tear down
+                diskInfoBuilder = vmMo.getDiskInfoBuilder();
                 vmMo.tearDownDevices(new Class<?>[] { VirtualDisk.class, VirtualEthernetCard.class });
                 vmMo.ensureScsiDeviceController();
             } else {
@@ -2685,6 +2684,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
 
                     if (getVmState(vmMo) != State.Stopped)
                         vmMo.safePowerOff(_shutdown_waitMs);
+                    
+                    diskInfoBuilder = vmMo.getDiskInfoBuilder();
                     vmMo.tearDownDevices(new Class<?>[] { VirtualDisk.class, VirtualEthernetCard.class });
                     vmMo.ensureScsiDeviceController();
                 } else {
@@ -2698,6 +2699,13 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
                     }
 
                     assert (vmSpec.getMinSpeed() != null) && (rootDiskDataStoreDetails != null);
+
+                    if(rootDiskDataStoreDetails.second().folderExists(String.format("[%s]", rootDiskDataStoreDetails.second().getName()), vmNameOnVcenter)) {
+                    	s_logger.warn("WARN!!! Folder already exists on datastore for new VM " + vmNameOnVcenter + ", erase it");
+                    	rootDiskDataStoreDetails.second().deleteFile(String.format("[%s] %s/", rootDiskDataStoreDetails.second().getName(), 
+                    		vmNameOnVcenter), dcMo.getMor(), false);
+                    }
+                    
                     if (!hyperHost.createBlankVm(vmNameOnVcenter, vmInternalCSName, vmSpec.getCpus(), vmSpec.getMaxSpeed().intValue(),
                             vmSpec.getMinSpeed(), vmSpec.getLimitCpuUse(),(int)(vmSpec.getMaxRam()/(1024*1024)), ramMb,
                             translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value(), rootDiskDataStoreDetails.first(), false)) {
@@ -2712,63 +2720,43 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
             }
             
             int totalChangeDevices = disks.length + nics.length;
+            
             DiskTO volIso = null;
             if (vmSpec.getType() != VirtualMachine.Type.User) {
                 // system VM needs a patch ISO
                 totalChangeDevices++;
             } else {
-                for (DiskTO vol : disks) {
-                    if (vol.getType() == Volume.Type.ISO) {
-                        volIso = vol;
-                        break;
-                    }
-                }
-
+            	volIso = getIsoDiskTO(disks);
                 if (volIso == null)
                     totalChangeDevices++;
             }
 
             VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
             int ramMb = (int) (vmSpec.getMinRam() / (1024 * 1024));
+            String guestOsId = translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value();
+            
             VmwareHelper.setBasicVmConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getMaxSpeed(),
                     vmSpec.getMinSpeed(),(int) (vmSpec.getMaxRam()/(1024*1024)), ramMb,
-                    translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value(), vmSpec.getLimitCpuUse());
-            String guestOsId = translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value();
+                    guestOsId, vmSpec.getLimitCpuUse());
+            
             // Check for hotadd settings
             vmConfigSpec.setMemoryHotAddEnabled(vmMo.isMemoryHotAddSupported(guestOsId));
             vmConfigSpec.setCpuHotAddEnabled(vmMo.isCpuHotAddSupported(guestOsId));
-
-            if ("true".equals(vmSpec.getDetails().get(VmDetailConstants.NESTED_VIRTUALIZATION_FLAG))) {
-                s_logger.debug("Nested Virtualization enabled in configuration, checking hypervisor capability");
-                ManagedObjectReference hostMor = vmMo.getRunningHost().getMor();
-                ManagedObjectReference computeMor = context.getVimClient().getMoRefProp(hostMor, "parent");
-                ManagedObjectReference environmentBrowser =
-                        context.getVimClient().getMoRefProp(computeMor, "environmentBrowser");
-                HostCapability hostCapability = context.getService().queryTargetCapabilities(environmentBrowser, hostMor);
-                Boolean nestedHvSupported = hostCapability.isNestedHVSupported();
-                if (nestedHvSupported == null) {
-                    // nestedHvEnabled property is supported only since VMware 5.1. It's not defined for earlier versions.
-                    s_logger.warn("Hypervisor doesn't support nested virtualization, unable to set config for VM " +vmSpec.getName());
-                } else if (nestedHvSupported.booleanValue()) {
-                    s_logger.debug("Hypervisor supports nested virtualization, enabling for VM " + vmSpec.getName());
-                    vmConfigSpec.setNestedHVEnabled(true);
-                }
-                else {
-                    s_logger.warn("Hypervisor doesn't support nested virtualization, unable to set config for VM " +vmSpec.getName());
-                    vmConfigSpec.setNestedHVEnabled(false);
-                }
-            }
+            configNestedHVSupport(vmMo, vmSpec, vmConfigSpec);
 
             VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[totalChangeDevices];
             int i = 0;
             int ideUnitNumber = 0;
-            int scsiUnitNumber =0;
+            int scsiUnitNumber = 0;
             int nicUnitNumber = 0;
             int ideControllerKey = vmMo.getIDEDeviceControllerKey();
             int scsiControllerKey = vmMo.getScsiDeviceControllerKey();
             int controllerKey;
-            String datastoreDiskPath;
 
+            //
+            // Setup ISO device
+            //
+            
             // prepare systemvm patch ISO
             if (vmSpec.getType() != VirtualMachine.Type.User) {
                 // attach ISO (for patching of system VM)
@@ -2800,8 +2788,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
                     deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.EDIT);
                 }
             } else {
-                // we will always plugin a CDROM device
-
+                // Note: we will always plug a CDROM device
                 if (volIso != null) {
                     TemplateObjectTO iso = (TemplateObjectTO)volIso.getData();
 
@@ -2847,55 +2834,58 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
                     }
                 }
             }
+            
             i++;
-            for (DiskTO vol : sortVolumesByDeviceId(disks)) {
+            
+            //
+            // Setup ROOT/DATA disk devices
+            //
+            DiskTO[] sortedDisks = sortVolumesByDeviceId(disks);
+            for (DiskTO vol : sortedDisks) {
                 deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
 
-                if (vol.getType() == Volume.Type.ISO) {
-                    controllerKey = ideControllerKey;
-                } else {
-                    if(vol.getType() == Volume.Type.ROOT) {
-                        if(vmSpec.getDetails() != null && vmSpec.getDetails().get(VmDetailConstants.ROOK_DISK_CONTROLLER) != null)
-                        {
-                            if(vmSpec.getDetails().get(VmDetailConstants.ROOK_DISK_CONTROLLER).equalsIgnoreCase("scsi"))
-                                controllerKey = scsiControllerKey;
-                            else
-                                controllerKey = ideControllerKey;
-                        } else {
-                            controllerKey = scsiControllerKey;
-                        }
-                    } else {
-                        // DATA volume always use SCSI device
-                        controllerKey = scsiControllerKey;
-                    }
-                }
-
-                if (vol.getType() != Volume.Type.ISO) {
-                    VolumeObjectTO volumeTO = (VolumeObjectTO)vol.getData();
-                    PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volumeTO.getDataStore();
-                    Pair<ManagedObjectReference, DatastoreMO> volumeDsDetails = dataStoresDetails.get(primaryStore.getUuid());
-                    assert (volumeDsDetails != null);
-                    VirtualDevice device;
-                    
-                    datastoreDiskPath = VmwareStorageLayoutHelper.syncVolumeToVmDefaultFolder(dcMo, vmNameOnVcenter, volumeDsDetails.second(), 
-                    	volumeTO.getPath());
-                    device = VmwareHelper.prepareDiskDevice(vmMo, controllerKey, new String[] { datastoreDiskPath }, volumeDsDetails.first(),
-                        (controllerKey==ideControllerKey)?ideUnitNumber++:scsiUnitNumber++, i + 1);
-                    
-                    deviceConfigSpecArray[i].setDevice(device);
-                    deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.ADD);
+                if (vol.getType() == Volume.Type.ISO)
+                	continue;
+                
+                controllerKey = getDiskController(vol, vmSpec, ideControllerKey, scsiControllerKey);
 
+                VolumeObjectTO volumeTO = (VolumeObjectTO)vol.getData();
+                PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volumeTO.getDataStore();
+                Pair<ManagedObjectReference, DatastoreMO> volumeDsDetails = dataStoresDetails.get(primaryStore.getUuid());
+                assert (volumeDsDetails != null);
+                VirtualDevice device;
+                
+                String[] diskChain = syncDiskChain(dcMo, vmMo, vmSpec, 
+                    	vol, diskInfoBuilder,
+                    	dataStoresDetails,
+                    	(controllerKey == ideControllerKey) ? true : false, 
+                    	0, 	// currently only support bus 0
+                    	(controllerKey == ideControllerKey) ? ideUnitNumber : scsiUnitNumber);
+                
+                device = VmwareHelper.prepareDiskDevice(vmMo, controllerKey, 
+                	diskChain, 
+                	volumeDsDetails.first(),
+                    (controllerKey == ideControllerKey) ? ideUnitNumber++ : scsiUnitNumber++, i + 1);
+                
+                deviceConfigSpecArray[i].setDevice(device);
+                deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.ADD);
 
-                    if(s_logger.isDebugEnabled())
-                        s_logger.debug("Prepare volume at new device " + _gson.toJson(device));
+                if(s_logger.isDebugEnabled())
+                    s_logger.debug("Prepare volume at new device " + _gson.toJson(device));
 
-                    i++;
-                }
+                i++;
             }
 
+            //
+            // Setup NIC devices
+            //
             VirtualDevice nic;
             int nicMask = 0;
             int nicCount = 0;
+            VirtualEthernetCardType nicDeviceType = VirtualEthernetCardType.valueOf(vmSpec.getDetails().get(VmDetailConstants.NIC_ADAPTER));
+            if(s_logger.isDebugEnabled())
+                s_logger.debug("VM " + vmInternalCSName + " will be started with NIC device type: " + nicDeviceType);
+            
             for (NicTO nicTo : sortNicsByDeviceId(nics)) {
                 s_logger.info("Prepare NIC device based on NicTO: " + _gson.toJson(nicTo));
 
@@ -2932,170 +2922,47 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
 
             vmConfigSpec.getDeviceChange().addAll(Arrays.asList(deviceConfigSpecArray));
 
+            //
+            // Setup VM options
+            //
+            
             // pass boot arguments through machine.id & perform customized options to VMX
-
             ArrayList<OptionValue> extraOptions = new ArrayList<OptionValue>();
-            OptionValue newVal = new OptionValue();
-            newVal.setKey("machine.id");
-            newVal.setValue(vmSpec.getBootArgs());
-            extraOptions.add(newVal);
-
-            newVal = new OptionValue();
-            newVal.setKey("devices.hotplug");
-            newVal.setValue("true");
-            extraOptions.add(newVal);
-
-            /**
-             * Extra Config : nvp.vm-uuid = uuid
-             *  - Required for Nicira NVP integration
-             */
-            newVal = new OptionValue();
-            newVal.setKey("nvp.vm-uuid");
-            newVal.setValue(vmSpec.getUuid());
-            extraOptions.add(newVal);
-
-            /**
-             * Extra Config : nvp.iface-id.<num> = uuid
-             *  - Required for Nicira NVP integration
-             */
-            int nicNum = 0;
-            for (NicTO nicTo : sortNicsByDeviceId(nics)) {
-                if (nicTo.getUuid() != null) {
-                    newVal = new OptionValue();
-                    newVal.setKey("nvp.iface-id." + nicNum);
-                    newVal.setValue(nicTo.getUuid());
-                    extraOptions.add(newVal);
-                }
-                nicNum++;
-            }
-
-            for(Map.Entry<String, String> entry : validateVmDetails(vmSpec.getDetails()).entrySet()) {
-                newVal = new OptionValue();
-                newVal.setKey(entry.getKey());
-                newVal.setValue(entry.getValue());
-                extraOptions.add(newVal);
-            }
+            configBasicExtraOption(extraOptions, vmSpec);
+            configNvpExtraOption(extraOptions, vmSpec);
+            configCustomExtraOption(extraOptions, vmSpec);
 
+            // config VNC
             String keyboardLayout = null;
             if(vmSpec.getDetails() != null)
                 keyboardLayout = vmSpec.getDetails().get(VmDetailConstants.KEYBOARD);
-            vmConfigSpec.getExtraConfig().addAll(Arrays.asList(configureVnc(extraOptions.toArray(new OptionValue[0]), hyperHost, vmInternalCSName, vmSpec.getVncPassword(), keyboardLayout)));
-
+            vmConfigSpec.getExtraConfig().addAll(
+            	Arrays.asList(
+            		configureVnc(
+            			extraOptions.toArray(new OptionValue[0]), 
+            			hyperHost, vmInternalCSName, vmSpec.getVncPassword(), keyboardLayout
+            		)
+            	)
+            );
+
+            //
+            // Configure VM
+            //
             if (!vmMo.configureVm(vmConfigSpec)) {
                 throw new Exception("Failed to configure VM before start. vmName: " + vmInternalCSName);
             }
 
+            //
+            // Post Configuration
+            //
+            
             vmMo.setCustomFieldValue(CustomFieldConstants.CLOUD_NIC_MASK, String.valueOf(nicMask));
-
-            /**
-             * We need to configure the port on the DV switch after the host is
-             * connected. So make this happen between the configure and start of
-             * the VM
-             */
-            int nicIndex = 0;
-            for (NicTO nicTo : sortNicsByDeviceId(nics)) {
-                if (nicTo.getBroadcastType() == BroadcastDomainType.Lswitch) {
-                    // We need to create a port with a unique vlan and pass the key to the nic device
-                    s_logger.trace("Nic " + nicTo.toString() + " is connected to an NVP logicalswitch");
-                    VirtualDevice nicVirtualDevice = vmMo.getNicDeviceByIndex(nicIndex);
-                    if (nicVirtualDevice == null) {
-                        throw new Exception("Failed to find a VirtualDevice for nic " + nicIndex); //FIXME Generic exceptions are bad
-                    }
-                    VirtualDeviceBackingInfo backing = nicVirtualDevice.getBacking();
-                    if (backing instanceof VirtualEthernetCardDistributedVirtualPortBackingInfo) {
-                        // This NIC is connected to a Distributed Virtual Switch
-                        VirtualEthernetCardDistributedVirtualPortBackingInfo portInfo = (VirtualEthernetCardDistributedVirtualPortBackingInfo) backing;
-                        DistributedVirtualSwitchPortConnection port = portInfo.getPort();
-                        String portKey = port.getPortKey();
-                        String portGroupKey = port.getPortgroupKey();
-                        String dvSwitchUuid = port.getSwitchUuid();
-
-                        s_logger.debug("NIC " + nicTo.toString() + " is connected to dvSwitch " + dvSwitchUuid + " pg " + portGroupKey + " port " + portKey);
-
-                        ManagedObjectReference dvSwitchManager = vmMo.getContext().getVimClient().getServiceContent().getDvSwitchManager();
-                        ManagedObjectReference dvSwitch = vmMo.getContext().getVimClient().getService().queryDvsByUuid(dvSwitchManager, dvSwitchUuid);
-
-                        // Get all ports
-                        DistributedVirtualSwitchPortCriteria criteria = new DistributedVirtualSwitchPortCriteria();
-                        criteria.setInside(true);
-                        criteria.getPortgroupKey().add(portGroupKey);
-                        List<DistributedVirtualPort> dvPorts = vmMo.getContext().getVimClient().getService().fetchDVPorts(dvSwitch, criteria);
-
-                        DistributedVirtualPort vmDvPort = null;
-                        List<Integer> usedVlans = new ArrayList<Integer>();
-                        for (DistributedVirtualPort dvPort : dvPorts) {
-                            // Find the port for this NIC by portkey
-                            if (portKey.equals(dvPort.getKey())) {
-                                vmDvPort = dvPort;
-                            }
-                            VMwareDVSPortSetting settings = (VMwareDVSPortSetting) dvPort
-                                    .getConfig().getSetting();
-                            VmwareDistributedVirtualSwitchVlanIdSpec vlanId = (VmwareDistributedVirtualSwitchVlanIdSpec) settings
-                                    .getVlan();
-                            s_logger.trace("Found port " + dvPort.getKey()
-                                    + " with vlan " + vlanId.getVlanId());
-                            if (vlanId.getVlanId() > 0
-                                    && vlanId.getVlanId() < 4095) {
-                                usedVlans.add(vlanId.getVlanId());
-                            }
-                        }
-
-                        if (vmDvPort == null) {
-                            throw new Exception("Empty port list from dvSwitch for nic " + nicTo.toString());
-                        }
-
-                        DVPortConfigInfo dvPortConfigInfo = vmDvPort
-                                .getConfig();
-                        VMwareDVSPortSetting settings = (VMwareDVSPortSetting) dvPortConfigInfo.getSetting();
-
-                        VmwareDistributedVirtualSwitchVlanIdSpec vlanId = (VmwareDistributedVirtualSwitchVlanIdSpec) settings.getVlan();
-                        BoolPolicy blocked = settings.getBlocked();
-                        if (blocked.isValue() == Boolean.TRUE) {
-                            s_logger.trace("Port is blocked, set a vlanid and unblock");
-                            DVPortConfigSpec dvPortConfigSpec = new DVPortConfigSpec();
-                            VMwareDVSPortSetting edittedSettings = new VMwareDVSPortSetting();
-                            // Unblock
-                            blocked.setValue(Boolean.FALSE);
-                            blocked.setInherited(Boolean.FALSE);
-                            edittedSettings.setBlocked(blocked);
-                            // Set vlan
-                            for (i = 1; i < 4095; i++) {
-                                if (!usedVlans.contains(i))
-                                    break;
-                            }
-                            vlanId.setVlanId(i); // FIXME should be a determined
-                            // based on usage
-                            vlanId.setInherited(false);
-                            edittedSettings.setVlan(vlanId);
-
-                            dvPortConfigSpec.setSetting(edittedSettings);
-                            dvPortConfigSpec.setOperation("edit");
-                            dvPortConfigSpec.setKey(portKey);
-                            List<DVPortConfigSpec> dvPortConfigSpecs = new ArrayList<DVPortConfigSpec>();
-                            dvPortConfigSpecs.add(dvPortConfigSpec);
-                            ManagedObjectReference task = vmMo.getContext().getVimClient().getService().reconfigureDVPortTask(dvSwitch, dvPortConfigSpecs);
-                            if (!vmMo.getContext().getVimClient().waitForTask(task)) {
-                                throw new Exception(
-                                        "Failed to configure the dvSwitch port for nic "
-                                                + nicTo.toString());
-                            }
-                            s_logger.debug("NIC " + nicTo.toString()
-                                    + " connected to vlan " + i);
-                        } else {
-                            s_logger.trace("Port already configured and set to vlan " + vlanId.getVlanId());
-                        }
-                    } else if (backing instanceof VirtualEthernetCardNetworkBackingInfo) {
-                        // This NIC is connected to a Virtual Switch
-                        // Nothing to do
-                    }
-                    else {
-                        s_logger.error("nic device backing is of type " + backing.getClass().getName());
-                        throw new Exception("Incompatible backing for a VirtualDevice for nic " + nicIndex); //FIXME Generic exceptions are bad
-                    }
-                }
-                nicIndex++;
-            }
-
+            postNvpConfigBeforeStart(vmMo, vmSpec);
+            postDiskConfigBeforeStart(vmMo, vmSpec, sortedDisks, ideControllerKey, scsiControllerKey);
+            
+            //
+            // Power-on VM
+            //
             if (!vmMo.powerOn()) {
                 throw new Exception("Failed to start VM. vmName: " + vmInternalCSName + " with hostname " + vmNameOnVcenter);
             }
@@ -3121,7 +2988,340 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
             }
         }
     }
+    
+    // return the finalized disk chain for startup, from top to bottom
+    private String[] syncDiskChain(DatacenterMO dcMo, VirtualMachineMO vmMo, VirtualMachineTO vmSpec, 
+    	DiskTO vol, VirtualMachineDiskInfoBuilder diskInfoBuilder,
+    	HashMap<String ,Pair<ManagedObjectReference, DatastoreMO>> dataStoresDetails,
+    	boolean ideController, int deviceBusNumber, int deviceUnitNumber) throws Exception {
+    	
+        VolumeObjectTO volumeTO = (VolumeObjectTO)vol.getData();
+        PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volumeTO.getDataStore();
+        
+        String deviceBusName;
+        if(ideController)
+        	deviceBusName = String.format("ide%d:%d", deviceBusNumber, deviceUnitNumber);
+        else
+        	deviceBusName = String.format("scsi%d:%d", deviceBusNumber, deviceUnitNumber);
+        
+        Pair<ManagedObjectReference, DatastoreMO> volumeDsDetails = dataStoresDetails.get(primaryStore.getUuid());
+        if(volumeDsDetails == null)
+        	throw new Exception("Primary datastore " + primaryStore.getUuid() + " is not mounted on host.");
+        DatastoreMO dsMo = volumeDsDetails.second();
+
+        String datastoreDiskPath = VmwareStorageLayoutHelper.syncVolumeToVmDefaultFolder(
+        	dcMo, vmMo.getName(), dsMo, volumeTO.getPath());
+
+        if(!dsMo.fileExists(datastoreDiskPath)) {
+    		if(s_logger.isInfoEnabled())
+    			s_logger.info("Volume " + volumeTO.getId() + " does not seem to exist on datastore, out of sync? path: " + datastoreDiskPath);
+    		
+            if(diskInfoBuilder != null && diskInfoBuilder.getDiskCount() > 0) {
+            	// we will always on-disk info from vCenter in this case
+            	VirtualMachineDiskInfo diskInfo = diskInfoBuilder.getDiskInfoByDeviceBusName(deviceBusName);
+            	if(diskInfo != null) {
+            		if(s_logger.isInfoEnabled())
+            			s_logger.info("Volume " + volumeTO.getId() + " does not seem to exist on datastore. use on-disk chain: " + 
+            				_gson.toJson(diskInfo));
+            		
+            		return diskInfo.getDiskChain();
+            	} else {
+            		s_logger.warn("Volume " + volumeTO.getId() + " does not seem to exist on datastore. on-disk may be out of sync as well. disk device info: " + deviceBusName);
+            	}
+            }
+            
+            // last resort, try chain info stored in DB
+            if(volumeTO.getChainInfo() != null) {
+            	VirtualMachineDiskInfo diskInfo = _gson.fromJson(volumeTO.getChainInfo(), VirtualMachineDiskInfo.class);
+            	if(diskInfo != null) {
+            		s_logger.info("Use chain info from DB: " + volumeTO.getChainInfo());
+            		return diskInfo.getDiskChain();
+            	}
+            	
+            	throw new Exception("Volume " + volumeTO.getId() + " does not seem to exist on datastore. Broken disk chain");
+            }
+    	}
+        
+    	return new String[] { datastoreDiskPath }; 
+    }
 
+    // Pair<internal CS name, vCenter display name>
+    private Pair<String, String> composeVmNames(VirtualMachineTO vmSpec) {
+        String vmInternalCSName = null;
+        String vmNameOnVcenter = null;
+        if (vmSpec.getHostName() != null) {
+            vmInternalCSName = vmSpec.getName();
+            if (_instanceNameFlag == true)
+                vmNameOnVcenter = vmSpec.getHostName();
+            else
+                vmNameOnVcenter = vmSpec.getName();
+        } else {
+            vmNameOnVcenter = vmInternalCSName = vmSpec.getName();
+        }
+    
+        return new Pair<String, String>(vmInternalCSName, vmNameOnVcenter);
+    }
+    
+    private static void configNestedHVSupport(VirtualMachineMO vmMo, 
+    	VirtualMachineTO vmSpec, VirtualMachineConfigSpec vmConfigSpec) throws Exception {
+    	
+    	VmwareContext context = vmMo.getContext();
+        if ("true".equals(vmSpec.getDetails().get(VmDetailConstants.NESTED_VIRTUALIZATION_FLAG))) {
+        	if(s_logger.isDebugEnabled())
+        		s_logger.debug("Nested Virtualization enabled in configuration, checking hypervisor capability");
+            
+        	ManagedObjectReference hostMor = vmMo.getRunningHost().getMor();
+            ManagedObjectReference computeMor = context.getVimClient().getMoRefProp(hostMor, "parent");
+            ManagedObjectReference environmentBrowser = context.getVimClient().getMoRefProp(computeMor, "environmentBrowser");
+            HostCapability hostCapability = context.getService().queryTargetCapabilities(environmentBrowser, hostMor);
+            Boolean nestedHvSupported = hostCapability.isNestedHVSupported();
+            if (nestedHvSupported == null) {
+                // nestedHvEnabled property is supported only since VMware 5.1. It's not defined for earlier versions.
+                s_logger.warn("Hypervisor doesn't support nested virtualization, unable to set config for VM " +vmSpec.getName());
+            } else if (nestedHvSupported.booleanValue()) {
+                s_logger.debug("Hypervisor supports nested virtualization, enabling for VM " + vmSpec.getName());
+                vmConfigSpec.setNestedHVEnabled(true);
+            }
+            else {
+                s_logger.warn("Hypervisor doesn't support nested virtualization, unable to set config for VM " +vmSpec.getName());
+                vmConfigSpec.setNestedHVEnabled(false);
+            }
+        }
+    }
+    
+    private static void configBasicExtraOption(List<OptionValue> extraOptions, VirtualMachineTO vmSpec) {
+        OptionValue newVal = new OptionValue();
+        newVal.setKey("machine.id");
+        newVal.setValue(vmSpec.getBootArgs());
+        extraOptions.add(newVal);
+
+        newVal = new OptionValue();
+        newVal.setKey("devices.hotplug");
+        newVal.setValue("true");
+        extraOptions.add(newVal);
+    }
+    
+    private static void configNvpExtraOption(List<OptionValue> extraOptions, VirtualMachineTO vmSpec) {
+        /**
+         * Extra Config : nvp.vm-uuid = uuid
+         *  - Required for Nicira NVP integration
+         */
+    	OptionValue newVal = new OptionValue();
+        newVal.setKey("nvp.vm-uuid");
+        newVal.setValue(vmSpec.getUuid());
+        extraOptions.add(newVal);
+
+        /**
+         * Extra Config : nvp.iface-id.<num> = uuid
+         *  - Required for Nicira NVP integration
+         */
+        int nicNum = 0;
+        for (NicTO nicTo : sortNicsByDeviceId(vmSpec.getNics())) {
+            if (nicTo.getUuid() != null) {
+                newVal = new OptionValue();
+                newVal.setKey("nvp.iface-id." + nicNum);
+                newVal.setValue(nicTo.getUuid());
+                extraOptions.add(newVal);
+            }
+            nicNum++;
+        }
+    }
+
+    private static void configCustomExtraOption(List<OptionValue> extraOptions, VirtualMachineTO vmSpec) {
+    	// we no longer to validation anymore
+        for(Map.Entry<String, String> entry : vmSpec.getDetails().entrySet()) {
+        	OptionValue newVal = new OptionValue();
+            newVal.setKey(entry.getKey());
+            newVal.setValue(entry.getValue());
+            extraOptions.add(newVal);
+        }
+    }
+    
+    private static void postNvpConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachineTO vmSpec) throws Exception {
+        /**
+         * We need to configure the port on the DV switch after the host is
+         * connected. So make this happen between the configure and start of
+         * the VM
+         */
+        int nicIndex = 0;
+        for (NicTO nicTo : sortNicsByDeviceId(vmSpec.getNics())) {
+            if (nicTo.getBroadcastType() == BroadcastDomainType.Lswitch) {
+                // We need to create a port with a unique vlan and pass the key to the nic device
+                s_logger.trace("Nic " + nicTo.toString() + " is connected to an NVP logicalswitch");
+                VirtualDevice nicVirtualDevice = vmMo.getNicDeviceByIndex(nicIndex);
+                if (nicVirtualDevice == null) {
+                    throw new Exception("Failed to find a VirtualDevice for nic " + nicIndex); //FIXME Generic exceptions are bad
+                }
+                VirtualDeviceBackingInfo backing = nicVirtualDevice.getBacking();
+                if (backing instanceof VirtualEthernetCardDistributedVirtualPortBackingInfo) {
+                    // This NIC is connected to a Distributed Virtual Switch
+                    VirtualEthernetCardDistributedVirtualPortBackingInfo portInfo = (VirtualEthernetCardDistributedVirtualPortBackingInfo) backing;
+                    DistributedVirtualSwitchPortConnection port = portInfo.getPort();
+                    String portKey = port.getPortKey();
+                    String portGroupKey = port.getPortgroupKey();
+                    String dvSwitchUuid = port.getSwitchUuid();
+
+                    s_logger.debug("NIC " + nicTo.toString() + " is connected to dvSwitch " + dvSwitchUuid + " pg " + portGroupKey + " port " + portKey);
+
+                    ManagedObjectReference dvSwitchManager = vmMo.getContext().getVimClient().getServiceContent().getDvSwitchManager();
+                    ManagedObjectReference dvSwitch = vmMo.getContext().getVimClient().getService().queryDvsByUuid(dvSwitchManager, dvSwitchUuid);
+
+                    // Get all ports
+                    DistributedVirtualSwitchPortCriteria criteria = new DistributedVirtualSwitchPortCriteria();
+                    criteria.setInside(true);
+                    criteria.getPortgroupKey().add(portGroupKey);
+                    List<DistributedVirtualPort> dvPorts = vmMo.getContext().getVimClient().getService().fetchDVPorts(dvSwitch, criteria);
+
+                    DistributedVirtualPort vmDvPort = null;
+                    List<Integer> usedVlans = new ArrayList<Integer>();
+                    for (DistributedVirtualPort dvPort : dvPorts) {
+                        // Find the port for this NIC by portkey
+                        if (portKey.equals(dvPort.getKey())) {
+                            vmDvPort = dvPort;
+                        }
+                        VMwareDVSPortSetting settings = (VMwareDVSPortSetting) dvPort
+                                .getConfig().getSetting();
+                        VmwareDistributedVirtualSwitchVlanIdSpec vlanId = (VmwareDistributedVirtualSwitchVlanIdSpec) settings
+                                .getVlan();
+                        s_logger.trace("Found port " + dvPort.getKey()
+                                + " with vlan " + vlanId.getVlanId());
+                        if (vlanId.getVlanId() > 0
+                                && vlanId.getVlanId() < 4095) {
+                            usedVlans.add(vlanId.getVlanId());
+                        }
+                    }
+
+                    if (vmDvPort == null) {
+                        throw new Exception("Empty port list from dvSwitch for nic " + nicTo.toString());
+                    }
+
+                    DVPortConfigInfo dvPortConfigInfo = vmDvPort
+                            .getConfig();
+                    VMwareDVSPortSetting settings = (VMwareDVSPortSetting) dvPortConfigInfo.getSetting();
+
+                    VmwareDistributedVirtualSwitchVlanIdSpec vlanId = (VmwareDistributedVirtualSwitchVlanIdSpec) settings.getVlan();
+                    BoolPolicy blocked = settings.getBlocked();
+                    if (blocked.isValue() == Boolean.TRUE) {
+                        s_logger.trace("Port is blocked, set a vlanid and unblock");
+                        DVPortConfigSpec dvPortConfigSpec = new DVPortConfigSpec();
+                        VMwareDVSPortSetting edittedSettings = new VMwareDVSPortSetting();
+                        // Unblock
+                        blocked.setValue(Boolean.FALSE);
+                        blocked.setInherited(Boolean.FALSE);
+                        edittedSettings.setBlocked(blocked);
+                        // Set vlan
+                        int i;
+                        for (i = 1; i < 4095; i++) {
+                            if (!usedVlans.contains(i))
+                                break;
+                        }
+                        vlanId.setVlanId(i); // FIXME should be a determined
+                        // based on usage
+                        vlanId.setInherited(false);
+                        edittedSettings.setVlan(vlanId);
+
+                        dvPortConfigSpec.setSetting(edittedSettings);
+                        dvPortConfigSpec.setOperation("edit");
+                        dvPortConfigSpec.setKey(portKey);
+                        List<DVPortConfigSpec> dvPortConfigSpecs = new ArrayList<DVPortConfigSpec>();
+                        dvPortConfigSpecs.add(dvPortConfigSpec);
+                        ManagedObjectReference task = vmMo.getContext().getVimClient().getService().reconfigureDVPortTask(dvSwitch, dvPortConfigSpecs);
+                        if (!vmMo.getContext().getVimClient().waitForTask(task)) {
+                            throw new Exception(
+                                    "Failed to configure the dvSwitch port for nic "
+                                            + nicTo.toString());
+                        }
+                        s_logger.debug("NIC " + nicTo.toString()
+                                + " connected to vlan " + i);
+                    } else {
+                        s_logger.trace("Port already configured and set to vlan " + vlanId.getVlanId());
+                    }
+                } else if (backing instanceof VirtualEthernetCardNetworkBackingInfo) {
+                    // This NIC is connected to a Virtual Switch
+                    // Nothing to do
+                }
+                else {
+                    s_logger.error("nic device backing is of type " + backing.getClass().getName());
+                    throw new Exception("Incompatible backing for a VirtualDevice for nic " + nicIndex); //FIXME Generic exceptions are bad
+                }
+            }
+            nicIndex++;
+        }
+    }
+    
+    private static int getDiskController(DiskTO vol, VirtualMachineTO vmSpec, int ideControllerKey, int scsiControllerKey) {
+    	int controllerKey;
+    	
+        if(vol.getType() == Volume.Type.ROOT) {
+            if(vmSpec.getDetails() != null && vmSpec.getDetails().get(VmDetailConstants.ROOK_DISK_CONTROLLER) != null)
+            {
+                if(vmSpec.getDetails().get(VmDetailConstants.ROOK_DISK_CONTROLLER).equalsIgnoreCase("scsi"))
+                    controllerKey = scsiControllerKey;
+                else
+                    controllerKey = ideControllerKey;
+            } else {
+                controllerKey = scsiControllerKey;
+            }
+        } else {
+            // DATA volume always use SCSI device
+            controllerKey = scsiControllerKey;
+        }
+    	
+        return controllerKey;
+    }
+    
+    private void postDiskConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachineTO vmSpec, DiskTO[] sortedDisks,
+    	int ideControllerKey, int scsiControllerKey) throws Exception {
+
+    	VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo.getDiskInfoBuilder();
+    	int controllerKey;
+        int ideUnitNumber = 1;				// we always count in IDE device first
+        int scsiUnitNumber = 0;
+    	
+    	for(DiskTO vol: sortedDisks) {
+    		VolumeObjectTO volumeTO = (VolumeObjectTO)vol.getData();
+    		
+            if (vol.getType() == Volume.Type.ISO)
+                continue;
+
+            controllerKey = getDiskController(vol, vmSpec, ideControllerKey, scsiControllerKey);
+            
+            String deviceBusName;
+            if(controllerKey == ideControllerKey)
+            	deviceBusName = String.format("ide%d:%d", 0, ideUnitNumber++);
+            else
+            	deviceBusName = String.format("scsi%d:%d", 0, scsiUnitNumber++);
+            
+    		VirtualMachineDiskInfo diskInfo = diskInfoBuilder.getDiskInfoByDeviceBusName(deviceBusName);
+    		assert(diskInfo != null);
+    		
+    		String[] diskChain = diskInfo.getDiskChain();
+    		assert(diskChain.length > 0);
+    		
+    		DatastoreFile file = new DatastoreFile(diskChain[0]);
+    		if(!file.getFileBaseName().equalsIgnoreCase(volumeTO.getPath())) {
+    			if(s_logger.isInfoEnabled())
+    				s_logger.info("Detected disk-chain top file change on volume: " + volumeTO.getId() + " "
+    					+ volumeTO.getPath() + " -> " + file.getFileBaseName());
+    		}
+    		
+    		VolumeObjectTO volInSpec = getVolumeInSpec(vmSpec, volumeTO);
+    		volInSpec.setPath(file.getFileBaseName());
+    		volInSpec.setChainInfo(_gson.toJson(diskInfo));
+    	}
+    }
+    
+    private static VolumeObjectTO getVolumeInSpec(VirtualMachineTO vmSpec, VolumeObjectTO srcVol) {
+    	for(DiskTO disk : vmSpec.getDisks()) {
+    		VolumeObjectTO vol = (VolumeObjectTO)disk.getData();
+    		if(vol.getId() == srcVol.getId())
+    			return vol;
+    	}
+    	
+    	return null;
+    }
+    
+    @Deprecated
     private Map<String, String> validateVmDetails(Map<String, String> vmDetails) {
 
         Map<String, String> validatedDetails = new HashMap<String, String>();
@@ -3147,7 +3347,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
         return validatedDetails;
     }
 
-    private NicTO[] sortNicsByDeviceId(NicTO[] nics) {
+    private static NicTO[] sortNicsByDeviceId(NicTO[] nics) {
 
         List<NicTO> listForSort = new ArrayList<NicTO>();
         for (NicTO nic : nics) {
@@ -3170,7 +3370,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
         return listForSort.toArray(new NicTO[0]);
     }
 
-    private DiskTO[] sortVolumesByDeviceId(DiskTO[] volumes) {
+    private static DiskTO[] sortVolumesByDeviceId(DiskTO[] volumes) {
 
         List<DiskTO> listForSort = new ArrayList<DiskTO>();
         for (DiskTO vol : volumes) {
@@ -6399,6 +6599,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
 	            cfmMo.ensureCustomFieldDef("Network", CustomFieldConstants.CLOUD_GC);
 	            cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_UUID);
 	            cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_NIC_MASK);
+	            cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
 	
 	            VmwareHypervisorHost hostMo = this.getHyperHost(context);
 	            _hostName = hostMo.getHyperHostName();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/21f631f1/server/src/com/cloud/storage/VolumeManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/VolumeManager.java b/server/src/com/cloud/storage/VolumeManager.java
index d022c4a..25929a4 100644
--- a/server/src/com/cloud/storage/VolumeManager.java
+++ b/server/src/com/cloud/storage/VolumeManager.java
@@ -119,4 +119,6 @@ public interface VolumeManager extends VolumeApiService {
     String getStoragePoolOfVolume(long volumeId);
 
     boolean validateVolumeSizeRange(long size);
+    
+    void updateVolumeDiskChain(long volumeId, String path, String chainInfo);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/21f631f1/server/src/com/cloud/storage/VolumeManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/VolumeManagerImpl.java b/server/src/com/cloud/storage/VolumeManagerImpl.java
index f7c0f86..6b7788b 100644
--- a/server/src/com/cloud/storage/VolumeManagerImpl.java
+++ b/server/src/com/cloud/storage/VolumeManagerImpl.java
@@ -2870,4 +2870,22 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
         VolumeVO vol = _volsDao.findById(volumeId);
         return dataStoreMgr.getPrimaryDataStore(vol.getPoolId()).getUuid();
     }
+    
+    public void updateVolumeDiskChain(long volumeId, String path, String chainInfo) {
+        VolumeVO vol = _volsDao.findById(volumeId);
+        boolean needUpdate = false;
+        if(!vol.getPath().equalsIgnoreCase(path))
+        	needUpdate = true;
+        
+        if(chainInfo != null && (vol.getChainInfo() == null || !chainInfo.equalsIgnoreCase(vol.getChainInfo())))
+        	needUpdate = true;
+        
+        if(needUpdate) {
+        	s_logger.info("Update volume disk chain info. vol: " + vol.getId() + ", " + vol.getPath() + " -> " + path 
+        		+ ", " + vol.getChainInfo() + " -> " + chainInfo);
+	        vol.setPath(path);
+	        vol.setChainInfo(chainInfo);
+	        _volsDao.update(volumeId, vol);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/21f631f1/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 499cf56..2f5d51b 100755
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -42,6 +42,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import org.apache.cloudstack.storage.to.VolumeObjectTO;
 import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
@@ -70,8 +71,10 @@ import com.cloud.agent.api.StartupRoutingCommand;
 import com.cloud.agent.api.StartupRoutingCommand.VmState;
 import com.cloud.agent.api.StopAnswer;
 import com.cloud.agent.api.StopCommand;
+import com.cloud.agent.api.to.DiskTO;
 import com.cloud.agent.api.to.NicTO;
 import com.cloud.agent.api.to.VirtualMachineTO;
+import com.cloud.agent.api.to.VolumeTO;
 import com.cloud.agent.manager.Commands;
 import com.cloud.agent.manager.allocator.HostAllocator;
 import com.cloud.alert.AlertManager;
@@ -925,6 +928,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
                             destHostId = finalHost.getId();
                         }
                         if (vmGuru.finalizeStart(vmProfile, destHostId, cmds, ctx)) {
+                            syncDiskChainChange(startAnswer);
+                            
                             if (!changeState(vm, Event.OperationSucceeded, destHostId, work, Step.Done)) {
                                 throw new ConcurrentOperationException("Unable to transition to a new state.");
                             }
@@ -1015,6 +1020,18 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 
         return startedVm;
     }
+    
+    private void syncDiskChainChange(StartAnswer answer) {
+    	VirtualMachineTO vmSpec = answer.getVirtualMachine();
+    	
+    	for(DiskTO disk : vmSpec.getDisks()) {
+    		if(disk.getType() != Volume.Type.ISO) {
+	    		VolumeObjectTO vol = (VolumeObjectTO)disk.getData();
+	    		
+	    		volumeMgr.updateVolumeDiskChain(vol.getId(), vol.getPath(), vol.getChainInfo());
+    		}
+    	}
+    }
 
     @Override
     public <T extends VMInstanceVO> boolean stop(T vm, User user, Account account) throws ResourceUnavailableException {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/21f631f1/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineDiskInfo.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineDiskInfo.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineDiskInfo.java
new file mode 100644
index 0000000..5a5060d
--- /dev/null
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineDiskInfo.java
@@ -0,0 +1,42 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.hypervisor.vmware.mo;
+
+public class VirtualMachineDiskInfo {
+	String diskDeviceBusName;
+	String[] diskChain;
+	
+	public VirtualMachineDiskInfo() {
+	}
+	
+	public String getDiskDeviceBusName() {
+		return diskDeviceBusName;
+	}
+
+	public void setDiskDeviceBusName(String diskDeviceBusName) {
+		this.diskDeviceBusName = diskDeviceBusName;
+	}
+
+	public String[] getDiskChain() {
+		return diskChain;
+	}
+
+	public void setDiskChain(String[] diskChain) {
+		this.diskChain = diskChain;
+	}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/21f631f1/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineDiskInfoBuilder.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineDiskInfoBuilder.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineDiskInfoBuilder.java
new file mode 100644
index 0000000..41c6db6
--- /dev/null
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineDiskInfoBuilder.java
@@ -0,0 +1,97 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.hypervisor.vmware.mo;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class VirtualMachineDiskInfoBuilder {
+	Map<String, List<String>> disks;
+	
+	public VirtualMachineDiskInfoBuilder() {
+		disks = new HashMap<String, List<String>>(); 
+	}
+	
+	public void addDisk(String diskDeviceBusName, String diskBackingFilePath) {
+		List<String> chain = getDiskChainContainer(diskDeviceBusName);
+		chain.add(diskBackingFilePath);
+	}
+	
+	public int getDiskCount() {
+		return disks.keySet().size();
+	}
+	
+	public List<VirtualMachineDiskInfo> getAllDiskInfo() {
+		List<VirtualMachineDiskInfo> infoList = new ArrayList<VirtualMachineDiskInfo>();
+		for(Map.Entry<String, List<String>> entry : disks.entrySet()) {
+			VirtualMachineDiskInfo diskInfo = new VirtualMachineDiskInfo();
+			diskInfo.setDiskDeviceBusName(entry.getKey());
+			diskInfo.setDiskChain(entry.getValue().toArray(new String[1]));
+			infoList.add(diskInfo);
+		}
+		return infoList;
+	}
+	
+	public VirtualMachineDiskInfo getDiskInfoByDeviceBusName(String diskDeviceBusName) {
+		List<String> chain = disks.get(diskDeviceBusName);
+		if(chain != null && chain.size() > 0) {
+			VirtualMachineDiskInfo diskInfo = new VirtualMachineDiskInfo();
+			diskInfo.setDiskDeviceBusName(diskDeviceBusName);
+			diskInfo.setDiskChain(chain.toArray(new String[1]));
+			return diskInfo;
+		}
+		
+		return null;
+	}
+	
+	public VirtualMachineDiskInfo getDiskInfoByBackingFileBaseName(String diskBackingFileBaseName) {
+		for(Map.Entry<String, List<String>> entry : disks.entrySet()) {
+			if(chainContains(entry.getValue(), diskBackingFileBaseName)) {
+				VirtualMachineDiskInfo diskInfo = new VirtualMachineDiskInfo();
+				diskInfo.setDiskDeviceBusName(entry.getKey());
+				diskInfo.setDiskChain(entry.getValue().toArray(new String[1]));
+				return diskInfo;
+			}
+		}
+		
+		return null;
+	}
+	
+	private List<String> getDiskChainContainer(String diskDeviceBusName) {
+		assert(diskDeviceBusName != null);
+		List<String> chain = disks.get(diskDeviceBusName);
+		if(chain == null) {
+			chain = new ArrayList<String>();
+			disks.put(diskDeviceBusName, chain);
+		}
+		return chain;
+	}
+	
+	private static boolean chainContains(List<String> chain, String diskBackingFileBaseName) {
+		for(String backing : chain) {
+			DatastoreFile file = new DatastoreFile(backing);
+			
+			if(file.getFileBaseName().contains(diskBackingFileBaseName))
+				return true;
+		}
+		
+		return false;
+	}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/21f631f1/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
index 6a16ffa..71ab609 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
@@ -1847,6 +1847,31 @@ public class VirtualMachineMO extends BaseMO {
 
 		return null;
 	}
+	
+	public VirtualMachineDiskInfoBuilder getDiskInfoBuilder() throws Exception {
+		VirtualMachineDiskInfoBuilder builder = new VirtualMachineDiskInfoBuilder();
+		
+		List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
+		
+		if(devices != null && devices.size() > 0) {
+			for(VirtualDevice device : devices) {
+				if(device instanceof VirtualDisk) {
+					VirtualDeviceBackingInfo backingInfo = ((VirtualDisk)device).getBacking();
+					if(backingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
+						VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo)backingInfo;
+						
+						while(diskBackingInfo != null) {
+							String deviceBusName = getDeviceBusName(devices, device);
+							builder.addDisk(deviceBusName, diskBackingInfo.getFileName());
+							diskBackingInfo = diskBackingInfo.getParent();
+						}
+					}
+				}
+			}
+		}
+		
+		return builder;
+	}
 
 	@Deprecated
 	public List<Pair<String, ManagedObjectReference>> getDiskDatastorePathChain(VirtualDisk disk, boolean followChain) throws Exception {
@@ -1938,7 +1963,7 @@ public class VirtualMachineMO extends BaseMO {
 		}
 		throw new Exception("Unable to find device controller");
 	}
-
+	
 	public VirtualDisk[] getAllDiskDevice() throws Exception {
 		List<VirtualDisk> deviceList = new ArrayList<VirtualDisk>();
 		List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");


[11/12] git commit: updated refs/heads/4.2 to 41d2fb3

Posted by an...@apache.org.
CLOUDSTACK-3010: [VMWare] [SharedNetworkWithServices] router VM
deployment fails with error "Message: Invalid configuration for device
'2'."

ensuring that direct network guru assigns a mac address for the nic that
it designs
(cherry picked from commit 47fa6d95611c596d4705ffc0f422e3dab70931a5)

Signed-off-by: animesh <an...@apache.org>


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

Branch: refs/heads/4.2
Commit: 4a5f2dd6992d2ec2d24fcb8c33aa0b6d1d67290e
Parents: 4b4315f
Author: Murali Reddy <mu...@gmail.com>
Authored: Wed Aug 28 00:31:15 2013 +0530
Committer: animesh <an...@apache.org>
Committed: Tue Aug 27 12:56:45 2013 -0700

----------------------------------------------------------------------
 server/src/com/cloud/network/guru/DirectNetworkGuru.java | 7 +++++++
 1 file changed, 7 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4a5f2dd6/server/src/com/cloud/network/guru/DirectNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/DirectNetworkGuru.java b/server/src/com/cloud/network/guru/DirectNetworkGuru.java
index b4577ac..ca4f068 100755
--- a/server/src/com/cloud/network/guru/DirectNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/DirectNetworkGuru.java
@@ -204,6 +204,13 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
         allocateDirectIp(nic, network, vm, dc, nic.getRequestedIpv4(), nic.getRequestedIpv6());
         nic.setStrategy(ReservationStrategy.Create);
 
+        if (nic.getMacAddress() == null) {
+            nic.setMacAddress(_networkModel.getNextAvailableMacAddressInNetwork(network.getId()));
+            if (nic.getMacAddress() == null) {
+                throw new InsufficientAddressCapacityException("Unable to allocate more mac addresses", Network.class, network.getId());
+            }
+        }
+
         return nic;
     }
 


[10/12] git commit: updated refs/heads/4.2 to 41d2fb3

Posted by an...@apache.org.
CLOUDSTACK-4522: check before we do dynamic casting
(cherry picked from commit 8099a6e200846878c2061c909609f88b437d8810)

Signed-off-by: animesh <an...@apache.org>


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

Branch: refs/heads/4.2
Commit: 4b4315ff710333deb12a245956f630a4c2f1b4b7
Parents: a48e668
Author: Kelven Yang <ke...@gmail.com>
Authored: Tue Aug 27 11:38:31 2013 -0700
Committer: animesh <an...@apache.org>
Committed: Tue Aug 27 12:56:25 2013 -0700

----------------------------------------------------------------------
 .../src/com/cloud/hypervisor/vmware/resource/VmwareResource.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b4315ff/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 6e4d230..63d0482 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -3296,10 +3296,10 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
         int scsiUnitNumber = 0;
     	
     	for(DiskTO vol: sortedDisks) {
-    		VolumeObjectTO volumeTO = (VolumeObjectTO)vol.getData();
-    		
             if (vol.getType() == Volume.Type.ISO)
                 continue;
+            
+    		VolumeObjectTO volumeTO = (VolumeObjectTO)vol.getData();
 
             controllerKey = getDiskController(vol, vmSpec, ideControllerKey, scsiControllerKey);
             


[12/12] git commit: updated refs/heads/4.2 to 41d2fb3

Posted by an...@apache.org.
CLOUDSTACK-4466: Fix DHCP capability breaks in 4.2 for MidoNet

A recent code change in NetworkManager causes NullPointerExceptions when DHCP
capability list is null.

The commit which made the NetworkManager change also changed the VirtualRouter
to not use null for the capabilitylist, but didn't make this change for other
network devices, causing DHCP to fail on MidoNet.

This change also updates the MidoNet plugin to use the most recent MidoNet API.

Signed-off-by: Sheng Yang <sh...@citrix.com>
(cherry picked from commit a55c75bbd201e53f0aca3e8f8f9dee08cd132a95)

Signed-off-by: animesh <an...@apache.org>


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

Branch: refs/heads/4.2
Commit: 41d2fb3d1704273042fbd02d85a276b2ec00c737
Parents: 4a5f2dd
Author: Dave Cahill <dc...@midokura.com>
Authored: Tue Aug 27 11:55:49 2013 -0700
Committer: animesh <an...@apache.org>
Committed: Tue Aug 27 12:57:01 2013 -0700

----------------------------------------------------------------------
 plugins/network-elements/midonet/pom.xml        |   4 +-
 .../cloud/network/element/MidoNetElement.java   | 153 ++++++++++---------
 .../network/element/SimpleFirewallRule.java     |  20 ++-
 .../network/guru/MidoNetGuestNetworkGuru.java   |  11 --
 .../network/resource/MidoNetVifDriver.java      |  18 +--
 .../network/element/MidoNetElementTest.java     |   4 +-
 6 files changed, 107 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/41d2fb3d/plugins/network-elements/midonet/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/network-elements/midonet/pom.xml b/plugins/network-elements/midonet/pom.xml
index b393a1a..c731068 100644
--- a/plugins/network-elements/midonet/pom.xml
+++ b/plugins/network-elements/midonet/pom.xml
@@ -35,9 +35,9 @@
 </repositories>
   <dependencies>
     <dependency>
-      <groupId>com.midokura</groupId>
+      <groupId>org.midonet</groupId>
       <artifactId>midonet-client</artifactId>
-      <version>12.12.2</version>
+      <version>1.1.0</version>
     </dependency>
     <dependency>
       <groupId>org.mockito</groupId>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/41d2fb3d/plugins/network-elements/midonet/src/com/cloud/network/element/MidoNetElement.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/midonet/src/com/cloud/network/element/MidoNetElement.java b/plugins/network-elements/midonet/src/com/cloud/network/element/MidoNetElement.java
index ab6a6de..42a6795 100644
--- a/plugins/network-elements/midonet/src/com/cloud/network/element/MidoNetElement.java
+++ b/plugins/network-elements/midonet/src/com/cloud/network/element/MidoNetElement.java
@@ -54,19 +54,21 @@ import com.cloud.vm.ReservationContext;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachineProfile;
 import com.cloud.vm.dao.NicDao;
-import com.midokura.midonet.client.MidonetApi;
-import com.midokura.midonet.client.dto.DtoRule;
-import com.midokura.midonet.client.resource.Bridge;
-import com.midokura.midonet.client.resource.BridgePort;
-import com.midokura.midonet.client.resource.DhcpHost;
-import com.midokura.midonet.client.resource.DhcpSubnet;
-import com.midokura.midonet.client.resource.Port;
-import com.midokura.midonet.client.resource.ResourceCollection;
-import com.midokura.midonet.client.resource.Route;
-import com.midokura.midonet.client.resource.Router;
-import com.midokura.midonet.client.resource.RouterPort;
-import com.midokura.midonet.client.resource.Rule;
-import com.midokura.midonet.client.resource.RuleChain;
+import org.midonet.client.MidonetApi;
+import org.midonet.client.exception.HttpInternalServerError;
+import org.midonet.client.dto.DtoRule;
+import org.midonet.client.dto.DtoRule.DtoRange;
+import org.midonet.client.resource.Bridge;
+import org.midonet.client.resource.BridgePort;
+import org.midonet.client.resource.DhcpHost;
+import org.midonet.client.resource.DhcpSubnet;
+import org.midonet.client.resource.Port;
+import org.midonet.client.resource.ResourceCollection;
+import org.midonet.client.resource.Route;
+import org.midonet.client.resource.Router;
+import org.midonet.client.resource.RouterPort;
+import org.midonet.client.resource.Rule;
+import org.midonet.client.resource.RuleChain;
 import com.sun.jersey.core.util.MultivaluedMapImpl;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
@@ -420,7 +422,9 @@ public class MidoNetElement extends AdapterBase implements
             sub.subnetLength(cidrInfo.second());
             sub.subnetPrefix(cidrInfo.first());
             sub.defaultGateway(network.getGateway());
-            sub.dnsServerAddr(dest.getDataCenter().getDns1());
+            List<String> dcs = new ArrayList<String>();
+            dcs.add(dest.getDataCenter().getDns1());
+            sub.dnsServerAddrs(dcs);
 
             sub.create();
         }
@@ -529,10 +533,8 @@ public class MidoNetElement extends AdapterBase implements
                 .nwDstAddress(floatingIp)
                 .nwDstLength(32)
                 .nwProto(SimpleFirewallRule.stringToProtocolNumber("icmp"))
-                .tpSrcStart(0)
-                .tpSrcEnd(0)
-                .tpDstStart(0)
-                .tpDstEnd(0)
+                .tpSrc(new DtoRange<Integer>(0,0))
+                .tpDst(new DtoRange<Integer>(0,0))
                 .position(2)
                 .create();
 
@@ -685,52 +687,56 @@ public class MidoNetElement extends AdapterBase implements
             }
 
             for (FirewallRule rule : rulesToApply) {
-                IpAddress dstIp = _networkModel.getIp(rule.getSourceIpAddressId());
-                FirewallRuleTO ruleTO = new FirewallRuleTO(rule, null, dstIp.getAddress().addr());
-
-                // Convert to string representation
-                SimpleFirewallRule fwRule = new SimpleFirewallRule(ruleTO);
-                String[] ruleStrings = fwRule.toStringArray();
-
-                if (rule.getState() == FirewallRule.State.Revoke) {
-                    // Lookup in existingRules, delete if present
-                    for(String revokeRuleString : ruleStrings){
-                        Rule foundRule = existingRules.get(revokeRuleString);
-                        if(foundRule != null){
-                            foundRule.delete();
+                if (rule.getState() == FirewallRule.State.Revoke || rule.getState() == FirewallRule.State.Add) {
+                    IpAddress dstIp = _networkModel.getIp(rule.getSourceIpAddressId());
+                    FirewallRuleTO ruleTO = new FirewallRuleTO(rule, null, dstIp.getAddress().addr());
+
+                    // Convert to string representation
+                    SimpleFirewallRule fwRule = new SimpleFirewallRule(ruleTO);
+                    String[] ruleStrings = fwRule.toStringArray();
+
+                    if (rule.getState() == FirewallRule.State.Revoke) {
+                        // Lookup in existingRules, delete if present
+                        for(String revokeRuleString : ruleStrings){
+                            Rule foundRule = existingRules.get(revokeRuleString);
+                            if(foundRule != null){
+                                foundRule.delete();
+                            }
                         }
-                    }
-                } else if (rule.getState() == FirewallRule.State.Add) {
-                    // Lookup in existingRules, add if not present
-                    for(int i = 0; i < ruleStrings.length; i++){
-                        String ruleString = ruleStrings[i];
-                        Rule foundRule = existingRules.get(ruleString);
-                        if(foundRule == null){
-                            // Get the cidr for the related entry in the Source Cidrs list
-                            String relatedCidr = fwRule.sourceCidrs.get(i);
-                            Pair<String,Integer> cidrParts = NetUtils.getCidr(relatedCidr);
-
-                            // Create rule with correct proto, cidr, ACCEPT, dst IP
-                            Rule toApply = preFilter.addRule()
-                                    .type(DtoRule.Jump)
-                                    .jumpChainId(preNat.getId())
-                                    .position(1)
-                                    .nwSrcAddress(cidrParts.first())
-                                    .nwSrcLength(cidrParts.second())
-                                    .nwDstAddress(ruleTO.getSrcIp())
-                                    .nwDstLength(32)
-                                    .nwProto(SimpleFirewallRule.stringToProtocolNumber(rule.getProtocol()));
+                    } else if (rule.getState() == FirewallRule.State.Add) {
+                        // Lookup in existingRules, add if not present
+                        for(int i = 0; i < ruleStrings.length; i++){
+                            String ruleString = ruleStrings[i];
+                            Rule foundRule = existingRules.get(ruleString);
+                            if(foundRule == null){
+                                // Get the cidr for the related entry in the Source Cidrs list
+                                String relatedCidr = fwRule.sourceCidrs.get(i);
+                                Pair<String,Integer> cidrParts = NetUtils.getCidr(relatedCidr);
+
+                                // Create rule with correct proto, cidr, ACCEPT, dst IP
+                                Rule toApply = preFilter.addRule()
+                                        .type(DtoRule.Jump)
+                                        .jumpChainId(preNat.getId())
+                                        .position(1)
+                                        .nwSrcAddress(cidrParts.first())
+                                        .nwSrcLength(cidrParts.second())
+                                        .nwDstAddress(ruleTO.getSrcIp())
+                                        .nwDstLength(32)
+                                        .nwProto(SimpleFirewallRule.stringToProtocolNumber(rule.getProtocol()));
+
+                                if(rule.getProtocol().equals("icmp")){
+                                    // ICMP rules - reuse port fields
+                                    // (-1, -1) means "allow all ICMP", so we don't set tpSrc / tpDst
+                                    if(fwRule.icmpType != -1 | fwRule.icmpCode != -1){
+                                        toApply.tpSrc(new DtoRange(fwRule.icmpType, fwRule.icmpType))
+                                            .tpDst(new DtoRange(fwRule.icmpCode, fwRule.icmpCode));
+                                    }
+                                } else {
+                                    toApply.tpDst(new DtoRange(fwRule.dstPortStart, fwRule.dstPortEnd));
+                                }
 
-                            if(rule.getProtocol().equals("icmp")){
-                                // ICMP rules - reuse port fields
-                                toApply.tpSrcStart(fwRule.icmpType).tpSrcEnd(fwRule.icmpType)
-                                    .tpDstStart(fwRule.icmpCode).tpDstEnd(fwRule.icmpCode);
-                            } else {
-                                toApply.tpDstStart(fwRule.dstPortStart)
-                                        .tpDstEnd(fwRule.dstPortEnd);
+                                toApply.create();
                             }
-
-                            toApply.create();
                         }
                     }
                 }
@@ -969,8 +975,11 @@ public class MidoNetElement extends AdapterBase implements
         // Rules in the preNat table
         Map<String, Rule> existingPreNatRules = new HashMap<String, Rule>();
         for (Rule existingRule : preNat.getRules()) {
-            String ruleString = new SimpleFirewallRule(existingRule).toStringArray()[0];
-            existingPreNatRules.put(ruleString, existingRule);
+            // The "port forwarding" rules we're interested in are dnat rules where src / dst ports are specified
+            if(existingRule.getType().equals(DtoRule.DNAT) && existingRule.getTpDst() != null){
+                String ruleString = new SimpleFirewallRule(existingRule).toStringArray()[0];
+                existingPreNatRules.put(ruleString, existingRule);
+            }
         }
 
         /*
@@ -1054,8 +1063,7 @@ public class MidoNetElement extends AdapterBase implements
                             .flowAction(DtoRule.Accept)
                             .nwDstAddress(publicIp)
                             .nwDstLength(32)
-                            .tpDstStart(pubPortStart)
-                            .tpDstEnd(pubPortEnd)
+                            .tpDst(new DtoRange(pubPortStart, pubPortEnd))
                             .natTargets(preTargets)
                             .nwProto(SimpleFirewallRule.stringToProtocolNumber(rule.getProtocol()))
                             .position(1);
@@ -1119,7 +1127,8 @@ public class MidoNetElement extends AdapterBase implements
         capabilities.put(Service.Gateway, null);
 
         // L3 Support : DHCP
-        capabilities.put(Service.Dhcp, null);
+        Map<Capability, String> dhcpCapabilities = new HashMap<Capability, String>();
+        capabilities.put(Service.Dhcp, dhcpCapabilities);
 
         // L3 Support : SourceNat
         Map<Capability, String> sourceNatCapabilities = new HashMap<Capability, String>();
@@ -1360,7 +1369,7 @@ public class MidoNetElement extends AdapterBase implements
         int pos = 1;
         // If it is ARP, accept it
         egressChain.addRule().type(DtoRule.Accept)
-            .dlType((short)0x0806)
+            .dlType(0x0806)
             .position(pos++)
             .create();
 
@@ -1419,7 +1428,7 @@ public class MidoNetElement extends AdapterBase implements
 
             // If it is ARP, accept it
             inc.addRule().type(DtoRule.Accept)
-                         .dlType((short)0x0806)
+                         .dlType(0x0806)
                          .position(pos++)
                          .create();
 
@@ -1483,7 +1492,13 @@ public class MidoNetElement extends AdapterBase implements
 
             String networkUUIDStr = String.valueOf(networkID);
 
-            netBridge = api.addBridge().tenantId(accountUuid).name(networkUUIDStr).create();
+            s_logger.debug("Attempting to create guest network bridge");
+            try {
+                netBridge = api.addBridge().tenantId(accountUuid).name(networkUUIDStr).create();
+            } catch (HttpInternalServerError ex) {
+                s_logger.warn("Bridge creation failed, retrying bridge get in case it now exists.", ex);
+                netBridge = getNetworkBridge(networkID, accountUuid);
+            }
         }
         return netBridge;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/41d2fb3d/plugins/network-elements/midonet/src/com/cloud/network/element/SimpleFirewallRule.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/midonet/src/com/cloud/network/element/SimpleFirewallRule.java b/plugins/network-elements/midonet/src/com/cloud/network/element/SimpleFirewallRule.java
index a6b78d8..e8d81ef 100644
--- a/plugins/network-elements/midonet/src/com/cloud/network/element/SimpleFirewallRule.java
+++ b/plugins/network-elements/midonet/src/com/cloud/network/element/SimpleFirewallRule.java
@@ -21,9 +21,10 @@ package com.cloud.network.element;
 import com.cloud.agent.api.to.FirewallRuleTO;
 import com.cloud.agent.api.to.NetworkACLTO;
 import com.cloud.agent.api.to.PortForwardingRuleTO;
-import com.midokura.midonet.client.dto.DtoRule;
+import org.midonet.client.dto.DtoRule;
+import org.midonet.client.resource.*;
 import com.google.common.collect.*;
-import com.midokura.midonet.client.resource.*;
+
 
 import java.util.*;
 // Used for translation between MidoNet firewall rules and
@@ -147,8 +148,14 @@ public class SimpleFirewallRule {
         dstIp = rule.getNwDstAddress();
 
         if("icmp".equals(protocol)){
-            icmpType = rule.getTpSrcStart();
-            icmpCode = rule.getTpDstStart();
+            if(rule.getTpSrc() != null && rule.getTpDst() != null){
+                icmpType = rule.getTpSrc().start;
+                icmpCode = rule.getTpDst().start;
+            } else {
+                icmpType = -1;
+                icmpCode = -1;
+            }
+
         } else {
             /*
              * If this is port forwarding, we want to take the start
@@ -158,9 +165,9 @@ public class SimpleFirewallRule {
             if (targets != null) {
                 dstPortStart = targets[0].portFrom;
             } else {
-                dstPortStart = rule.getTpDstStart();
+                dstPortStart = rule.getTpDst().start;
             }
-            dstPortEnd = rule.getTpDstEnd();
+            dstPortEnd = rule.getTpDst().end;
         }
 
         // cidr, protocol, dstIp, dstPortStart, dstPortEnd, icmpType, icmpCode);
@@ -177,6 +184,7 @@ public class SimpleFirewallRule {
     public int getFieldOne(){
         if(protocol.equals("icmp")){
             return icmpType;
+
         } else {
             return dstPortStart;
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/41d2fb3d/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetGuestNetworkGuru.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetGuestNetworkGuru.java b/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetGuestNetworkGuru.java
index d57affc..acc574e 100644
--- a/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetGuestNetworkGuru.java
+++ b/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetGuestNetworkGuru.java
@@ -19,8 +19,6 @@
 
 package com.cloud.network.guru;
 
-import com.cloud.network.element.MidoNetElement;
-import com.cloud.dc.DataCenter;
 import com.cloud.dc.DataCenter.NetworkType;
 import com.cloud.deploy.DeployDestination;
 import com.cloud.deploy.DeploymentPlan;
@@ -33,21 +31,12 @@ import com.cloud.user.Account;
 import com.cloud.user.AccountVO;
 import com.cloud.user.dao.AccountDao;
 import com.cloud.vm.*;
-import com.midokura.midonet.client.resource.Bridge;
-import com.cloud.utils.net.NetUtils;
-
-import com.cloud.network.Networks.AddressFormat;
-import com.midokura.midonet.client.resource.BridgePort;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 import com.cloud.network.dao.NetworkVO;
 import com.cloud.network.dao.PhysicalNetworkVO;
 
-
-import com.cloud.vm.Nic.ReservationStrategy;
-
 import javax.ejb.Local;
-import java.util.UUID;
 import javax.inject.Inject;
 
 @Component

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/41d2fb3d/plugins/network-elements/midonet/src/com/cloud/network/resource/MidoNetVifDriver.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/midonet/src/com/cloud/network/resource/MidoNetVifDriver.java b/plugins/network-elements/midonet/src/com/cloud/network/resource/MidoNetVifDriver.java
index 3c7c23d..9c21636 100644
--- a/plugins/network-elements/midonet/src/com/cloud/network/resource/MidoNetVifDriver.java
+++ b/plugins/network-elements/midonet/src/com/cloud/network/resource/MidoNetVifDriver.java
@@ -21,32 +21,24 @@ package com.cloud.network.resource;
 
 import com.cloud.hypervisor.kvm.resource.*;
 import com.cloud.agent.api.to.NicTO;
-import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource;
 import com.cloud.exception.InternalErrorException;
 import com.cloud.network.Networks;
 import com.cloud.utils.NumbersUtil;
-import com.cloud.utils.net.NetUtils;
 import com.cloud.utils.script.OutputInterpreter;
 import com.cloud.utils.script.Script;
-import com.midokura.midonet.client.resource.Bridge;
-import com.midokura.midonet.client.resource.Router;
-import com.midokura.midonet.client.resource.BridgePort;
-import com.midokura.midonet.client.resource.RouterPort;
-import com.midokura.midonet.client.resource.Host;
 import org.apache.log4j.Logger;
 import org.libvirt.LibvirtException;
-
 import com.sun.jersey.core.util.MultivaluedMapImpl;
-import com.midokura.midonet.client.MidonetApi;
-
 import javax.ws.rs.core.MultivaluedMap;
-
 import javax.naming.ConfigurationException;
-import javax.ws.rs.core.MultivaluedMap;
-import java.net.URI;
 import java.util.Map;
 import java.util.UUID;
 
+import org.midonet.client.resource.Bridge;
+import org.midonet.client.resource.BridgePort;
+import org.midonet.client.resource.Host;
+import org.midonet.client.MidonetApi;
+
 public class MidoNetVifDriver extends VifDriverBase {
 
     private static final Logger s_logger = Logger

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/41d2fb3d/plugins/network-elements/midonet/test/com/cloud/network/element/MidoNetElementTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/midonet/test/com/cloud/network/element/MidoNetElementTest.java b/plugins/network-elements/midonet/test/com/cloud/network/element/MidoNetElementTest.java
index a7d96b0..47b16b8 100644
--- a/plugins/network-elements/midonet/test/com/cloud/network/element/MidoNetElementTest.java
+++ b/plugins/network-elements/midonet/test/com/cloud/network/element/MidoNetElementTest.java
@@ -24,8 +24,8 @@ import com.cloud.user.dao.AccountDao;
 import junit.framework.TestCase;
 import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.*;
-import com.midokura.midonet.client.MidonetApi;
-import com.midokura.midonet.client.resource.*;
+import org.midonet.client.MidonetApi;
+import org.midonet.client.resource.*;
 import com.sun.jersey.core.util.MultivaluedMapImpl;
 import com.cloud.network.*;
 import com.cloud.vm.*;


[05/12] git commit: updated refs/heads/4.2 to 41d2fb3

Posted by an...@apache.org.
CLOUDSTACK-4482: getVMPassword() API call does not return password for Vms that are deployed with password enabled templates.

Improving the error message saying no ssh key pair is assinged to VM to get the encrypted password and included a check for password enabled template

Signed-off-by: Koushik Das <ko...@apache.org>
(cherry picked from commit 37d500d2a6b71c267af20a83208eb6049157f95f)

Signed-off-by: animesh <an...@apache.org>


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

Branch: refs/heads/4.2
Commit: 1e3eeacf2de3e09d1495736d1d07c03cf561a933
Parents: daaba12
Author: Harikrishna Patnala <ha...@citrix.com>
Authored: Tue Aug 27 11:46:26 2013 +0530
Committer: animesh <an...@apache.org>
Committed: Tue Aug 27 12:54:52 2013 -0700

----------------------------------------------------------------------
 server/src/com/cloud/server/ManagementServerImpl.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1e3eeacf/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index d1e4e5f..b20bf48 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -3673,7 +3673,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
         _userVmDao.loadDetails(vm);
         String password = vm.getDetail("Encrypted.Password");
         if (password == null || password.equals("")) {
-            InvalidParameterValueException ex = new InvalidParameterValueException("No password for VM with specified id found.");
+            InvalidParameterValueException ex = new InvalidParameterValueException("No password for VM with specified id found. " +
+                "If VM is created from password enabled template and SSH keypair is assigned to VM then only password can be retrieved.");
             ex.addProxyObject(vm.getUuid(), "vmId");
             throw ex;
         }


[03/12] git commit: updated refs/heads/4.2 to 41d2fb3

Posted by an...@apache.org.
CLOUDSTACK-3806: There was error in host_view sql, it was using host_details.id for join instead host_details.host_id

Signed-off-by: Sateesh Chodapuneedi <sa...@apache.org>


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

Branch: refs/heads/4.2
Commit: 7accca25e1ee9c39ffb57bb3aba56320f02fc690
Parents: 21f631f
Author: Anshul Gangwar <an...@citrix.com>
Authored: Mon Aug 26 13:27:56 2013 +0530
Committer: animesh <an...@apache.org>
Committed: Tue Aug 27 12:53:44 2013 -0700

----------------------------------------------------------------------
 setup/db/db/schema-307to410.sql | 2 +-
 setup/db/db/schema-40to410.sql  | 2 +-
 setup/db/db/schema-410to420.sql | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7accca25/setup/db/db/schema-307to410.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-307to410.sql b/setup/db/db/schema-307to410.sql
index 70cddfd..7feb53e 100644
--- a/setup/db/db/schema-307to410.sql
+++ b/setup/db/db/schema-307to410.sql
@@ -977,7 +977,7 @@ CREATE VIEW `cloud`.`host_view` AS
             left join
         `cloud`.`host_pod_ref` ON host.pod_id = host_pod_ref.id
             left join
-        `cloud`.`host_details` ON host.id = host_details.id
+        `cloud`.`host_details` ON host.id = host_details.host_id
             and host_details.name = 'guest.os.category.id'
             left join
         `cloud`.`guest_os_category` ON guest_os_category.id = CONVERT( host_details.value , UNSIGNED)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7accca25/setup/db/db/schema-40to410.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-40to410.sql b/setup/db/db/schema-40to410.sql
index f1482f8..24f6d4c 100644
--- a/setup/db/db/schema-40to410.sql
+++ b/setup/db/db/schema-40to410.sql
@@ -1073,7 +1073,7 @@ CREATE VIEW `cloud`.`host_view` AS
             left join
         `cloud`.`host_pod_ref` ON host.pod_id = host_pod_ref.id
             left join
-        `cloud`.`host_details` ON host.id = host_details.id
+        `cloud`.`host_details` ON host.id = host_details.host_id
             and host_details.name = 'guest.os.category.id'
             left join
         `cloud`.`guest_os_category` ON guest_os_category.id = CONVERT( host_details.value , UNSIGNED)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7accca25/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index c29fd86..4d68838 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -992,7 +992,7 @@ CREATE VIEW `cloud`.`host_view` AS
             left join
         `cloud`.`host_pod_ref` ON host.pod_id = host_pod_ref.id
             left join
-        `cloud`.`host_details` ON host.id = host_details.id
+        `cloud`.`host_details` ON host.id = host_details.host_id
             and host_details.name = 'guest.os.category.id'
             left join
         `cloud`.`guest_os_category` ON guest_os_category.id = CONVERT( host_details.value , UNSIGNED)


[06/12] git commit: updated refs/heads/4.2 to 41d2fb3

Posted by an...@apache.org.
CLOUDSTACK-4498 we should not reserve memory and cpu for vmware VMs if the vmware.reserve.cpu and vmware.reserve.mem are set to false.

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

Signed-off-by: Jayapal <ja...@apache.org>
(cherry picked from commit f7018317131f42f77e9bba18e5e1c78457679afc)

Signed-off-by: animesh <an...@apache.org>


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

Branch: refs/heads/4.2
Commit: fa6da31e157c96e88c470209f7ab0e8659b4c4d5
Parents: 1e3eeac
Author: Bharat Kumar <bh...@citrix.com>
Authored: Tue Aug 27 12:27:22 2013 +0530
Committer: animesh <an...@apache.org>
Committed: Tue Aug 27 12:55:14 2013 -0700

----------------------------------------------------------------------
 .../com/cloud/hypervisor/guru/VMwareGuru.java   | 12 +++++-
 .../vmware/manager/VmwareManagerImpl.java       |  2 -
 .../vmware/resource/VmwareResource.java         | 43 ++++++++++++--------
 server/src/com/cloud/configuration/Config.java  |  4 +-
 4 files changed, 39 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fa6da31e/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
index 8aae8c8..7c70c6a 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
@@ -29,8 +29,11 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 
 import com.cloud.agent.api.storage.CreateEntityDownloadURLCommand;
+import com.cloud.dc.dao.ClusterDao;
 import com.cloud.host.Host;
+import com.cloud.server.ConfigurationServer;
 import com.cloud.storage.Storage;
+import com.cloud.vm.dao.VMInstanceDao;
 import org.apache.cloudstack.storage.to.VolumeObjectTO;
 import org.apache.log4j.Logger;
 
@@ -108,12 +111,17 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru {
     @Inject SecondaryStorageVmManager _secStorageMgr;
     @Inject NetworkModel _networkMgr;
     @Inject ConfigurationDao _configDao;
+    @Inject ConfigurationServer _configServer;
     @Inject
     NicDao _nicDao;
     @Inject
     PhysicalNetworkDao _physicalNetworkDao;
     @Inject
     PhysicalNetworkTrafficTypeDao _physicalNetworkTrafficTypeDao;
+    @Inject
+    VMInstanceDao _vmDao;
+    @Inject
+    ClusterDao _clusterDao;
 
     protected VMwareGuru() {
         super();
@@ -180,7 +188,9 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru {
                 break;
             }
         }
-
+        long clusterId = _hostDao.findById( _vmDao.findById(vm.getId()).getHostId()).getClusterId();
+        details.put(Config.VmwareReserveCpu.key(), _configServer.getConfigValue(Config.VmwareReserveCpu.key(), Config.ConfigurationParameterScope.cluster.toString(), clusterId));
+        details.put(Config.VmwareReserveMem.key(), _configServer.getConfigValue(Config.VmwareReserveMem.key(), Config.ConfigurationParameterScope.cluster.toString(), clusterId));
         to.setDetails(details);
 
         if(vm.getVirtualMachine() instanceof DomainRouterVO) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fa6da31e/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
index 4d24562..b5e7535 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
@@ -518,8 +518,6 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
         params.put("vm.instancename.flag", _instanceNameFlag);
         params.put("service.console.name", _serviceConsoleName);
         params.put("management.portgroup.name", _managemetPortGroupName);
-        params.put("vmware.reserve.cpu", _reserveCpu);
-        params.put("vmware.reserve.mem", _reserveMem);
         params.put("vmware.root.disk.controller", _rootDiskController);
         params.put("vmware.recycle.hung.wokervm", _recycleHungWorker);
         params.put("ports.per.dvportgroup", _portsPerDvPortGroup);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fa6da31e/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 b612ac7..6e4d230 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -46,6 +46,7 @@ import java.util.concurrent.TimeUnit;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import com.cloud.configuration.Config;
 import org.apache.cloudstack.storage.command.DeleteCommand;
 import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
 import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
@@ -364,9 +365,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
     protected boolean _fullCloneFlag = false;
     protected boolean _instanceNameFlag = false;
 
-    protected boolean _reserveCpu = false;
 
-    protected boolean _reserveMem = false;
     protected boolean _recycleHungWorker = false;
     protected DiskControllerType _rootDiskController = DiskControllerType.ide;
 
@@ -2689,7 +2688,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
                     vmMo.tearDownDevices(new Class<?>[] { VirtualDisk.class, VirtualEthernetCard.class });
                     vmMo.ensureScsiDeviceController();
                 } else {
-                    int ramMb = (int) (vmSpec.getMinRam() / (1024 * 1024));
                     Pair<ManagedObjectReference, DatastoreMO> rootDiskDataStoreDetails = null;
                     for (DiskTO vol : disks) {
                         if (vol.getType() == Volume.Type.ROOT) {
@@ -2707,7 +2705,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
                     }
                     
                     if (!hyperHost.createBlankVm(vmNameOnVcenter, vmInternalCSName, vmSpec.getCpus(), vmSpec.getMaxSpeed().intValue(),
-                            vmSpec.getMinSpeed(), vmSpec.getLimitCpuUse(),(int)(vmSpec.getMaxRam()/(1024*1024)), ramMb,
+                            getReservedCpuMHZ(vmSpec), vmSpec.getLimitCpuUse(),(int)(vmSpec.getMaxRam()/(1024*1024)), getReservedMemoryMb(vmSpec),
                             translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value(), rootDiskDataStoreDetails.first(), false)) {
                         throw new Exception("Failed to create VM. vmName: " + vmInternalCSName);
                     }
@@ -2732,11 +2730,10 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
             }
 
             VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
-            int ramMb = (int) (vmSpec.getMinRam() / (1024 * 1024));
             String guestOsId = translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value();
             
             VmwareHelper.setBasicVmConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getMaxSpeed(),
-                    vmSpec.getMinSpeed(),(int) (vmSpec.getMaxRam()/(1024*1024)), ramMb,
+                    getReservedCpuMHZ(vmSpec),(int) (vmSpec.getMaxRam()/(1024*1024)), getReservedMemoryMb(vmSpec),
                     guestOsId, vmSpec.getLimitCpuUse());
             
             // Check for hotadd settings
@@ -2988,7 +2985,27 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
             }
         }
     }
-    
+
+    int getReservedMemoryMb(VirtualMachineTO vmSpec) {
+        if (vmSpec.getDetails().get(Config.VmwareReserveMem.key()).equalsIgnoreCase("true")) {
+              return  (int) (vmSpec.getMinRam() / (1024 * 1024));
+        }  else if (vmSpec.getMinRam() != vmSpec.getMaxRam()) {
+              s_logger.warn("memory overprovisioning factor is set to "+ (vmSpec.getMaxRam()/vmSpec.getMinRam())+" ignoring the flag vmware.reserve.mem");
+              return  (int) (vmSpec.getMinRam() / (1024 * 1024));
+        }
+        return 0;
+    }
+
+    int getReservedCpuMHZ(VirtualMachineTO vmSpec) {
+         if (vmSpec.getDetails().get(Config.VmwareReserveCpu.key()).equalsIgnoreCase("true")) {
+              return vmSpec.getMinSpeed();
+         }else if (vmSpec.getMinSpeed().intValue() != vmSpec.getMaxSpeed().intValue()) {
+              s_logger.warn("cpu overprovisioning factor is set to "+ (vmSpec.getMaxSpeed().intValue()/vmSpec.getMinSpeed().intValue())+" ignoring the flag vmware.reserve.cpu");
+              return vmSpec.getMinSpeed();
+         }
+         return 0;
+    }
+
     // return the finalized disk chain for startup, from top to bottom
     private String[] syncDiskChain(DatacenterMO dcMo, VirtualMachineMO vmMo, VirtualMachineTO vmSpec, 
     	DiskTO vol, VirtualMachineDiskInfoBuilder diskInfoBuilder,
@@ -6623,18 +6640,10 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
 	            _privateNetworkVSwitchName = (String) params.get("private.network.vswitch.name");
 	        }
 	
-	        String value = (String) params.get("vmware.reserve.cpu");
-	        if(value != null && value.equalsIgnoreCase("true"))
-	            _reserveCpu = true;
-	
-	        value = (String) params.get("vmware.recycle.hung.wokervm");
+	        String value = (String) params.get("vmware.recycle.hung.wokervm");
 	        if(value != null && value.equalsIgnoreCase("true"))
 	            _recycleHungWorker = true;
-	
-	        value = (String) params.get("vmware.reserve.mem");
-	        if(value != null && value.equalsIgnoreCase("true"))
-	            _reserveMem = true;
-	
+
 	        value = (String)params.get("vmware.root.disk.controller");
 	        if(value != null && value.equalsIgnoreCase("scsi"))
 	            _rootDiskController = DiskControllerType.scsi;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fa6da31e/server/src/com/cloud/configuration/Config.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java
index 1cc31b6..8dd5c8b 100755
--- a/server/src/com/cloud/configuration/Config.java
+++ b/server/src/com/cloud/configuration/Config.java
@@ -293,8 +293,8 @@ public enum Config {
     VmwareAdditionalVncPortRangeStart("Advanced", ManagementServer.class, Integer.class, "vmware.additional.vnc.portrange.start", "50000", "Start port number of additional VNC port range", null),
     VmwareAdditionalVncPortRangeSize("Advanced", ManagementServer.class, Integer.class, "vmware.additional.vnc.portrange.size", "1000", "Start port number of additional VNC port range", null),
     //VmwareGuestNicDeviceType("Advanced", ManagementServer.class, String.class, "vmware.guest.nic.device.type", "E1000", "Ethernet card type used in guest VM, valid values are E1000, PCNet32, Vmxnet2, Vmxnet3", null),
-    VmwareReserveCpu("Advanced", ManagementServer.class, Boolean.class, "vmware.reserve.cpu", "false", "Specify whether or not to reserve CPU based on CPU overprovisioning factor", null),
-    VmwareReserveMem("Advanced", ManagementServer.class, Boolean.class, "vmware.reserve.mem", "false", "Specify whether or not to reserve memory based on memory overprovisioning factor", null),
+    VmwareReserveCpu("Advanced", ManagementServer.class, Boolean.class, "vmware.reserve.cpu", "false", "Specify whether or not to reserve CPU when not overprovisioning, In case of cpu overprovisioning we will always reserve cpu", null, ConfigurationParameterScope.cluster.toString()),
+    VmwareReserveMem("Advanced", ManagementServer.class, Boolean.class, "vmware.reserve.mem", "false", "Specify whether or not to reserve memory when not overprovisioning, In case of memory overprovisioning we will always reserve memory", null, ConfigurationParameterScope.cluster.toString()),
     VmwareRootDiskControllerType("Advanced", ManagementServer.class, String.class, "vmware.root.disk.controller", "ide", "Specify the default disk controller for root volumes, valid values are scsi, ide", null),
     VmwareSystemVmNicDeviceType("Advanced", ManagementServer.class, String.class, "vmware.systemvm.nic.device.type", "E1000", "Specify the default network device type for system VMs, valid values are E1000, PCNet32, Vmxnet2, Vmxnet3", null),
     VmwareRecycleHungWorker("Advanced", ManagementServer.class, Boolean.class, "vmware.recycle.hung.wokervm", "false", "Specify whether or not to recycle hung worker VMs", null),


[07/12] git commit: updated refs/heads/4.2 to 41d2fb3

Posted by an...@apache.org.
CLOUDSTACK-1191: Re-enable deployment of SystemVMs on RBD

This was reverted by 0a5228922b822b57af72249912ed854281e1d85a unintentionnaly
but broke this feature for RBD.

Enable SystemVM deployment on RBD again
(cherry picked from commit 3315159de62620166c119dbf72dad9cf661cc0cb)

Signed-off-by: animesh <an...@apache.org>


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

Branch: refs/heads/4.2
Commit: 7678ab4d0da74daa9032cec0a4484fffdde5f098
Parents: fa6da31
Author: Wido den Hollander <wi...@widodh.nl>
Authored: Tue Aug 27 17:03:56 2013 +0200
Committer: animesh <an...@apache.org>
Committed: Tue Aug 27 12:55:29 2013 -0700

----------------------------------------------------------------------
 .../storage/allocator/AbstractStoragePoolAllocator.java      | 8 --------
 1 file changed, 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7678ab4d/engine/storage/src/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java b/engine/storage/src/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java
index 89e0974..e5a1d8b 100755
--- a/engine/storage/src/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java
@@ -183,14 +183,6 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement
             return false;
         }
 
-
-        DiskOfferingVO diskOffering = _diskOfferingDao.findById(dskCh.getDiskOfferingId());
-        if (diskOffering.getSystemUse() && pool.getPoolType() == StoragePoolType.RBD) {
-            s_logger.debug("Skipping RBD pool " + pool.getName()
-                    + " as a suitable pool. RBD is not supported for System VM's");
-            return false;
-        }
-
         Long clusterId = pool.getClusterId();
         ClusterVO cluster = _clusterDao.findById(clusterId);
         if (!(cluster.getHypervisorType() == dskCh.getHypervisorType())) {


[08/12] git commit: updated refs/heads/4.2 to 41d2fb3

Posted by an...@apache.org.
CLOUDSTACK-4423: Do not always append .qcow2 to volume names when copying

Disk images are not always in the QCOW2 format, so don't assume that the
filename will always and in .qcow2
(cherry picked from commit 93b40b0ca6a796ffbacd80c40897f6ada6284bc4)

Signed-off-by: animesh <an...@apache.org>


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

Branch: refs/heads/4.2
Commit: bba9801cf7ef1eb65a730b45140bf5af0d978741
Parents: 7678ab4
Author: Wido den Hollander <wi...@widodh.nl>
Authored: Tue Aug 27 18:33:46 2013 +0200
Committer: animesh <an...@apache.org>
Committed: Tue Aug 27 12:55:51 2013 -0700

----------------------------------------------------------------------
 .../cloud/hypervisor/kvm/storage/KVMStorageProcessor.java    | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bba9801c/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
index fd5c9d9..8482a8d 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
@@ -319,6 +319,8 @@ public class KVMStorageProcessor implements StorageProcessor {
         DataTO destData = cmd.getDestTO();
         DataStoreTO srcStore = srcData.getDataStore();
         DataStoreTO destStore = destData.getDataStore();
+        VolumeObjectTO srcVol = (VolumeObjectTO) srcData;
+        ImageFormat srcFormat = srcVol.getFormat();
         PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) destStore;
         if (!(srcStore instanceof NfsTO)) {
             return new CopyCmdAnswer("can only handle nfs storage");
@@ -352,14 +354,16 @@ public class KVMStorageProcessor implements StorageProcessor {
             secondaryStoragePool = storagePoolMgr.getStoragePoolByURI(
                     secondaryStorageUrl + File.separator + volumeDir
                            );
-            if (!srcVolumeName.endsWith(".qcow2")) {
+            if (!srcVolumeName.endsWith(".qcow2") && srcFormat == ImageFormat.QCOW2) {
                 srcVolumeName = srcVolumeName + ".qcow2";
             }
             KVMPhysicalDisk volume = secondaryStoragePool
                     .getPhysicalDisk(srcVolumeName);
-            storagePoolMgr.copyPhysicalDisk(volume, volumeName,
+            volume.setFormat(PhysicalDiskFormat.valueOf(srcFormat.toString()));
+            KVMPhysicalDisk newDisk = storagePoolMgr.copyPhysicalDisk(volume, volumeName,
                     primaryPool);
             VolumeObjectTO newVol = new VolumeObjectTO();
+            newVol.setFormat(ImageFormat.valueOf(newDisk.getFormat().toString().toUpperCase()));
             newVol.setPath(volumeName);
             return new CopyCmdAnswer(newVol);
         } catch (CloudRuntimeException e) {


[04/12] git commit: updated refs/heads/4.2 to 41d2fb3

Posted by an...@apache.org.
CLOUDSTACK-4471. If an instance fails to start then mark the volumes allocated as part of VM creation as removed and set the volume state as destroyed.
(cherry picked from commit 7cc8ccead541f6089ed48d9a1c335daa458b74fc)

Signed-off-by: animesh <an...@apache.org>


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

Branch: refs/heads/4.2
Commit: daaba129970d961455d647b8ced110752998ac4d
Parents: 7accca2
Author: Likitha Shetty <li...@citrix.com>
Authored: Tue Aug 27 15:23:31 2013 +0530
Committer: animesh <an...@apache.org>
Committed: Tue Aug 27 12:54:10 2013 -0700

----------------------------------------------------------------------
 server/src/com/cloud/storage/VolumeManagerImpl.java | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/daaba129/server/src/com/cloud/storage/VolumeManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/VolumeManagerImpl.java b/server/src/com/cloud/storage/VolumeManagerImpl.java
index 6b7788b..35fe72a 100644
--- a/server/src/com/cloud/storage/VolumeManagerImpl.java
+++ b/server/src/com/cloud/storage/VolumeManagerImpl.java
@@ -2676,8 +2676,14 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
     @Override
     public void destroyVolume(VolumeVO volume) {
         try {
-            volService.destroyVolume(volume.getId());
-        } catch (ConcurrentOperationException e) {
+            // Mark volume as removed if volume has not been created on primary
+            if (volume.getState() == Volume.State.Allocated) {
+                _volsDao.remove(volume.getId());
+                stateTransitTo(volume, Volume.Event.DestroyRequested);
+            } else {
+                volService.destroyVolume(volume.getId());
+            }
+        } catch (Exception e) {
             s_logger.debug("Failed to destroy volume" + volume.getId(), e);
             throw new CloudRuntimeException("Failed to destroy volume" + volume.getId(), e);
         }