cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject git commit: updated refs/heads/4.4 to 4807fa7
Date Tue, 23 Dec 2014 20:52:51 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/4.4 53fbe8401 -> 4807fa7de


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)


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

Branch: refs/heads/4.4
Commit: 4807fa7de64d287950d45717a40a36e72efaabad
Parents: 53fbe84
Author: Likitha Shetty <likitha.shetty@citrix.com>
Authored: Mon Nov 10 10:58:11 2014 +0530
Committer: Daan Hoogland <daan@onecht.net>
Committed: Tue Dec 23 21:52:23 2014 +0100

----------------------------------------------------------------------
 .../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/4807fa7d/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 ecdffa6..3d02eb0 100755
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -1074,6 +1074,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/4807fa7d/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 faf63b4..b38eb6e 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
@@ -1288,6 +1288,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();
@@ -1305,6 +1306,17 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
             }
 
             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();
@@ -1323,7 +1335,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;
@@ -1695,7 +1706,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 {
             synchronized (_vms) {
                 if (state != State.Stopped) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4807fa7d/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 ef13783..96ae2a0 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
@@ -131,6 +131,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