Search in sources :

Example 1 with Xen

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

the class Ovm3HypervisorResourceTest method createVm.

public VirtualMachineTO createVm(String vmName) throws Ovm3ResourceException {
    con = support.prepConnectionResults();
    Xen vdata = new Xen(con);
    Xen.Vm vm = vdata.getVmConfig(vmName);
    vdata.listVm(xen.getRepoId(), xen.getVmId());
    // Ovm3VmGuestTypes types = new Ovm3VmGuestTypes();
    Long id = 1L;
    String instanceName = vm.getVmName();
    VirtualMachine.Type type = Type.User;
    // vm.getVmCpus();
    int cpus = 1;
    Integer speed = 0;
    long minRam = vm.getVmMemory();
    long maxRam = vm.getVmMemory();
    BootloaderType bootloader = BootloaderType.PyGrub;
    String os = "Oracle Enterprise Linux 6.0 (64-bit)";
    boolean enableHA = true;
    boolean limitCpuUse = false;
    String vncPassword = "gobbeldygoo";
    VirtualMachineTO vmspec = new VirtualMachineTO(id, instanceName, type, cpus, speed, minRam, maxRam, bootloader, os, enableHA, limitCpuUse, vncPassword);
    vmspec.setBootArgs("");
    addDisksToSpec(vmspec, vm.getVmDisks());
    addNicsToSpec(vmspec, vm.getVmVifs());
    return vmspec;
}
Also used : Xen(com.cloud.hypervisor.ovm3.objects.Xen) Type(com.cloud.vm.VirtualMachine.Type) BootloaderType(com.cloud.template.VirtualMachineTemplate.BootloaderType) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 2 with Xen

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

the class Ovm3VmSupport method execute.

/* do migrations of VMs in a simple way just inside a cluster for now */
public MigrateAnswer execute(final MigrateCommand cmd) {
    final String vmName = cmd.getVmName();
    String destUuid = cmd.getHostGuid();
    String destIp = cmd.getDestinationIp();
    State state = State.Error;
    /*
         * TODO: figure out non pooled migration, works from CLI but not from
         * the agent... perhaps pause the VM and then migrate it ? for now just
         * stop the VM.
         */
    String msg = "Migrating " + vmName + " to " + destIp;
    LOGGER.info(msg);
    if (!config.getAgentInOvm3Cluster() && !config.getAgentInOvm3Pool()) {
        try {
            Xen xen = new Xen(c);
            Xen.Vm vm = xen.getRunningVmConfig(vmName);
            HostVO destHost = resourceMgr.findHostByGuid(destUuid);
            if (destHost == null) {
                msg = "Unable to find migration target host in DB " + destUuid + " with ip " + destIp;
                LOGGER.info(msg);
                return new MigrateAnswer(cmd, false, msg, null);
            }
            xen.stopVm(ovmObject.deDash(vm.getVmRootDiskPoolId()), vm.getVmUuid());
            msg = destHost.toString();
            state = State.Stopping;
            return new MigrateAnswer(cmd, false, msg, null);
        } catch (Ovm3ResourceException e) {
            msg = "Unpooled VM Migrate of " + vmName + " to " + destUuid + " failed due to: " + e.getMessage();
            LOGGER.debug(msg, e);
            return new MigrateAnswer(cmd, false, msg, null);
        } finally {
            /* shouldn't we just reinitialize completely as a last resort ? */
            hypervisor.setVmState(vmName, state);
        }
    } else {
        try {
            Xen xen = new Xen(c);
            Xen.Vm vm = xen.getRunningVmConfig(vmName);
            if (vm == null) {
                state = State.Stopped;
                msg = vmName + " is no running on " + config.getAgentHostname();
                return new MigrateAnswer(cmd, false, msg, null);
            }
            /* not a storage migration!!! */
            xen.migrateVm(ovmObject.deDash(vm.getVmRootDiskPoolId()), vm.getVmUuid(), destIp);
            state = State.Stopping;
            msg = "Migration of " + vmName + " successfull";
            return new MigrateAnswer(cmd, true, msg, null);
        } catch (Ovm3ResourceException e) {
            msg = "Pooled VM Migrate" + ": Migration of " + vmName + " to " + destIp + " failed due to " + e.getMessage();
            LOGGER.debug(msg, e);
            return new MigrateAnswer(cmd, false, msg, null);
        } finally {
            hypervisor.setVmState(vmName, state);
        }
    }
}
Also used : Xen(com.cloud.hypervisor.ovm3.objects.Xen) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) State(com.cloud.vm.VirtualMachine.State) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) HostVO(com.cloud.host.HostVO)

Example 3 with Xen

use of com.cloud.hypervisor.ovm3.objects.Xen 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 4 with Xen

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

the class Ovm3HypervisorResource method execute.

/**
 * Removes the vm and its configuration from the hypervisor.
 */
@Override
public StopAnswer execute(StopCommand cmd) {
    String vmName = cmd.getVmName();
    State state = State.Error;
    hypervisorsupport.setVmState(vmName, State.Stopping);
    try {
        Xen vms = new Xen(c);
        Xen.Vm vm = null;
        vm = vms.getRunningVmConfig(vmName);
        if (vm == null) {
            state = State.Stopping;
            LOGGER.debug("Unable to get details of vm: " + vmName + ", treating it as Stopping");
            return new StopAnswer(cmd, "success", true);
        }
        String repoId = ovmObject.deDash(vm.getVmRootDiskPoolId());
        String vmId = vm.getVmUuid();
        /* can we do without the poolId ? */
        vms.stopVm(repoId, vmId);
        int tries = 30;
        while (vms.getRunningVmConfig(vmName) != null && tries > 0) {
            String msg = "Waiting for " + vmName + " to stop";
            LOGGER.debug(msg);
            tries--;
            Thread.sleep(10 * 1000);
        }
        vms.deleteVm(repoId, vmId);
        vmsupport.cleanup(vm);
        if (vms.getRunningVmConfig(vmName) != null) {
            String msg = "Stop " + vmName + " failed ";
            LOGGER.debug(msg);
            return new StopAnswer(cmd, msg, false);
        }
        state = State.Stopped;
        return new StopAnswer(cmd, "success", true);
    } catch (Exception e) {
        LOGGER.debug("Stop " + vmName + " failed ", e);
        return new StopAnswer(cmd, e.getMessage(), false);
    } finally {
        if (state != null) {
            hypervisorsupport.setVmState(vmName, state);
        } else {
            hypervisorsupport.revmoveVmState(vmName);
        }
    }
}
Also used : Xen(com.cloud.hypervisor.ovm3.objects.Xen) State(com.cloud.vm.VirtualMachine.State) StopAnswer(com.cloud.agent.api.StopAnswer) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 5 with Xen

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

the class Ovm3VirtualRoutingResource method prepNetBoth.

private ExecutionResult prepNetBoth(String routerName, IpAddressTO[] ips, String type) {
    Xen xen = new Xen(c);
    try {
        Xen.Vm vm = xen.getVmConfig(routerName);
        for (IpAddressTO ip : ips) {
            Integer devId = vm.getVifIdByMac(ip.getVifMacAddress());
            if (devId < 0 && "IpAssocVpcCommand".equals(type)) {
                String msg = "No valid Nic devId found for " + vm.getVmName() + " with " + ip.getVifMacAddress();
                logger.error(msg);
                return new ExecutionResult(false, msg);
            } else if (devId < 0 && "IpAssocCommand".equals(type)) {
                // vm.get
                String msg = "No valid Nic devId found for " + vm.getVmName() + " with " + ip.getVifMacAddress() + " " + " Ignoring for now (routervm)";
                logger.debug(msg);
                devId = 2;
            }
            ip.setNicDevId(devId);
        }
    } catch (Exception e) {
        String msg = type + " failure on applying one ip due to exception:  " + e;
        logger.error(msg);
        return new ExecutionResult(false, msg);
    }
    return new ExecutionResult(true, null);
}
Also used : Xen(com.cloud.hypervisor.ovm3.objects.Xen) IpAddressTO(com.cloud.agent.api.to.IpAddressTO) ExecutionResult(com.cloud.utils.ExecutionResult)

Aggregations

Xen (com.cloud.hypervisor.ovm3.objects.Xen)10 Ovm3ResourceException (com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 State (com.cloud.vm.VirtualMachine.State)3 ConfigurationException (javax.naming.ConfigurationException)3 GetVncPortAnswer (com.cloud.agent.api.GetVncPortAnswer)2 MigrateAnswer (com.cloud.agent.api.MigrateAnswer)2 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)2 Answer (com.cloud.agent.api.Answer)1 GetVmStatsAnswer (com.cloud.agent.api.GetVmStatsAnswer)1 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)1 PrepareForMigrationAnswer (com.cloud.agent.api.PrepareForMigrationAnswer)1 RebootAnswer (com.cloud.agent.api.RebootAnswer)1 StartAnswer (com.cloud.agent.api.StartAnswer)1 StopAnswer (com.cloud.agent.api.StopAnswer)1 UnPlugNicAnswer (com.cloud.agent.api.UnPlugNicAnswer)1 DataTO (com.cloud.agent.api.to.DataTO)1 IpAddressTO (com.cloud.agent.api.to.IpAddressTO)1 NicTO (com.cloud.agent.api.to.NicTO)1 HostVO (com.cloud.host.HostVO)1