Skip to content

Commit a74971d

Browse files
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
1 parent 96ad6f6 commit a74971d

4 files changed

Lines changed: 26 additions & 7 deletions

File tree

api/src/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ public class ApiConstants {
180180
public static final String PARAMS = "params";
181181
public static final String PARENT_DOMAIN_ID = "parentdomainid";
182182
public static final String PASSWORD = "password";
183+
public static final String SHOULD_UPDATE_PASSWORD = "password";
183184
public static final String NEW_PASSWORD = "new_password";
184185
public static final String PASSWORD_ENABLED = "passwordenabled";
185186
public static final String SSHKEY_ENABLED = "sshkeyenabled";
@@ -631,4 +632,4 @@ public enum HostDetails {
631632
public enum VMDetails {
632633
all, group, nics, stats, secgrp, tmpl, servoff, diskoff, iso, volume, min, affgrp;
633634
}
634-
}
635+
}

api/src/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,16 @@ public class UpdateHostPasswordCmd extends BaseCmd {
4444
@Parameter(name = ApiConstants.CLUSTER_ID, type = CommandType.UUID, entityType = ClusterResponse.class, description = "the cluster ID")
4545
private Long clusterId;
4646

47+
@Parameter(name = ApiConstants.SHOULD_UPDATE_PASSWORD, type = CommandType.BOOLEAN, description = "if the password should also be updated on the hosts")
48+
private Boolean shouldUpdateHost;
49+
4750
@Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, required = true, description = "the username for the host/cluster")
4851
private String username;
4952

5053
@Parameter(name = ApiConstants.PASSWORD, type = CommandType.STRING, required = true, description = "the new password for the host/cluster")
5154
private String password;
5255

56+
5357
// ///////////////////////////////////////////////////
5458
// ///////////////// Accessors ///////////////////////
5559
// ///////////////////////////////////////////////////
@@ -62,6 +66,10 @@ public Long getClusterId() {
6266
return clusterId;
6367
}
6468

69+
public Boolean getShouldUpdateHost() {
70+
return shouldUpdateHost;
71+
}
72+
6573
public String getPassword() {
6674
return password;
6775
}

server/src/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,7 @@ private boolean doUpdateHostPassword(final long hostId) {
22402240

22412241
@Override
22422242
public boolean updateClusterPassword(final UpdateHostPasswordCmd command) {
2243+
final boolean shouldUpdateHostPasswd = command.getShouldUpdateHost();
22432244
// get agents for the cluster
22442245
final List<HostVO> hosts = listAllHostsInCluster(command.getClusterId());
22452246
for (final HostVO host : hosts) {
@@ -2255,28 +2256,33 @@ public boolean updateClusterPassword(final UpdateHostPasswordCmd command) {
22552256
} catch (final AgentUnavailableException e) {
22562257
s_logger.error("Agent is not availbale!", e);
22572258
}
2258-
final boolean isUpdated = doUpdateHostPassword(host.getId());
2259-
if (!isUpdated) {
2260-
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.");
2259+
2260+
if (shouldUpdateHostPasswd) {
2261+
final boolean isUpdated = doUpdateHostPassword(host.getId());
2262+
if (!isUpdated) {
2263+
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.");
2264+
}
22612265
}
22622266
}
22632267

22642268
return true;
22652269
}
22662270

22672271
@Override
2268-
public boolean updateHostPassword(final UpdateHostPasswordCmd cmd) {
2272+
public boolean updateHostPassword(final UpdateHostPasswordCmd command) {
22692273
// update agent attache password
22702274
try {
2271-
final Boolean result = propagateResourceEvent(cmd.getHostId(), ResourceState.Event.UpdatePassword);
2275+
final Boolean result = propagateResourceEvent(command.getHostId(), ResourceState.Event.UpdatePassword);
22722276
if (result != null) {
22732277
return result;
22742278
}
22752279
} catch (final AgentUnavailableException e) {
22762280
s_logger.error("Agent is not availbale!", e);
22772281
}
22782282

2279-
return doUpdateHostPassword(cmd.getHostId());
2283+
final boolean shouldUpdateHostPasswd = command.getShouldUpdateHost();
2284+
// If shouldUpdateHostPasswd has been set to false, the method doUpdateHostPassword() won't be called.
2285+
return shouldUpdateHostPasswd && doUpdateHostPassword(command.getHostId());
22802286
}
22812287

22822288
public String getPeerName(final long agentHostId) {

server/src/com/cloud/server/ManagementServerImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3797,6 +3797,10 @@ public boolean updateHostPassword(final UpdateHostPasswordCmd cmd) {
37973797

37983798
final HostVO host = _hostDao.findById(cmd.getHostId());
37993799

3800+
if (host.getHypervisorType() == HypervisorType.XenServer) {
3801+
throw new InvalidParameterValueException("Single host update is not supported by XenServer hypervisors. Please try again informing the Cluster ID.");
3802+
}
3803+
38003804
if (!supportedHypervisors.contains(host.getHypervisorType())) {
38013805
throw new InvalidParameterValueException("This operation is not supported for this hypervisor type");
38023806
}

0 commit comments

Comments
 (0)