Search in sources :

Example 6 with PingTestCommand

use of com.cloud.legacymodel.communication.command.PingTestCommand in project cosmic by MissionCriticalCloud.

the class UserVmDomRInvestigator method testUserVM.

private Boolean testUserVM(final VirtualMachine vm, final Nic nic, final VirtualRouter router) {
    final String privateIp = nic.getIPv4Address();
    final String routerPrivateIp = router.getPrivateIpAddress();
    List<Long> otherHosts = new ArrayList<>();
    if (vm.getHypervisorType() == HypervisorType.XenServer || vm.getHypervisorType() == HypervisorType.KVM) {
        otherHosts.add(router.getHostId());
    } else {
        otherHosts = findHostByPod(router.getPodIdToDeployIn(), null);
    }
    for (final Long hostId : otherHosts) {
        try {
            final Answer pingTestAnswer = _agentMgr.easySend(hostId, new PingTestCommand(routerPrivateIp, privateIp));
            if (pingTestAnswer != null && pingTestAnswer.getResult()) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("user vm's " + vm.getHostName() + " ip address " + privateIp + "  has been successfully pinged from the Virtual Router " + router.getHostName() + ", returning that vm is alive");
                }
                return Boolean.TRUE;
            }
        } catch (final Exception e) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Couldn't reach due to", e);
            }
            continue;
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug(vm + " could not be pinged, returning that it is unknown");
    }
    return null;
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) ArrayList(java.util.ArrayList) PingTestCommand(com.cloud.legacymodel.communication.command.PingTestCommand)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)6 PingTestCommand (com.cloud.legacymodel.communication.command.PingTestCommand)6 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)5 Test (org.junit.Test)5 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)3 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)3 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)2 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ArrayList (java.util.ArrayList)1