Search in sources :

Example 31 with Ovm3ResourceException

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

the class Ovm3HypervisorSupportTest method ReportedVmStatesTest.

@Test
public void ReportedVmStatesTest() throws ConfigurationException, Ovm3ResourceException {
    Ovm3Configuration config = new Ovm3Configuration(configTest.getParams());
    con.setResult(xen.getMultipleVmsListXML());
    Ovm3HypervisorSupport hypervisor = new Ovm3HypervisorSupport(con, config);
    hypervisor.vmStateMapClear();
    State vmState = hypervisor.getVmState(vmName);
    results.basicStringTest(vmState.toString(), State.Running.toString());
    hypervisor.setVmStateStarting(vmName);
    results.basicStringTest(hypervisor.getVmState(vmName).toString(), State.Starting.toString());
    hypervisor.setVmState(vmName, State.Running);
    results.basicStringTest(hypervisor.getVmState(vmName).toString(), State.Running.toString());
    hypervisor.revmoveVmState(vmName);
    assertNull(hypervisor.getVmState(vmName));
}
Also used : State(com.cloud.vm.VirtualMachine.State) Test(org.junit.Test) ConnectionTest(com.cloud.hypervisor.ovm3.objects.ConnectionTest) LinuxTest(com.cloud.hypervisor.ovm3.objects.LinuxTest) NetworkTest(com.cloud.hypervisor.ovm3.objects.NetworkTest) XenTest(com.cloud.hypervisor.ovm3.objects.XenTest) Ovm3SupportTest(com.cloud.hypervisor.ovm3.support.Ovm3SupportTest) XmlTestResultTest(com.cloud.hypervisor.ovm3.objects.XmlTestResultTest)

Example 32 with Ovm3ResourceException

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

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

the class Ovm3StorageProcessor method createTemplateFromSnapshot.

/**
     * Copies from secondary to secondary
     */
@Override
public Answer createTemplateFromSnapshot(CopyCommand cmd) {
    LOGGER.debug("execute createTemplateFromSnapshot: " + cmd.getClass());
    try {
        // src.getPath contains the uuid of the snapshot.
        DataTO srcData = cmd.getSrcTO();
        SnapshotObjectTO srcSnap = (SnapshotObjectTO) srcData;
        String secPoolUuid = pool.setupSecondaryStorage(srcData.getDataStore().getUrl());
        String srcFile = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + srcSnap.getPath();
        // dest
        DataTO destData = cmd.getDestTO();
        TemplateObjectTO destTemplate = (TemplateObjectTO) destData;
        String secPoolUuidTemplate = pool.setupSecondaryStorage(destData.getDataStore().getUrl());
        String destDir = config.getAgentSecStoragePath() + "/" + secPoolUuidTemplate + "/" + destTemplate.getPath();
        String destFile = destDir + "/" + destTemplate.getUuid() + ".raw";
        CloudstackPlugin csp = new CloudstackPlugin(c);
        csp.ovsMkdirs(destDir);
        Linux host = new Linux(c);
        host.copyFile(srcFile, destFile);
        TemplateObjectTO newVol = new TemplateObjectTO();
        newVol.setUuid(destTemplate.getUuid());
        newVol.setPath(destTemplate.getUuid());
        newVol.setFormat(ImageFormat.RAW);
        return new CopyCmdAnswer(newVol);
    } 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) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 34 with Ovm3ResourceException

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

the class Ovm3StoragePool method setupPool.

/**
     * Setup a pool in general, this creates a repo if it doesn't exist yet, if
     * it does however we mount it.
     *
     * @param cmd
     * @return
     * @throws Ovm3ResourceException
     */
private Boolean setupPool(StorageFilerTO cmd) throws Ovm3ResourceException {
    String primUuid = cmd.getUuid();
    String ssUuid = ovmObject.deDash(primUuid);
    String fsType = "nfs";
    String clusterUuid = config.getAgentOwnedByUuid().substring(0, 15);
    String managerId = config.getAgentOwnedByUuid();
    String poolAlias = cmd.getHost() + ":" + cmd.getPath();
    String mountPoint = String.format("%1$s:%2$s", cmd.getHost(), cmd.getPath()) + "/VirtualMachines";
    Integer poolSize = 0;
    Pool poolHost = new Pool(c);
    PoolOCFS2 poolFs = new PoolOCFS2(c);
    if (config.getAgentIsMaster()) {
        try {
            LOGGER.debug("Create poolfs on " + config.getAgentHostname() + " for repo " + primUuid);
            /* double check if we're not overwritting anything here!@ */
            poolFs.createPoolFs(fsType, mountPoint, clusterUuid, primUuid, ssUuid, managerId);
        } catch (Ovm3ResourceException e) {
            throw e;
        }
        try {
            poolHost.createServerPool(poolAlias, primUuid, config.getOvm3PoolVip(), poolSize + 1, config.getAgentHostname(), c.getIp());
        } catch (Ovm3ResourceException e) {
            throw e;
        }
    } else if (config.getAgentHasMaster()) {
        try {
            poolHost.joinServerPool(poolAlias, primUuid, config.getOvm3PoolVip(), poolSize + 1, config.getAgentHostname(), c.getIp());
        } catch (Ovm3ResourceException e) {
            throw e;
        }
    }
    try {
        /* should contain check if we're in an OVM pool or not */
        CloudstackPlugin csp = new CloudstackPlugin(c);
        Boolean vip = csp.dom0CheckPort(config.getOvm3PoolVip(), 22, 60, 1);
        if (!vip) {
            throw new Ovm3ResourceException("Unable to reach Ovm3 Pool VIP " + config.getOvm3PoolVip());
        }
        /*
             * should also throw exception, we need to stop pool creation here,
             * or is the manual addition fine?
             */
        if (!addMembers()) {
            return false;
        }
    } catch (Ovm3ResourceException e) {
        throw new Ovm3ResourceException("Unable to add members to pool" + e.getMessage());
    }
    return true;
}
Also used : Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) PoolOCFS2(com.cloud.hypervisor.ovm3.objects.PoolOCFS2) Pool(com.cloud.hypervisor.ovm3.objects.Pool) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin)

Example 35 with Ovm3ResourceException

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

the class Ovm3StoragePool method setupNfsStorage.

/**
     * Sets up NFS Storage
     *
     * @param uri
     * @param uuid
     * @return
     * @throws Ovm3ResourceException
     */
private String setupNfsStorage(URI uri, String uuid) throws Ovm3ResourceException {
    String fsUri = "nfs";
    String msg = "";
    String mountPoint = config.getAgentSecStoragePath() + "/" + uuid;
    Linux host = new Linux(c);
    Map<String, Linux.FileSystem> fsList = host.getFileSystemMap(fsUri);
    Linux.FileSystem fs = fsList.get(uuid);
    if (fs == null || !fs.getRemoteDir().equals(mountPoint)) {
        try {
            StoragePlugin sp = new StoragePlugin(c);
            sp.storagePluginMountNFS(uri.getHost(), uri.getPath(), uuid, mountPoint);
            msg = "Nfs storage " + uri + " mounted on " + mountPoint;
            return uuid;
        } catch (Ovm3ResourceException ec) {
            msg = "Nfs storage " + uri + " mount on " + mountPoint + " FAILED " + ec.getMessage();
            LOGGER.error(msg);
            throw ec;
        }
    } else {
        msg = "NFS storage " + uri + " already mounted on " + mountPoint;
        return uuid;
    }
}
Also used : Linux(com.cloud.hypervisor.ovm3.objects.Linux) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin)

Aggregations

Ovm3ResourceException (com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)41 Linux (com.cloud.hypervisor.ovm3.objects.Linux)13 Test (org.junit.Test)10 Answer (com.cloud.agent.api.Answer)9 DataTO (com.cloud.agent.api.to.DataTO)9 CloudstackPlugin (com.cloud.hypervisor.ovm3.objects.CloudstackPlugin)9 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)8 StoragePlugin (com.cloud.hypervisor.ovm3.objects.StoragePlugin)7 Xen (com.cloud.hypervisor.ovm3.objects.Xen)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 ConfigurationException (javax.naming.ConfigurationException)6 ConnectionTest (com.cloud.hypervisor.ovm3.objects.ConnectionTest)5 Pool (com.cloud.hypervisor.ovm3.objects.Pool)5 XenTest (com.cloud.hypervisor.ovm3.objects.XenTest)5 XmlTestResultTest (com.cloud.hypervisor.ovm3.objects.XmlTestResultTest)5 Ovm3SupportTest (com.cloud.hypervisor.ovm3.support.Ovm3SupportTest)5 CreateObjectAnswer (org.apache.cloudstack.storage.command.CreateObjectAnswer)5 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)5 CopyVolumeAnswer (com.cloud.agent.api.storage.CopyVolumeAnswer)4 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)4