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
This commit is contained in:
wilderrodrigues 2015-07-02 11:12:08 +02:00
parent 96ad6f6ccd
commit a74971df06
4 changed files with 26 additions and 7 deletions

View File

@ -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;
}
}
}

View File

@ -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;
}

View File

@ -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) {

View File

@ -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");
}