cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [06/20] git commit: updated refs/heads/4.5 to 64e938b
Date Mon, 02 Feb 2015 10:17:04 GMT
CLOUDSTACK-8112. CS allows creation of VM's with the same Display name when vm.instancename.flag
is set to true.
Before registering a VM check if a different CS VM with same name exists in vCenter.

(cherry picked from commit 33179cce56b15f0632e38afa260cb829bb2a2273)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>


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

Branch: refs/heads/4.5
Commit: 45d32234a69b9e20372d00cc3d6d8cd48f4ea89c
Parents: b2fa916
Author: Likitha Shetty <likitha.shetty@citrix.com>
Authored: Mon Nov 10 10:58:11 2014 +0530
Committer: Rohit Yadav <rohit.yadav@shapeblue.com>
Committed: Mon Feb 2 13:51:22 2015 +0530

----------------------------------------------------------------------
 .../com/cloud/vm/VirtualMachineManagerImpl.java |  3 ++
 .../vmware/resource/VmwareResource.java         | 19 ++++++++++--
 .../hypervisor/vmware/mo/DatacenterMO.java      | 32 ++++++++++++++++++++
 3 files changed, 52 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/45d32234/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 0051cff..8c7388d 100755
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -1067,6 +1067,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
                         }
                     }
                     s_logger.info("Unable to start VM on " + dest.getHost() + " due to "
+ (startAnswer == null ? " no start answer" : startAnswer.getDetails()));
+                    if (startAnswer.getContextParam("stopRetry") != null) {
+                        break;
+                    }
 
                 } catch (OperationTimedoutException e) {
                     s_logger.debug("Unable to send the start command to host " + dest.getHost());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/45d32234/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 4e71090..9ad3a5f 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
@@ -1324,6 +1324,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
         }
 
         VirtualMachineTO vmSpec = cmd.getVirtualMachine();
+        boolean vmAlreadyExistsInVcenter = false;
 
         Pair<String, String> names = composeVmNames(vmSpec);
         String vmInternalCSName = names.first();
@@ -1335,6 +1336,17 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
             VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
 
             VmwareHypervisorHost hyperHost = getHyperHost(context);
+            DatacenterMO dcMo = new DatacenterMO(hyperHost.getContext(), hyperHost.getHyperHostDatacenter());
+
+            // Validate VM name is unique in Datacenter
+            VirtualMachineMO vmInVcenter = dcMo.checkIfVmAlreadyExistsInVcenter(vmNameOnVcenter,
vmInternalCSName);
+            if(vmInVcenter != null) {
+                vmAlreadyExistsInVcenter = true;
+                String msg = "VM with name: " + vmNameOnVcenter +" already exists in vCenter.";
+                s_logger.error(msg);
+                throw new Exception(msg);
+            }
+
             DiskTO[] disks = validateDisks(vmSpec.getDisks());
             assert (disks.length > 0);
             NicTO[] nics = vmSpec.getNics();
@@ -1353,7 +1365,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
                 throw new Exception(msg);
             }
 
-            DatacenterMO dcMo = new DatacenterMO(hyperHost.getContext(), hyperHost.getHyperHostDatacenter());
             VirtualMachineDiskInfoBuilder diskInfoBuilder = null;
             VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName);
             boolean hasSnapshot = false;
@@ -1738,7 +1749,11 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
 
             String msg = "StartCommand failed due to " + VmwareHelper.getExceptionMessage(e);
             s_logger.warn(msg, e);
-            return new StartAnswer(cmd, msg);
+            StartAnswer startAnswer = new StartAnswer(cmd, msg);
+            if(vmAlreadyExistsInVcenter) {
+                startAnswer.setContextParam("stopRetry", "true");
+            }
+            return startAnswer;
         } finally {
         }
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/45d32234/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
index 39a30be..38b1565 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
@@ -125,6 +125,38 @@ public class DatacenterMO extends BaseMO {
         return list;
     }
 
+    public VirtualMachineMO checkIfVmAlreadyExistsInVcenter(String vmNameOnVcenter, String
vmNameInCS) throws Exception {
+        int key = getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
+        if (key == 0) {
+            s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME +
" is not registered ?!");
+        }
+
+        List<ObjectContent> ocs = getVmPropertiesOnDatacenterVmFolder(new String[]
{"name", String.format("value[%d]", key)});
+        if (ocs != null && ocs.size() > 0) {
+            for (ObjectContent oc : ocs) {
+                List<DynamicProperty> props = oc.getPropSet();
+                if (props != null) {
+                    String vmVcenterName = null;
+                    String vmInternalCSName = null;
+                    for (DynamicProperty prop : props) {
+                        if (prop.getName().equals("name")) {
+                            vmVcenterName = prop.getVal().toString();
+                        }
+                        if (prop.getName().startsWith("value[") && prop.getVal()
!= null) {
+                            vmInternalCSName = ((CustomFieldStringValue)prop.getVal()).getValue();
+                        }
+                    }
+                    if (vmNameOnVcenter.equals(vmVcenterName)) {
+                        if (vmInternalCSName != null && !vmInternalCSName.isEmpty()
&& !vmNameInCS.equals(vmInternalCSName)) {
+                            return (new VirtualMachineMO(_context, oc.getObj()));
+                        }
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
     public List<Pair<ManagedObjectReference, String>> getAllVmsOnDatacenter()
throws Exception {
         List<Pair<ManagedObjectReference, String>> vms = new ArrayList<Pair<ManagedObjectReference,
String>>();
 


Mime
View raw message