You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by sa...@apache.org on 2013/07/11 17:13:16 UTC

git commit: updated refs/heads/master to a3660d8

Updated Branches:
  refs/heads/master 521dcbdcc -> a3660d810


CLOUDSTACK-3469 [VMware] Support to make username/password optional while adding VMware cluster

For legacy zones insist on the old model of asking for credentials for each cluster being added.
For non-legacy zones check if username & password are provided. If either or both not provided, try to retrieve & use the credentials from database, which are provided earlier while adding VMware DC to zone.
This lets user to not specify credentials while adding VMware cluster to zone, if the credentials are same as that of provided while adding VMware DC to zone.

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/a3660d81
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a3660d81
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a3660d81

Branch: refs/heads/master
Commit: a3660d8109918ddf3897411deaf4520733eabc00
Parents: 521dcbd
Author: Sateesh Chodapuneedi <sa...@apache.org>
Authored: Thu Jul 11 20:39:33 2013 +0530
Committer: Sateesh Chodapuneedi <sa...@apache.org>
Committed: Thu Jul 11 20:39:33 2013 +0530

----------------------------------------------------------------------
 .../vmware/VmwareServerDiscoverer.java          | 70 ++++++++++++++------
 1 file changed, 51 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a3660d81/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java
index 2807da5..33bc3e8 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java
@@ -23,20 +23,21 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
-import javax.annotation.PostConstruct;
 import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import org.apache.log4j.Logger;
+
+import com.vmware.vim25.ClusterDasConfigInfo;
+import com.vmware.vim25.ManagedObjectReference;
+
 import org.apache.cloudstack.api.ApiConstants;
-import org.springframework.beans.NullValueInNestedPathException;
 
 import com.cloud.agent.api.StartupCommand;
 import com.cloud.agent.api.StartupRoutingCommand;
 import com.cloud.alert.AlertManager;
 import com.cloud.configuration.Config;
-import com.cloud.configuration.dao.ConfigurationDao;
 import com.cloud.dc.ClusterDetailsDao;
 import com.cloud.dc.ClusterVO;
 import com.cloud.dc.DataCenter.NetworkType;
@@ -67,7 +68,6 @@ import com.cloud.network.PhysicalNetwork;
 import com.cloud.network.VmwareTrafficLabel;
 import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
 import com.cloud.network.element.CiscoNexusVSMElement;
-import com.cloud.network.element.CiscoNexusVSMElementService;
 import com.cloud.resource.Discoverer;
 import com.cloud.resource.DiscovererBase;
 import com.cloud.resource.ResourceManager;
@@ -81,9 +81,6 @@ import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.user.Account;
 import com.cloud.utils.UriUtils;
 
-import com.vmware.vim25.ClusterDasConfigInfo;
-import com.vmware.vim25.ManagedObjectReference;
-
 
 @Local(value = Discoverer.class)
 public class VmwareServerDiscoverer extends DiscovererBase implements
@@ -150,14 +147,41 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
 
         Map<String, String> clusterDetails = _clusterDetailsDao.findDetails(clusterId);
         boolean legacyZone = _vmwareMgr.isLegacyZone(dcId);
+        boolean usernameNotProvided = (username == null || username.isEmpty());
+        boolean passwordNotProvided = (password == null || password.isEmpty());
         //Check if NOT a legacy zone.
         if (!legacyZone) {
-            String updatedInventoryPath = validateCluster(dcId, url, username, password);
+            // Retrieve VMware DC associated with specified zone
+            VmwareDatacenterVO vmwareDc = fetchVmwareDatacenterByZone(dcId);
+            // Ensure username & password provided.
+            // If either or both not provided, try to retrieve & use the credentials from database, which are provided earlier while adding VMware DC to zone.
+            if (usernameNotProvided || passwordNotProvided) {
+                // Retrieve credentials associated with VMware DC
+                s_logger.info("Username and/or Password not provided while adding cluster to cloudstack zone. " +
+                        "Hence using both username & password provided while adding VMware DC to CloudStack zone.");
+                username = vmwareDc.getUser();
+                password = vmwareDc.getPassword();
+                clusterDetails.put("username", username);
+                clusterDetails.put("password", password);
+                _clusterDetailsDao.persist(clusterId, clusterDetails);
+            }
+            String updatedInventoryPath = validateCluster(url, vmwareDc);
             if (url.getPath() != updatedInventoryPath) {
-                // If url from API doesn't specifiy DC then update url in database with DC assocaited with this zone.
+                // If url from API doesn't specify DC then update url in database with DC associated with this zone.
                 clusterDetails.put("url", url.getScheme() + "://" + url.getHost() + updatedInventoryPath);
                 _clusterDetailsDao.persist(clusterId, clusterDetails);
             }
+        } else {
+            // For legacy zones insist on the old model of asking for credentials for each cluster being added.
+            if (usernameNotProvided) {
+                if (passwordNotProvided) {
+                    throw new InvalidParameterValueException("Please provide username & password to add this cluster to zone");
+                } else {
+                    throw new InvalidParameterValueException("Please provide username to add this cluster to zone");
+                }
+            } else if (passwordNotProvided) {
+                throw new InvalidParameterValueException("Please provide password to add this cluster to zone");
+            }
         }
 
         List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(clusterId);
@@ -414,21 +438,17 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
 		}
 	}
 
-    private String validateCluster(Long dcId, URI url, String username, String password) throws DiscoveryException {
-        String msg;
-        long vmwareDcId;
+    private VmwareDatacenterVO fetchVmwareDatacenterByZone(Long dcId) throws DiscoveryException {
         VmwareDatacenterVO vmwareDc;
-        String vmwareDcNameFromDb;
-        String vmwareDcNameFromApi;
-        String vCenterHost;
-        String updatedInventoryPath = url.getPath();
-        String clusterName = null;
+        VmwareDatacenterZoneMapVO vmwareDcZone;
+        long vmwareDcId;
+        String msg;
 
         // Check if zone is associated with DC
-        VmwareDatacenterZoneMapVO vmwareDcZone = _vmwareDcZoneMapDao.findByZoneId(dcId);
+        vmwareDcZone = _vmwareDcZoneMapDao.findByZoneId(dcId);
         if (vmwareDcZone == null) {
             msg = "Zone " + dcId + " is not associated with any VMware DC yet. "
-                        + "Please add VMware DC to this zone first and then try to add clusters.";
+                    + "Please add VMware DC to this zone first and then try to add clusters.";
             s_logger.error(msg);
             throw new DiscoveryException(msg);
         }
@@ -436,6 +456,18 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
         // Retrieve DC added to this zone from database
         vmwareDcId = vmwareDcZone.getVmwareDcId();
         vmwareDc = _vmwareDcDao.findById(vmwareDcId);
+
+        return vmwareDc;
+    }
+
+    private String validateCluster(URI url, VmwareDatacenterVO vmwareDc) throws DiscoveryException {
+        String msg;
+        String vmwareDcNameFromDb;
+        String vmwareDcNameFromApi;
+        String vCenterHost;
+        String updatedInventoryPath = url.getPath();
+        String clusterName = null;
+
         vmwareDcNameFromApi = vmwareDcNameFromDb = vmwareDc.getVmwareDatacenterName();
         vCenterHost = vmwareDc.getVcenterHost();
         String inventoryPath = url.getPath();