cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject [24/50] [abbrv] git commit: updated refs/heads/reporter to b26f3fc
Date Fri, 02 Jan 2015 14:36:16 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.


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

Branch: refs/heads/reporter
Commit: 33179cce56b15f0632e38afa260cb829bb2a2273
Parents: 6475323
Author: Likitha Shetty <likitha.shetty@citrix.com>
Authored: Mon Nov 10 10:58:11 2014 +0530
Committer: Likitha Shetty <likitha.shetty@citrix.com>
Committed: Tue Dec 23 13:48:01 2014 +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/33179cce/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 caf374e..07b2277 100644
--- 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/33179cce/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 2e7553a..c2cf9e9 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -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/33179cce/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 100644
--- 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