Search in sources :

Example 6 with CheckSshAnswer

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;
}
Also used : CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) IPAddressVO(com.cloud.network.dao.IPAddressVO) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) URISyntaxException(java.net.URISyntaxException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException)

Example 7 with CheckSshAnswer

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);
}
Also used : CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Example 8 with CheckSshAnswer

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);
}
Also used : CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) Commands(com.cloud.agent.manager.Commands) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Example 9 with CheckSshAnswer

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);
}
Also used : CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) Commands(com.cloud.agent.manager.Commands) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Example 10 with CheckSshAnswer

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);
}
Also used : CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ClientProtocolException(org.apache.http.client.ClientProtocolException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) CertificateException(java.security.cert.CertificateException)

Aggregations

CheckSshAnswer (com.cloud.agent.api.check.CheckSshAnswer)11 ConfigurationException (javax.naming.ConfigurationException)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 InternalErrorException (com.cloud.exception.InternalErrorException)3 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 Commands (com.cloud.agent.manager.Commands)2 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)2 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)2 IPAddressVO (com.cloud.network.dao.IPAddressVO)2 UnableDeleteHostException (com.cloud.resource.UnableDeleteHostException)2 ReservationContext (com.cloud.vm.ReservationContext)2 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)2 ConnectException (java.net.ConnectException)2 RemoteException (java.rmi.RemoteException)2 Test (org.junit.Test)2 Answer (com.cloud.agent.api.Answer)1 GetDomRVersionAnswer (com.cloud.agent.api.GetDomRVersionAnswer)1