Search in sources :

Example 1 with CheckSshAnswer

use of com.cloud.agent.api.check.CheckSshAnswer in project cloudstack by apache.

the class LibvirtCheckSshCommandWrapper method execute.

@Override
public Answer execute(final CheckSshCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final String vmName = command.getName();
    final String privateIp = command.getIp();
    final int cmdPort = command.getPort();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Ping command port, " + privateIp + ":" + cmdPort);
    }
    final VirtualRoutingResource virtRouterResource = libvirtComputingResource.getVirtRouterResource();
    if (!virtRouterResource.connect(privateIp, cmdPort)) {
        return new CheckSshAnswer(command, "Can not ping System vm " + vmName + " because of a connection failure");
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Ping command port succeeded for vm " + vmName);
    }
    return new CheckSshAnswer(command);
}
Also used : CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) VirtualRoutingResource(com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource)

Example 2 with CheckSshAnswer

use of com.cloud.agent.api.check.CheckSshAnswer in project cloudstack by apache.

the class InternalLoadBalancerVMManagerImpl method finalizeStart.

@Override
public boolean finalizeStart(final VirtualMachineProfile profile, final long hostId, final Commands cmds, final ReservationContext context) {
    DomainRouterVO internalLbVm = _internalLbVmDao.findById(profile.getId());
    boolean result = true;
    Answer answer = cmds.getAnswer("checkSsh");
    if (answer != null && answer instanceof CheckSshAnswer) {
        final CheckSshAnswer sshAnswer = (CheckSshAnswer) answer;
        if (sshAnswer == null || !sshAnswer.getResult()) {
            s_logger.warn("Unable to ssh to the internal LB VM: " + sshAnswer.getDetails());
            result = false;
        }
    } else {
        result = false;
    }
    if (result == false) {
        return result;
    }
    //Get guest network info
    final List<Network> guestNetworks = new ArrayList<Network>();
    final List<? extends Nic> internalLbVmNics = _nicDao.listByVmId(profile.getId());
    for (final Nic internalLbVmNic : internalLbVmNics) {
        final Network network = _ntwkModel.getNetwork(internalLbVmNic.getNetworkId());
        if (network.getTrafficType() == TrafficType.Guest) {
            guestNetworks.add(network);
        }
    }
    answer = cmds.getAnswer("getDomRVersion");
    if (answer != null && answer instanceof GetDomRVersionAnswer) {
        final GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer) answer;
        if (answer == null || !answer.getResult()) {
            s_logger.warn("Unable to get the template/scripts version of internal LB VM " + internalLbVm.getInstanceName() + " due to: " + versionAnswer.getDetails());
            result = false;
        } else {
            internalLbVm.setTemplateVersion(versionAnswer.getTemplateVersion());
            internalLbVm.setScriptsVersion(versionAnswer.getScriptsVersion());
            internalLbVm = _internalLbVmDao.persist(internalLbVm, guestNetworks);
        }
    } else {
        result = false;
    }
    return result;
}
Also used : CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) Answer(com.cloud.agent.api.Answer) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) Nic(com.cloud.vm.Nic) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 3 with CheckSshAnswer

use of com.cloud.agent.api.check.CheckSshAnswer in project cloudstack by apache.

the class ConsoleProxyManagerImpl method finalizeStart.

@Override
public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) {
    CheckSshAnswer answer = (CheckSshAnswer) cmds.getAnswer("checkSsh");
    if (answer == null || !answer.getResult()) {
        if (answer != null) {
            s_logger.warn("Unable to ssh to the VM: " + answer.getDetails());
        } else {
            s_logger.warn("Unable to ssh to the VM: null answer");
        }
        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()) {
            ConsoleProxyVO consoleVm = _consoleProxyDao.findById(profile.getId());
            // override CPVM guest IP with EIP, so that console url's will be prepared with EIP
            consoleVm.setPublicIpAddress(ipaddr.getAddress().addr());
            _consoleProxyDao.update(consoleVm.getId(), consoleVm);
        }
    } 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) IPAddressVO(com.cloud.network.dao.IPAddressVO) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException)

Example 4 with CheckSshAnswer

use of com.cloud.agent.api.check.CheckSshAnswer in project cloudstack by apache.

the class Ovm3VirtualRoutingSupport method execute.

public CheckSshAnswer execute(CheckSshCommand cmd) {
    String vmName = cmd.getName();
    String privateIp = cmd.getIp();
    int cmdPort = cmd.getPort();
    int interval = cmd.getInterval();
    int retries = cmd.getRetries();
    try {
        CloudstackPlugin cSp = new CloudstackPlugin(c);
        if (!cSp.dom0CheckPort(privateIp, cmdPort, retries, interval)) {
            String msg = "Port " + cmdPort + " not reachable for " + vmName + ": " + config.getAgentHostname();
            LOGGER.info(msg);
            return new CheckSshAnswer(cmd, msg);
        }
    } catch (Exception e) {
        String msg = "Can not reach port " + cmdPort + " on System vm " + vmName + ": " + config.getAgentHostname() + " due to exception: " + e;
        LOGGER.error(msg);
        return new CheckSshAnswer(cmd, msg);
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Ping " + cmdPort + " succeeded for vm " + vmName + ": " + config.getAgentHostname() + " " + cmd);
    }
    return new CheckSshAnswer(cmd);
}
Also used : CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin)

Example 5 with CheckSshAnswer

use of com.cloud.agent.api.check.CheckSshAnswer in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource 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 = _virtRouterResource.connect(privateIp, cmdPort);
        if (result != null) {
            return new CheckSshAnswer(cmd, "Can not ping System vm " + vmName + "due to:" + result);
        }
    } catch (Exception e) {
        return new CheckSshAnswer(cmd, e);
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Ping command port succeeded for vm " + vmName);
    }
    return new CheckSshAnswer(cmd);
}
Also used : CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) URISyntaxException(java.net.URISyntaxException) LibvirtException(org.libvirt.LibvirtException) FileNotFoundException(java.io.FileNotFoundException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException)

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