mirror of https://github.com/apache/cloudstack.git
fix Maintenance releated issues with kvm:
1. put host into Maintenance, will send a Maintenance command to host, tell host that do not reconnect to mgt server 2. cancel Maintenance, will ssh into kvm host, and restart cloud-agent, which will reconnect to host
This commit is contained in:
parent
c6b19615c2
commit
fe667e949e
|
|
@ -43,6 +43,8 @@ import com.cloud.agent.api.AgentControlCommand;
|
|||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.CronCommand;
|
||||
import com.cloud.agent.api.MaintainAnswer;
|
||||
import com.cloud.agent.api.MaintainCommand;
|
||||
import com.cloud.agent.api.ModifySshKeysCommand;
|
||||
import com.cloud.agent.api.PingCommand;
|
||||
import com.cloud.agent.api.ShutdownCommand;
|
||||
|
|
@ -476,6 +478,11 @@ public class Agent implements HandlerFactory, IAgentControl {
|
|||
cancelTasks();
|
||||
_reconnectAllowed = false;
|
||||
answer = new Answer(cmd, true, null);
|
||||
} else if (cmd instanceof MaintainCommand) {
|
||||
s_logger.debug("Received maintainCommand" );
|
||||
cancelTasks();
|
||||
_reconnectAllowed = false;
|
||||
answer = new MaintainAnswer((MaintainCommand)cmd);
|
||||
} else if (cmd instanceof AgentControlCommand) {
|
||||
answer = null;
|
||||
synchronized (_controlListeners) {
|
||||
|
|
|
|||
|
|
@ -242,6 +242,13 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
|
|||
cluster.setGuid(UUID.nameUUIDFromBytes(String.valueOf(clusterId).getBytes()).toString());
|
||||
_clusterDao.update(clusterId, cluster);
|
||||
}
|
||||
|
||||
//save user name and password
|
||||
_hostDao.loadDetails(connectedHost);
|
||||
Map<String, String> hostDetails = connectedHost.getDetails();
|
||||
hostDetails.put("password", password);
|
||||
hostDetails.put("username", username);
|
||||
_hostDao.saveDetails(connectedHost);
|
||||
return resources;
|
||||
} catch (DiscoveredWithErrorException e){
|
||||
throw e;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
package com.cloud.resource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLDecoder;
|
||||
|
|
@ -138,6 +139,8 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
|||
import com.cloud.utils.fsm.NoTransitionException;
|
||||
import com.cloud.utils.net.Ip;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.utils.ssh.SSHCmdHelper;
|
||||
import com.cloud.utils.ssh.sshException;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachineManager;
|
||||
|
|
@ -1040,8 +1043,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
|||
HostVO host = _hostDao.findById(hostId);
|
||||
MaintainAnswer answer = (MaintainAnswer) _agentMgr.easySend(hostId, new MaintainCommand());
|
||||
if (answer == null || !answer.getResult()) {
|
||||
s_logger.warn("Unable to put host in maintainance mode: " + hostId);
|
||||
return false;
|
||||
s_logger.warn("Unable to send MaintainCommand to host: " + hostId);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
@ -1805,6 +1807,29 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
|||
try {
|
||||
resourceStateTransitTo(host, ResourceState.Event.AdminCancelMaintenance, _nodeId);
|
||||
_agentMgr.pullAgentOutMaintenance(hostId);
|
||||
|
||||
//for kvm, need to log into kvm host, restart cloud-agent
|
||||
if (host.getHypervisorType() == HypervisorType.KVM) {
|
||||
_hostDao.loadDetails(host);
|
||||
String password = host.getDetail("password");
|
||||
String username = host.getDetail("username");
|
||||
if (password == null || username == null) {
|
||||
s_logger.debug("Can't find password/username");
|
||||
return false;
|
||||
}
|
||||
com.trilead.ssh2.Connection connection = SSHCmdHelper.acquireAuthorizedConnection(host.getPrivateIpAddress(), 22, username, password);
|
||||
if (connection == null) {
|
||||
s_logger.debug("Failed to connect to host: " + host.getPrivateIpAddress());
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
SSHCmdHelper.sshExecuteCmdOneShot(connection, "service cloud-agent restart");
|
||||
} catch (sshException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.debug("Cannot transmit host " + host.getId() + "to Enabled state", e);
|
||||
|
|
|
|||
Loading…
Reference in New Issue