use of com.cloud.agent.api.check.CheckSshAnswer in project cloudstack by apache.
the class SecondaryStorageManagerImpl method finalizeStart.
@Override
public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) {
CheckSshAnswer answer = (CheckSshAnswer) cmds.getAnswer("checkSsh");
if (!answer.getResult()) {
s_logger.warn("Unable to ssh to the VM: " + answer.getDetails());
return false;
}
try {
//get system ip and create static nat rule for the vm in case of basic networking with EIP/ELB
_rulesMgr.getSystemIpAndEnableStaticNatForVm(profile.getVirtualMachine(), false);
IPAddressVO ipaddr = _ipAddressDao.findByAssociatedVmId(profile.getVirtualMachine().getId());
if (ipaddr != null && ipaddr.getSystem()) {
SecondaryStorageVmVO secVm = _secStorageVmDao.findById(profile.getId());
// override SSVM guest IP with EIP, so that download url's with be prepared with EIP
secVm.setPublicIpAddress(ipaddr.getAddress().addr());
_secStorageVmDao.update(secVm.getId(), secVm);
}
} catch (Exception ex) {
s_logger.warn("Failed to get system ip and enable static nat for the vm " + profile.getVirtualMachine() + " due to exception ", ex);
return false;
}
return true;
}
use of com.cloud.agent.api.check.CheckSshAnswer in project cloudstack by apache.
the class VmwareResource method execute.
protected CheckSshAnswer execute(CheckSshCommand cmd) {
String vmName = cmd.getName();
String privateIp = cmd.getIp();
int cmdPort = cmd.getPort();
if (s_logger.isDebugEnabled()) {
s_logger.debug("Ping command port, " + privateIp + ":" + cmdPort);
}
try {
String result = connect(cmd.getName(), privateIp, cmdPort);
if (result != null) {
s_logger.error("Can not ping System vm " + vmName + "due to:" + result);
return new CheckSshAnswer(cmd, "Can not ping System vm " + vmName + "due to:" + result);
}
} catch (Exception e) {
s_logger.error("Can not ping System vm " + vmName + "due to exception");
return new CheckSshAnswer(cmd, e);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Ping command port succeeded for vm " + vmName);
}
if (VirtualMachineName.isValidRouterName(vmName)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Execute network usage setup command on " + vmName);
}
networkUsage(privateIp, "create", null);
}
return new CheckSshAnswer(cmd);
}
use of com.cloud.agent.api.check.CheckSshAnswer in project cloudstack by apache.
the class ElasticLoadBalancerManagerImplTest method testFinalizeStartWhenCmdsAnswerIsNotNullButAnswerResultIsFalse.
@Test
public void testFinalizeStartWhenCmdsAnswerIsNotNullButAnswerResultIsFalse() throws Exception {
CheckSshAnswer answerMock = mock(CheckSshAnswer.class);
when(answerMock.getResult()).thenReturn(false);
VirtualMachineProfile profileMock = mock(VirtualMachineProfile.class);
long hostId = 1L;
Commands cmds = mock(Commands.class);
when(cmds.getAnswer("checkSsh")).thenReturn(answerMock);
ReservationContext context = mock(ReservationContext.class);
boolean expected = false;
boolean actual = elasticLoadBalancerManagerImpl.finalizeStart(profileMock, hostId, cmds, context);
assertEquals(expected, actual);
}
use of com.cloud.agent.api.check.CheckSshAnswer in project cloudstack by apache.
the class ElasticLoadBalancerManagerImplTest method testFinalizeStartWhenCmdsAnswerIsNotNullAndAnswerResultIsTrue.
@Test
public void testFinalizeStartWhenCmdsAnswerIsNotNullAndAnswerResultIsTrue() throws Exception {
CheckSshAnswer answerMock = mock(CheckSshAnswer.class);
when(answerMock.getResult()).thenReturn(true);
VirtualMachineProfile profileMock = mock(VirtualMachineProfile.class);
long hostId = 1L;
Commands cmds = mock(Commands.class);
when(cmds.getAnswer("checkSsh")).thenReturn(answerMock);
ReservationContext context = mock(ReservationContext.class);
boolean expected = true;
boolean actual = elasticLoadBalancerManagerImpl.finalizeStart(profileMock, hostId, cmds, context);
assertEquals(expected, actual);
}
use of com.cloud.agent.api.check.CheckSshAnswer in project cloudstack by apache.
the class HypervDirectConnectResource method execute.
protected CheckSshAnswer execute(final CheckSshCommand cmd) {
final String vmName = cmd.getName();
final String privateIp = cmd.getIp();
final int cmdPort = cmd.getPort();
if (s_logger.isDebugEnabled()) {
s_logger.debug("Ping command port, " + privateIp + ":" + cmdPort);
}
try {
final String result = connect(cmd.getName(), privateIp, cmdPort);
if (result != null) {
s_logger.error("Can not ping System vm " + vmName + "due to:" + result);
return new CheckSshAnswer(cmd, "Can not ping System vm " + vmName + "due to:" + result);
}
} catch (final Exception e) {
s_logger.error("Can not ping System vm " + vmName + "due to exception");
return new CheckSshAnswer(cmd, e);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Ping command port succeeded for vm " + vmName);
}
if (VirtualMachineName.isValidRouterName(vmName)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Execute network usage setup command on " + vmName);
}
networkUsage(privateIp, "create", null);
}
return new CheckSshAnswer(cmd);
}
Aggregations