CLOUDSTACK-8607 - Adding shouldUpdateHost flag - Make sure doUpdateHostPassword() doesn't get called if flag is set to false - Do not update XenServer hosts if the cluster ID is not informed
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a74971df Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a74971df Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a74971df Branch: refs/heads/reporter Commit: a74971df06e04ee2df993a9876bb274d58c9662d Parents: 96ad6f6 Author: wilderrodrigues <wrodrig...@schubergphilis.com> Authored: Thu Jul 2 11:12:08 2015 +0200 Committer: wilderrodrigues <wrodrig...@schubergphilis.com> Committed: Thu Jul 2 11:12:08 2015 +0200 ---------------------------------------------------------------------- .../org/apache/cloudstack/api/ApiConstants.java | 3 ++- .../command/admin/host/UpdateHostPasswordCmd.java | 8 ++++++++ .../com/cloud/resource/ResourceManagerImpl.java | 18 ++++++++++++------ .../com/cloud/server/ManagementServerImpl.java | 4 ++++ 4 files changed, 26 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a74971df/api/src/org/apache/cloudstack/api/ApiConstants.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java index 204f33b..ee98e06 100644 --- a/api/src/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/org/apache/cloudstack/api/ApiConstants.java @@ -180,6 +180,7 @@ public class ApiConstants { public static final String PARAMS = "params"; public static final String PARENT_DOMAIN_ID = "parentdomainid"; public static final String PASSWORD = "password"; + public static final String SHOULD_UPDATE_PASSWORD = "password"; public static final String NEW_PASSWORD = "new_password"; public static final String PASSWORD_ENABLED = "passwordenabled"; public static final String SSHKEY_ENABLED = "sshkeyenabled"; @@ -631,4 +632,4 @@ public class ApiConstants { public enum VMDetails { all, group, nics, stats, secgrp, tmpl, servoff, diskoff, iso, volume, min, affgrp; } -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a74971df/api/src/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java b/api/src/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java index 74b06d7..3915cee 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java @@ -44,12 +44,16 @@ public class UpdateHostPasswordCmd extends BaseCmd { @Parameter(name = ApiConstants.CLUSTER_ID, type = CommandType.UUID, entityType = ClusterResponse.class, description = "the cluster ID") private Long clusterId; + @Parameter(name = ApiConstants.SHOULD_UPDATE_PASSWORD, type = CommandType.BOOLEAN, description = "if the password should also be updated on the hosts") + private Boolean shouldUpdateHost; + @Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, required = true, description = "the username for the host/cluster") private String username; @Parameter(name = ApiConstants.PASSWORD, type = CommandType.STRING, required = true, description = "the new password for the host/cluster") private String password; + // /////////////////////////////////////////////////// // ///////////////// Accessors /////////////////////// // /////////////////////////////////////////////////// @@ -62,6 +66,10 @@ public class UpdateHostPasswordCmd extends BaseCmd { return clusterId; } + public Boolean getShouldUpdateHost() { + return shouldUpdateHost; + } + public String getPassword() { return password; } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a74971df/server/src/com/cloud/resource/ResourceManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index df6071c..b6f7f4e 100644 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -2240,6 +2240,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, @Override public boolean updateClusterPassword(final UpdateHostPasswordCmd command) { + final boolean shouldUpdateHostPasswd = command.getShouldUpdateHost(); // get agents for the cluster final List<HostVO> hosts = listAllHostsInCluster(command.getClusterId()); for (final HostVO host : hosts) { @@ -2255,9 +2256,12 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } catch (final AgentUnavailableException e) { s_logger.error("Agent is not availbale!", e); } - final boolean isUpdated = doUpdateHostPassword(host.getId()); - if (!isUpdated) { - throw new CloudRuntimeException("CloudStack failed to update the password of the Host with UUID/ID ==> " + host.getUuid() + "/" + host.getId() + ". Please make sure you are still able to connect to your hosts."); + + if (shouldUpdateHostPasswd) { + final boolean isUpdated = doUpdateHostPassword(host.getId()); + if (!isUpdated) { + throw new CloudRuntimeException("CloudStack failed to update the password of the Host with UUID/ID ==> " + host.getUuid() + "/" + host.getId() + ". Please make sure you are still able to connect to your hosts."); + } } } @@ -2265,10 +2269,10 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } @Override - public boolean updateHostPassword(final UpdateHostPasswordCmd cmd) { + public boolean updateHostPassword(final UpdateHostPasswordCmd command) { // update agent attache password try { - final Boolean result = propagateResourceEvent(cmd.getHostId(), ResourceState.Event.UpdatePassword); + final Boolean result = propagateResourceEvent(command.getHostId(), ResourceState.Event.UpdatePassword); if (result != null) { return result; } @@ -2276,7 +2280,9 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, s_logger.error("Agent is not availbale!", e); } - return doUpdateHostPassword(cmd.getHostId()); + final boolean shouldUpdateHostPasswd = command.getShouldUpdateHost(); + // If shouldUpdateHostPasswd has been set to false, the method doUpdateHostPassword() won't be called. + return shouldUpdateHostPasswd && doUpdateHostPassword(command.getHostId()); } public String getPeerName(final long agentHostId) { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a74971df/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 acf301f..781c915 100644 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -3797,6 +3797,10 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe final HostVO host = _hostDao.findById(cmd.getHostId()); + if (host.getHypervisorType() == HypervisorType.XenServer) { + throw new InvalidParameterValueException("Single host update is not supported by XenServer hypervisors. Please try again informing the Cluster ID."); + } + if (!supportedHypervisors.contains(host.getHypervisorType())) { throw new InvalidParameterValueException("This operation is not supported for this hypervisor type"); }