Search in sources :

Example 6 with Xen

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

the class Ovm3HypervisorResource method execute.

@Override
public RebootAnswer execute(RebootCommand cmd) {
    String vmName = cmd.getVmName();
    hypervisorsupport.setVmStateStarting(vmName);
    try {
        Xen xen = new Xen(c);
        Xen.Vm vm = xen.getRunningVmConfig(vmName);
        if (vm == null) {
            return new RebootAnswer(cmd, vmName + " not present", false);
        }
        xen.rebootVm(ovmObject.deDash(vm.getVmRootDiskPoolId()), vm.getVmUuid());
        vm = xen.getRunningVmConfig(vmName);
        Integer vncPort = vm.getVncPort();
        return new RebootAnswer(cmd, null, vncPort);
    } catch (Exception e) {
        LOGGER.debug("Reboot " + vmName + " failed", e);
        return new RebootAnswer(cmd, e.getMessage(), false);
    } finally {
        hypervisorsupport.setVmState(vmName, State.Running);
    }
}
Also used : Xen(com.cloud.hypervisor.ovm3.objects.Xen) RebootAnswer(com.cloud.agent.api.RebootAnswer) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 7 with Xen

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

the class Ovm3StorageProcessor method createSnapshot.

/**
     * Creates a snapshot from a volume, but only if the VM is stopped.
     * This due qemu not being able to snap raw volumes.
     *
     * if stopped yes, if running ... no, unless we have ocfs2 when
     * using raw partitions (file:) if using tap:aio we cloud...
     * The "ancient" way:
     * We do however follow the "two stage" approach, of "snap"
     * on primary first, with the create object... and then
     * backup the snapshot with the copycmd....
     * (should transfer to createSnapshot, backupSnapshot)
     */
@Override
public Answer createSnapshot(CreateObjectCommand cmd) {
    LOGGER.debug("execute createSnapshot: " + cmd.getClass());
    DataTO data = cmd.getData();
    Xen xen = new Xen(c);
    SnapshotObjectTO snap = (SnapshotObjectTO) data;
    VolumeObjectTO vol = snap.getVolume();
    try {
        Xen.Vm vm = xen.getVmConfig(snap.getVmName());
        if (vm != null) {
            return new CreateObjectAnswer("Snapshot object creation not supported for running VMs." + snap.getVmName());
        }
        Linux host = new Linux(c);
        String uuid = host.newUuid();
        /* for root volumes this works... */
        String src = vol.getPath() + "/" + vol.getUuid() + ".raw";
        String dest = vol.getPath() + "/" + uuid + ".raw";
        /* seems that sometimes the path is already contains a file
             * in case, we just replace it.... (Seems to happen if not ROOT)
             */
        if (vol.getPath().contains(vol.getUuid())) {
            src = getVirtualDiskPath(vol.getUuid(), data.getDataStore().getUuid());
            dest = src.replace(vol.getUuid(), uuid);
        }
        LOGGER.debug("Snapshot " + src + " to " + dest);
        host.copyFile(src, dest);
        SnapshotObjectTO nsnap = new SnapshotObjectTO();
        // nsnap.setPath(dest);
        // move to something that looks the same as xenserver.
        nsnap.setPath(uuid);
        return new CreateObjectAnswer(nsnap);
    } catch (Ovm3ResourceException e) {
        return new CreateObjectAnswer("Snapshot object creation failed. " + e.getMessage());
    }
}
Also used : Xen(com.cloud.hypervisor.ovm3.objects.Xen) 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) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO)

Example 8 with Xen

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

the class Ovm3StorageProcessor method attachDetach.

/**
     * Generic disk attach/detach.
     * @param cmd
     * @param vmName
     * @param disk
     * @param isAttach
     * @return
     */
private AttachAnswer attachDetach(Command cmd, String vmName, DiskTO disk, boolean isAttach) {
    Xen xen = new Xen(c);
    String doThis = (isAttach) ? "Attach" : "Dettach";
    LOGGER.debug(doThis + " volume type " + disk.getType() + "  " + vmName);
    String msg = "";
    String path = "";
    try {
        Xen.Vm vm = xen.getVmConfig(vmName);
        /* check running */
        if (vm == null) {
            msg = doThis + " can't find VM " + vmName;
            LOGGER.debug(msg);
            return new AttachAnswer(msg);
        }
        if (disk.getType() == Volume.Type.ISO) {
            path = getIsoPath(disk);
        } else if (disk.getType() == Volume.Type.DATADISK) {
            path = getVirtualDiskPath(disk, vm.getPrimaryPoolUuid());
        }
        if ("".equals(path)) {
            msg = doThis + " can't do anything with an empty path.";
            LOGGER.debug(msg);
            return new AttachAnswer(msg);
        }
        if (isAttach) {
            if (disk.getType() == Volume.Type.ISO) {
                vm.addIso(path);
            } else {
                vm.addDataDisk(path);
            }
        } else {
            if (!vm.removeDisk(path)) {
                msg = doThis + " failed for " + vmName + disk.getType() + "  was not attached " + path;
                LOGGER.debug(msg);
                return new AttachAnswer(msg);
            }
        }
        xen.configureVm(ovmObject.deDash(vm.getPrimaryPoolUuid()), vm.getVmUuid());
        return new AttachAnswer(disk);
    } catch (Ovm3ResourceException e) {
        msg = doThis + " failed for " + vmName + " " + e.getMessage();
        LOGGER.warn(msg, e);
        return new AttachAnswer(msg);
    }
}
Also used : Xen(com.cloud.hypervisor.ovm3.objects.Xen) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer)

Example 9 with Xen

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

the class Ovm3VmSupport method plugNunplugNic.

/**
     * Implements the unplug and plug feature for Nics, the boolan decides
     * to either plug (true) or unplug (false)
     *
     * @param nic
     * @param vmName
     * @param plug
     * @return
     */
private Answer plugNunplugNic(NicTO nic, String vmName, Boolean plug) {
    try {
        Xen xen = new Xen(c);
        Xen.Vm vm = xen.getVmConfig(vmName);
        /* check running */
        if (vm == null) {
            return new Answer(null, false, "Unable to execute command due to missing VM");
        }
        // setup the NIC in the VM config.
        if (plug) {
            createVif(vm, nic);
            vm.setupVifs();
        } else {
            deleteVif(vm, nic);
        }
        // execute the change
        xen.configureVm(ovmObject.deDash(vm.getPrimaryPoolUuid()), vm.getVmUuid());
    } catch (Ovm3ResourceException e) {
        String msg = "Unable to execute command due to " + e.toString();
        LOGGER.debug(msg);
        return new Answer(null, false, msg);
    }
    return new Answer(null, true, "success");
}
Also used : Xen(com.cloud.hypervisor.ovm3.objects.Xen) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 10 with Xen

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

the class Ovm3VmSupport method execute.

/*
     */
public GetVncPortAnswer execute(GetVncPortCommand cmd) {
    try {
        Xen host = new Xen(c);
        Xen.Vm vm = host.getRunningVmConfig(cmd.getName());
        Integer vncPort = vm.getVncPort();
        LOGGER.debug("get vnc port for " + cmd.getName() + ": " + vncPort);
        return new GetVncPortAnswer(cmd, c.getIp(), vncPort);
    } catch (Ovm3ResourceException e) {
        LOGGER.debug("get vnc port for " + cmd.getName() + " failed", e);
        return new GetVncPortAnswer(cmd, e.getMessage());
    }
}
Also used : Xen(com.cloud.hypervisor.ovm3.objects.Xen) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

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