bug 6451: host username/password should be changable through API

Propogate update password to other managment server nodes in a cluster.
This commit is contained in:
Abhinandan Prateek 2011-05-16 15:57:35 +05:30
parent 6707048fd5
commit 542e3d6f53
3 changed files with 41 additions and 2 deletions

View File

@ -72,7 +72,8 @@ public enum Status {
ManagementServerDown(false, "Management Server that the agent is connected is going down"),
WaitedTooLong(false, "Waited too long from the agent to reconnect on its own. Time to do HA"),
Remove(true, "Host is removed"),
Ready(false, "Host is ready for commands");
Ready(false, "Host is ready for commands"),
UpdatePassword(false, "Update host password from db");
private final boolean isUserRequest;
private final String comment;

View File

@ -77,6 +77,7 @@ import com.cloud.agent.manager.allocator.PodAllocator;
import com.cloud.agent.transport.Request;
import com.cloud.agent.transport.Response;
import com.cloud.alert.AlertManager;
import com.cloud.api.ApiConstants;
import com.cloud.api.commands.AddClusterCmd;
import com.cloud.api.commands.AddHostCmd;
import com.cloud.api.commands.AddSecondaryStorageCmd;
@ -208,6 +209,8 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
@Inject
protected HostDao _hostDao = null;
@Inject
protected DetailsDao _detailsDao = null;
@Inject
protected DataCenterDao _dcDao = null;
@Inject
protected DataCenterIpAddressDao _privateIPAddressDao = null;
@ -1227,7 +1230,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
agent.updatePassword(cmd);
}
}
return false;
return true;
}
@DB
@ -2096,6 +2099,17 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
} else if (event == Event.ShutdownRequested) {
return reconnect(hostId);
}
else if (event == Event.UpdatePassword) {
AgentAttache attache = findAttache(hostId);
DetailVO nv = _detailsDao.findDetail(hostId, ApiConstants.USERNAME);
String username = nv.getValue();
nv = _detailsDao.findDetail(hostId, ApiConstants.PASSWORD);
String password = nv.getValue();
UpdateHostPasswordCommand cmd = new UpdateHostPasswordCommand(username, password);
if (attache != null) {
attache.updatePassword(cmd);
}
}
return false;
}

View File

@ -26,9 +26,11 @@ import com.cloud.agent.AgentManager;
import com.cloud.agent.api.CancelCommand;
import com.cloud.agent.api.ChangeAgentCommand;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.UpdateHostPasswordCommand;
import com.cloud.agent.transport.Request;
import com.cloud.agent.transport.Request.Version;
import com.cloud.agent.transport.Response;
import com.cloud.api.commands.UpdateHostPasswordCmd;
import com.cloud.cluster.ClusterManager;
import com.cloud.cluster.ClusterManagerListener;
import com.cloud.cluster.ManagementServerHostVO;
@ -318,6 +320,28 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
return super.deleteHost(hostId, isForced, caller);
}
@Override
public boolean updateHostPassword(UpdateHostPasswordCmd upasscmd) {
if (upasscmd.getClusterId() == null) {
//update agent attache password
try {
Boolean result = _clusterMgr.propagateAgentEvent(upasscmd.getHostId(), Event.UpdatePassword);
} catch (AgentUnavailableException e) {
}
}
else {
// get agents for the cluster
List<HostVO> hosts = _hostDao.listByCluster(upasscmd.getClusterId());
for (HostVO h : hosts) {
try {
Boolean result = _clusterMgr.propagateAgentEvent(h.getId(), Event.UpdatePassword);
} catch (AgentUnavailableException e) {
}
}
}
return super.updateHostPassword(upasscmd);
}
public void notifyNodesInCluster(AgentAttache attache) {
s_logger.debug("Notifying other nodes of to disconnect");