Search in sources :

Example 1 with CloudstackPlugin

use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin in project cloudstack by apache.

the class Ovm3HypervisorSupport method masterCheck.

/**
     * materCheck
     *
     * @return
     */
public boolean masterCheck() {
    if ("".equals(config.getOvm3PoolVip())) {
        LOGGER.debug("No cluster vip, not checking for master");
        return false;
    }
    try {
        CloudstackPlugin cSp = new CloudstackPlugin(c);
        if (cSp.dom0HasIp(config.getOvm3PoolVip())) {
            LOGGER.debug(config.getAgentHostname() + " is a master, already has vip " + config.getOvm3PoolVip());
            config.setAgentIsMaster(true);
        } else if (cSp.ping(config.getOvm3PoolVip())) {
            LOGGER.debug(config.getAgentHostname() + " has a master, someone has vip " + config.getOvm3PoolVip());
            config.setAgentHasMaster(true);
        } else {
            LOGGER.debug(config.getAgentHostname() + " becomes a master, no one has vip " + config.getOvm3PoolVip());
            config.setAgentIsMaster(true);
        }
    } catch (Ovm3ResourceException e) {
        LOGGER.debug(config.getAgentHostname() + " can't reach master: " + e.getMessage());
        config.setAgentHasMaster(false);
    }
    return config.getAgentIsMaster();
}
Also used : Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin)

Example 2 with CloudstackPlugin

use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin in project cloudstack by apache.

the class Ovm3HypervisorResource method execute.

@Override
public synchronized StartAnswer execute(StartCommand cmd) {
    VirtualMachineTO vmSpec = cmd.getVirtualMachine();
    String vmName = vmSpec.getName();
    State state = State.Stopped;
    Xen xen = new Xen(c);
    try {
        hypervisorsupport.setVmStateStarting(vmName);
        Xen.Vm vm = xen.getVmConfig();
        /* max and min ? */
        vm.setVmCpus(vmSpec.getCpus());
        /* in mb not in bytes */
        vm.setVmMemory(vmSpec.getMinRam() / 1024 / 1024);
        vm.setVmUuid(UUID.nameUUIDFromBytes(vmSpec.getName().getBytes(Charset.defaultCharset())).toString());
        vm.setVmName(vmName);
        String domType = guesttypes.getOvm3GuestType(vmSpec.getOs());
        if (domType == null || domType.isEmpty()) {
            domType = "default";
            LOGGER.debug("VM Virt type missing setting to: " + domType);
        } else {
            LOGGER.debug("VM Virt type set to " + domType + " for " + vmSpec.getOs());
        }
        vm.setVmDomainType(domType);
        if (vmSpec.getBootloader() == BootloaderType.CD) {
            LOGGER.warn("CD booting is not supported");
        }
        /*
             * officially CD boot is only supported on HVM, although there is a
             * simple way around it..
             */
        vmsupport.createVbds(vm, vmSpec);
        if (vmSpec.getType() != VirtualMachine.Type.User) {
            // double check control network if we run a non user VM
            hypervisornetwork.configureNetworking();
            vm.setVmExtra(vmSpec.getBootArgs().replace(" ", "%"));
            String svmPath = configuration.getAgentOvmRepoPath() + "/" + ovmObject.deDash(vm.getPrimaryPoolUuid()) + "/ISOs";
            String svmIso = svmPath + "/" + storagepool.getSystemVMPatchIsoFile().getName();
            vm.addIso(svmIso);
        }
        /* OVS/Network stuff should go here! */
        vmsupport.createVifs(vm, vmSpec);
        vm.setupVifs();
        vm.setVnc("0.0.0.0", vmSpec.getVncPassword());
        xen.createVm(ovmObject.deDash(vm.getPrimaryPoolUuid()), vm.getVmUuid());
        xen.startVm(ovmObject.deDash(vm.getPrimaryPoolUuid()), vm.getVmUuid());
        state = State.Running;
        if (vmSpec.getType() != VirtualMachine.Type.User) {
            String controlIp = null;
            for (NicTO nic : vmSpec.getNics()) {
                if (nic.getType() == TrafficType.Control) {
                    controlIp = nic.getIp();
                }
            }
            /* fix is in cloudstack.py for xend restart timer */
            for (int count = 0; count < 60; count++) {
                CloudstackPlugin cSp = new CloudstackPlugin(c);
                /* skip a beat to make sure we didn't miss start */
                if (hypervisorsupport.getVmState(vmName) == null && count > 1) {
                    String msg = "VM " + vmName + " went missing on " + configuration.getAgentHostname() + ", returning stopped";
                    LOGGER.debug(msg);
                    state = State.Stopped;
                    return new StartAnswer(cmd, msg);
                }
                /* creative fix? */
                try {
                    Boolean res = cSp.domrCheckSsh(controlIp);
                    LOGGER.debug("connected to " + controlIp + " on attempt " + count + " result: " + res);
                    if (res) {
                        break;
                    }
                } catch (Exception x) {
                    LOGGER.trace("unable to connect to " + controlIp + " on attempt " + count + " " + x.getMessage(), x);
                }
                Thread.sleep(5000);
            }
        }
        /*
             * Can't remember if HA worked if we were only a pool ?
             */
        if (configuration.getAgentInOvm3Pool() && configuration.getAgentInOvm3Cluster()) {
            xen.configureVmHa(ovmObject.deDash(vm.getPrimaryPoolUuid()), vm.getVmUuid(), true);
        }
        /* should be starting no ? */
        state = State.Running;
        return new StartAnswer(cmd);
    } catch (Exception e) {
        LOGGER.debug("Start vm " + vmName + " failed", e);
        state = State.Stopped;
        return new StartAnswer(cmd, e.getMessage());
    } finally {
        hypervisorsupport.setVmState(vmName, state);
    }
}
Also used : Xen(com.cloud.hypervisor.ovm3.objects.Xen) StartAnswer(com.cloud.agent.api.StartAnswer) State(com.cloud.vm.VirtualMachine.State) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) NicTO(com.cloud.agent.api.to.NicTO)

Example 3 with CloudstackPlugin

use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin in project cloudstack by apache.

the class Ovm3VirtualRoutingResource method executeInVR.

@Override
public ExecutionResult executeInVR(String routerIp, String script, String args, Duration timeout) {
    if (!script.contains(domRCloudPath)) {
        script = domRCloudPath + "/" + script;
    }
    String cmd = script + " " + args;
    logger.debug("executeInVR via " + agentName + " on " + routerIp + ": " + cmd);
    try {
        CloudstackPlugin cSp = new CloudstackPlugin(c);
        CloudstackPlugin.ReturnCode result;
        result = cSp.domrExec(routerIp, cmd);
        return new ExecutionResult(result.getRc(), result.getStdOut());
    } catch (Exception e) {
        logger.error("executeInVR FAILED via " + agentName + " on " + routerIp + ":" + cmd + ", " + e.getMessage(), e);
    }
    return new ExecutionResult(false, "");
}
Also used : ExecutionResult(com.cloud.utils.ExecutionResult) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin)

Example 4 with CloudstackPlugin

use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin in project cloudstack by apache.

the class Ovm3StorageProcessor method backupSnapshot.

/**
 * use the cache, or the normal nfs, also delete the leftovers for us
 * also contains object store storage in xenserver.
 */
@Override
public CopyCmdAnswer backupSnapshot(CopyCommand cmd) {
    LOGGER.debug("execute backupSnapshot: " + cmd.getClass());
    try {
        DataTO srcData = cmd.getSrcTO();
        DataTO destData = cmd.getDestTO();
        SnapshotObjectTO src = (SnapshotObjectTO) srcData;
        SnapshotObjectTO dest = (SnapshotObjectTO) destData;
        // src.getPath contains the uuid of the snapshot.
        String srcFile = getVirtualDiskPath(src.getPath(), src.getDataStore().getUuid());
        // destination
        String storeUrl = dest.getDataStore().getUrl();
        String secPoolUuid = pool.setupSecondaryStorage(storeUrl);
        String destDir = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + dest.getPath();
        String destFile = destDir + "/" + src.getPath();
        destFile = destFile.concat(".raw");
        // copy
        Linux host = new Linux(c);
        CloudstackPlugin csp = new CloudstackPlugin(c);
        csp.ovsMkdirs(destDir);
        LOGGER.debug("CopyFrom: " + srcData.getObjectType() + "," + srcFile + " to " + destData.getObjectType() + "," + destFile);
        host.copyFile(srcFile, destFile);
        StoragePlugin sp = new StoragePlugin(c);
        sp.storagePluginDestroy(secPoolUuid, srcFile);
        SnapshotObjectTO newSnap = new SnapshotObjectTO();
        // newSnap.setPath(destFile);
        // damnit frickin crap, no reference whatsoever... could use parent ?
        newSnap.setPath(dest.getPath() + "/" + src.getPath() + ".raw");
        newSnap.setParentSnapshotPath(null);
        return new CopyCmdAnswer(newSnap);
    } catch (Ovm3ResourceException e) {
        String msg = "Error backupSnapshot: " + e.getMessage();
        LOGGER.info(msg);
        return new CopyCmdAnswer(msg);
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) DataTO(com.cloud.agent.api.to.DataTO) Linux(com.cloud.hypervisor.ovm3.objects.Linux) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 5 with CloudstackPlugin

use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin in project cloudstack by apache.

the class Ovm3HypervisorSupport method setupServer.

/**
 * setupServer:
 * Add the cloudstack plugin and setup the agent.
 * Add the ssh keys to the host.
 *
 * @param c
 * @throws IOException
 */
public Boolean setupServer(String key) throws IOException {
    LOGGER.debug("Setup all bits on agent: " + config.getAgentHostname());
    /* version dependent patching ? */
    try {
        com.trilead.ssh2.Connection sshConnection = SSHCmdHelper.acquireAuthorizedConnection(config.getAgentIp(), config.getAgentSshUserName(), config.getAgentSshPassword());
        if (sshConnection == null) {
            throw new ConfigurationException(String.format("Unable to " + "connect to server(IP=%1$s, username=%2$s, " + "password=%3$s", config.getAgentIp(), config.getAgentSshUserName(), config.getAgentSshPassword()));
        }
        SCPClient scp = new SCPClient(sshConnection);
        String userDataScriptDir = "scripts/vm/hypervisor/ovm3/";
        String userDataScriptPath = Script.findScript("", userDataScriptDir);
        if (userDataScriptPath == null) {
            throw new ConfigurationException("Can not find " + userDataScriptDir);
        }
        String mkdir = "mkdir -p " + config.getAgentScriptsDir();
        if (!SSHCmdHelper.sshExecuteCmd(sshConnection, mkdir)) {
            throw new ConfigurationException("Failed " + mkdir + " on " + config.getAgentHostname());
        }
        for (String script : config.getAgentScripts()) {
            script = userDataScriptPath + "/" + script;
            scp.put(script, config.getAgentScriptsDir(), "0755");
        }
        String prepareCmd = String.format(config.getAgentScriptsDir() + "/" + config.getAgentScript() + " --ssl=" + c.getUseSsl() + " " + "--port=" + c.getPort());
        if (!SSHCmdHelper.sshExecuteCmd(sshConnection, prepareCmd)) {
            throw new ConfigurationException("Failed to insert module on " + config.getAgentHostname());
        } else {
            /* because of OVM 3.3.1 (might be 2000) */
            Thread.sleep(5000);
        }
        CloudstackPlugin cSp = new CloudstackPlugin(c);
        cSp.ovsUploadSshKey(config.getAgentSshKeyFileName(), FileUtils.readFileToString(getSystemVMKeyFile(key)));
        cSp.dom0CheckStorageHealthCheck(config.getAgentScriptsDir(), config.getAgentCheckStorageScript(), config.getCsHostGuid(), config.getAgentStorageCheckTimeout(), config.getAgentStorageCheckInterval());
    } catch (Exception es) {
        LOGGER.error("Unexpected exception ", es);
        String msg = "Unable to install module in agent";
        throw new CloudRuntimeException(msg);
    }
    return true;
}
Also used : SCPClient(com.trilead.ssh2.SCPClient) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Aggregations

CloudstackPlugin (com.cloud.hypervisor.ovm3.objects.CloudstackPlugin)16 Ovm3ResourceException (com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)13 ConfigurationException (javax.naming.ConfigurationException)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 CheckOnHostAnswer (com.cloud.agent.api.CheckOnHostAnswer)2 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)2 DataTO (com.cloud.agent.api.to.DataTO)2 Linux (com.cloud.hypervisor.ovm3.objects.Linux)2 ExecutionResult (com.cloud.utils.ExecutionResult)2 State (com.cloud.vm.VirtualMachine.State)2 IOException (java.io.IOException)2 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)2 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)2 Answer (com.cloud.agent.api.Answer)1 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)1 FenceAnswer (com.cloud.agent.api.FenceAnswer)1 GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)1 HostStatsEntry (com.cloud.agent.api.HostStatsEntry)1 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)1 PingRoutingCommand (com.cloud.agent.api.PingRoutingCommand)1