Skip to content

Commit 542e3d6

Browse files
author
Abhinandan Prateek
committed
bug 6451: host username/password should be changable through API
Propogate update password to other managment server nodes in a cluster.
1 parent 6707048 commit 542e3d6

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

api/src/com/cloud/host/Status.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public enum Event {
7272
ManagementServerDown(false, "Management Server that the agent is connected is going down"),
7373
WaitedTooLong(false, "Waited too long from the agent to reconnect on its own. Time to do HA"),
7474
Remove(true, "Host is removed"),
75-
Ready(false, "Host is ready for commands");
75+
Ready(false, "Host is ready for commands"),
76+
UpdatePassword(false, "Update host password from db");
7677

7778
private final boolean isUserRequest;
7879
private final String comment;

server/src/com/cloud/agent/manager/AgentManagerImpl.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import com.cloud.agent.transport.Request;
7878
import com.cloud.agent.transport.Response;
7979
import com.cloud.alert.AlertManager;
80+
import com.cloud.api.ApiConstants;
8081
import com.cloud.api.commands.AddClusterCmd;
8182
import com.cloud.api.commands.AddHostCmd;
8283
import com.cloud.api.commands.AddSecondaryStorageCmd;
@@ -208,6 +209,8 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
208209
@Inject
209210
protected HostDao _hostDao = null;
210211
@Inject
212+
protected DetailsDao _detailsDao = null;
213+
@Inject
211214
protected DataCenterDao _dcDao = null;
212215
@Inject
213216
protected DataCenterIpAddressDao _privateIPAddressDao = null;
@@ -1227,7 +1230,7 @@ public boolean updateHostPassword(UpdateHostPasswordCmd upasscmd) {
12271230
agent.updatePassword(cmd);
12281231
}
12291232
}
1230-
return false;
1233+
return true;
12311234
}
12321235

12331236
@DB
@@ -2096,6 +2099,17 @@ public boolean executeUserRequest(long hostId, Event event) throws AgentUnavaila
20962099
} else if (event == Event.ShutdownRequested) {
20972100
return reconnect(hostId);
20982101
}
2102+
else if (event == Event.UpdatePassword) {
2103+
AgentAttache attache = findAttache(hostId);
2104+
DetailVO nv = _detailsDao.findDetail(hostId, ApiConstants.USERNAME);
2105+
String username = nv.getValue();
2106+
nv = _detailsDao.findDetail(hostId, ApiConstants.PASSWORD);
2107+
String password = nv.getValue();
2108+
UpdateHostPasswordCommand cmd = new UpdateHostPasswordCommand(username, password);
2109+
if (attache != null) {
2110+
attache.updatePassword(cmd);
2111+
}
2112+
}
20992113
return false;
21002114
}
21012115

server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
import com.cloud.agent.api.CancelCommand;
2727
import com.cloud.agent.api.ChangeAgentCommand;
2828
import com.cloud.agent.api.Command;
29+
import com.cloud.agent.api.UpdateHostPasswordCommand;
2930
import com.cloud.agent.transport.Request;
3031
import com.cloud.agent.transport.Request.Version;
3132
import com.cloud.agent.transport.Response;
33+
import com.cloud.api.commands.UpdateHostPasswordCmd;
3234
import com.cloud.cluster.ClusterManager;
3335
import com.cloud.cluster.ClusterManagerListener;
3436
import com.cloud.cluster.ManagementServerHostVO;
@@ -318,6 +320,28 @@ public boolean deleteHost(long hostId, boolean isForced, User caller) {
318320

319321
return super.deleteHost(hostId, isForced, caller);
320322
}
323+
324+
@Override
325+
public boolean updateHostPassword(UpdateHostPasswordCmd upasscmd) {
326+
if (upasscmd.getClusterId() == null) {
327+
//update agent attache password
328+
try {
329+
Boolean result = _clusterMgr.propagateAgentEvent(upasscmd.getHostId(), Event.UpdatePassword);
330+
} catch (AgentUnavailableException e) {
331+
}
332+
}
333+
else {
334+
// get agents for the cluster
335+
List<HostVO> hosts = _hostDao.listByCluster(upasscmd.getClusterId());
336+
for (HostVO h : hosts) {
337+
try {
338+
Boolean result = _clusterMgr.propagateAgentEvent(h.getId(), Event.UpdatePassword);
339+
} catch (AgentUnavailableException e) {
340+
}
341+
}
342+
}
343+
return super.updateHostPassword(upasscmd);
344+
}
321345

322346
public void notifyNodesInCluster(AgentAttache attache) {
323347
s_logger.debug("Notifying other nodes of to disconnect");

0 commit comments

Comments
 (0)