| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c6b1961 commit fe667e9
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,6 +43,8 @@ | |||
| 43 | 43 | import com.cloud.agent.api.Answer; | |
| 44 | 44 | import com.cloud.agent.api.Command; | |
| 45 | 45 | import com.cloud.agent.api.CronCommand; | |
| 46 | + import com.cloud.agent.api.MaintainAnswer; | ||
| 47 | + import com.cloud.agent.api.MaintainCommand; | ||
| 46 | 48 | import com.cloud.agent.api.ModifySshKeysCommand; | |
| 47 | 49 | import com.cloud.agent.api.PingCommand; | |
| 48 | 50 | import com.cloud.agent.api.ShutdownCommand; | |
@@ -476,6 +478,11 @@ protected void processRequest(final Request request, final Link link) { | |||
| 476 | 478 | cancelTasks(); | |
| 477 | 479 | _reconnectAllowed = false; | |
| 478 | 480 | answer = new Answer(cmd, true, null); | |
| 481 | + } else if (cmd instanceof MaintainCommand) { | ||
| 482 | + s_logger.debug("Received maintainCommand" ); | ||
| 483 | + cancelTasks(); | ||
| 484 | + _reconnectAllowed = false; | ||
| 485 | + answer = new MaintainAnswer((MaintainCommand)cmd); | ||
| 479 | 486 | } else if (cmd instanceof AgentControlCommand) { | |
| 480 | 487 | answer = null; | |
| 481 | 488 | synchronized (_controlListeners) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -242,6 +242,13 @@ public Map<? extends ServerResource, Map<String, String>> find(long dcId, | |||
| 242 | 242 | cluster.setGuid(UUID.nameUUIDFromBytes(String.valueOf(clusterId).getBytes()).toString()); | |
| 243 | 243 | _clusterDao.update(clusterId, cluster); | |
| 244 | 244 | } | |
| 245 | + | ||
| 246 | + //save user name and password | ||
| 247 | + _hostDao.loadDetails(connectedHost); | ||
| 248 | + Map<String, String> hostDetails = connectedHost.getDetails(); | ||
| 249 | + hostDetails.put("password", password); | ||
| 250 | + hostDetails.put("username", username); | ||
| 251 | + _hostDao.saveDetails(connectedHost); | ||
| 245 | 252 | return resources; | |
| 246 | 253 | } catch (DiscoveredWithErrorException e){ | |
| 247 | 254 | throw e; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,7 @@ | |||
| 17 | 17 | */ | |
| 18 | 18 | package com.cloud.resource; | |
| 19 | 19 | ||
| 20 | + import java.io.IOException; | ||
| 20 | 21 | import java.net.URI; | |
| 21 | 22 | import java.net.URISyntaxException; | |
| 22 | 23 | import java.net.URLDecoder; | |
@@ -138,6 +139,8 @@ | |||
| 138 | 139 | import com.cloud.utils.fsm.NoTransitionException; | |
| 139 | 140 | import com.cloud.utils.net.Ip; | |
| 140 | 141 | import com.cloud.utils.net.NetUtils; | |
| 142 | + import com.cloud.utils.ssh.SSHCmdHelper; | ||
| 143 | + import com.cloud.utils.ssh.sshException; | ||
| 141 | 144 | import com.cloud.vm.VMInstanceVO; | |
| 142 | 145 | import com.cloud.vm.VirtualMachine.State; | |
| 143 | 146 | import com.cloud.vm.VirtualMachineManager; | |
@@ -1040,8 +1043,7 @@ private boolean doMaintain(final long hostId) { | |||
| 1040 | 1043 | HostVO host = _hostDao.findById(hostId); | |
| 1041 | 1044 | MaintainAnswer answer = (MaintainAnswer) _agentMgr.easySend(hostId, new MaintainCommand()); | |
| 1042 | 1045 | if (answer == null || !answer.getResult()) { | |
| 1043 | - s_logger.warn("Unable to put host in maintainance mode: " + hostId); | ||
| 1044 | - return false; | ||
| 1046 | + s_logger.warn("Unable to send MaintainCommand to host: " + hostId); | ||
| 1045 | 1047 | } | |
| 1046 | 1048 | ||
| 1047 | 1049 | try { | |
@@ -1805,6 +1807,29 @@ private boolean doCancelMaintenance(long hostId) { | |||
| 1805 | 1807 | try { | |
| 1806 | 1808 | resourceStateTransitTo(host, ResourceState.Event.AdminCancelMaintenance, _nodeId); | |
| 1807 | 1809 | _agentMgr.pullAgentOutMaintenance(hostId); | |
| 1810 | + | ||
| 1811 | + //for kvm, need to log into kvm host, restart cloud-agent | ||
| 1812 | + if (host.getHypervisorType() == HypervisorType.KVM) { | ||
| 1813 | + _hostDao.loadDetails(host); | ||
| 1814 | + String password = host.getDetail("password"); | ||
| 1815 | + String username = host.getDetail("username"); | ||
| 1816 | + if (password == null || username == null) { | ||
| 1817 | + s_logger.debug("Can't find password/username"); | ||
| 1818 | + return false; | ||
| 1819 | + } | ||
| 1820 | + com.trilead.ssh2.Connection connection = SSHCmdHelper.acquireAuthorizedConnection(host.getPrivateIpAddress(), 22, username, password); | ||
| 1821 | + if (connection == null) { | ||
| 1822 | + s_logger.debug("Failed to connect to host: " + host.getPrivateIpAddress()); | ||
| 1823 | + return false; | ||
| 1824 | + } | ||
| 1825 | + | ||
| 1826 | + try { | ||
| 1827 | + SSHCmdHelper.sshExecuteCmdOneShot(connection, "service cloud-agent restart"); | ||
| 1828 | + } catch (sshException e) { | ||
| 1829 | + return false; | ||
| 1830 | + } | ||
| 1831 | + } | ||
| 1832 | + | ||
| 1808 | 1833 | return true; | |
| 1809 | 1834 | } catch (NoTransitionException e) { | |
| 1810 | 1835 | s_logger.debug("Cannot transmit host " + host.getId() + "to Enabled state", e); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments