Search in sources :

Example 6 with Ovm3ResourceException

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

the class Ovm3StorageProcessor method cloneVolumeFromBaseTemplate.

/**
     * dest is VolumeObject, src is a template
     */
@Override
public CopyCmdAnswer cloneVolumeFromBaseTemplate(CopyCommand cmd) {
    LOGGER.debug("execute cloneVolumeFromBaseTemplate: " + cmd.getClass());
    try {
        // src
        DataTO srcData = cmd.getSrcTO();
        TemplateObjectTO src = (TemplateObjectTO) srcData;
        String srcFile = getVirtualDiskPath(src.getUuid(), src.getDataStore().getUuid());
        srcFile = srcFile.replace(config.getVirtualDiskDir(), config.getTemplateDir());
        DataTO destData = cmd.getDestTO();
        VolumeObjectTO dest = (VolumeObjectTO) destData;
        String destFile = getVirtualDiskPath(dest.getUuid(), dest.getDataStore().getUuid());
        Linux host = new Linux(c);
        LOGGER.debug("CopyFrom: " + srcData.getObjectType() + "," + srcFile + " to " + destData.getObjectType() + "," + destFile);
        host.copyFile(srcFile, destFile);
        VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setUuid(dest.getUuid());
        // was destfile
        newVol.setPath(dest.getUuid());
        newVol.setFormat(ImageFormat.RAW);
        return new CopyCmdAnswer(newVol);
    } catch (Ovm3ResourceException e) {
        String msg = "Error cloneVolumeFromBaseTemplate: " + e.getMessage();
        LOGGER.info(msg);
        return new CopyCmdAnswer(msg);
    }
}
Also used : DataTO(com.cloud.agent.api.to.DataTO) Linux(com.cloud.hypervisor.ovm3.objects.Linux) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 7 with Ovm3ResourceException

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

the class Ovm3StorageProcessor method createVolume.

/**
     * Creates a volume, just a normal empty volume.
     */
@Override
public Answer createVolume(CreateObjectCommand cmd) {
    LOGGER.debug("execute createVolume: " + cmd.getClass());
    DataTO data = cmd.getData();
    VolumeObjectTO volume = (VolumeObjectTO) data;
    try {
        /*
             * public Boolean storagePluginCreate(String uuid, String ssuuid,
             * String host, String file, Integer size)
             */
        String poolUuid = data.getDataStore().getUuid();
        String storeUrl = data.getDataStore().getUrl();
        URI uri = new URI(storeUrl);
        String host = uri.getHost();
        String file = getVirtualDiskPath(volume.getUuid(), poolUuid);
        Long size = volume.getSize();
        StoragePlugin sp = new StoragePlugin(c);
        FileProperties fp = sp.storagePluginCreate(poolUuid, host, file, size, false);
        if (!fp.getName().equals(file)) {
            return new CreateObjectAnswer("Filename mismatch: " + fp.getName() + " != " + file);
        }
        VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setName(volume.getName());
        newVol.setSize(fp.getSize());
        newVol.setPath(volume.getUuid());
        return new CreateObjectAnswer(newVol);
    } catch (Ovm3ResourceException | URISyntaxException e) {
        LOGGER.info("Volume creation failed: " + e.toString(), e);
        return new CreateObjectAnswer(e.toString());
    }
}
Also used : FileProperties(com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties) DataTO(com.cloud.agent.api.to.DataTO) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin)

Example 8 with Ovm3ResourceException

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

the class Ovm3StorageProcessor method deleteSnapshot.

/**
     * Is not used in normal operation, the SSVM takes care of this.
     */
@Override
public Answer deleteSnapshot(DeleteCommand cmd) {
    LOGGER.debug("execute deleteSnapshot: " + cmd.getClass());
    DataTO data = cmd.getData();
    SnapshotObjectTO snap = (SnapshotObjectTO) data;
    String storeUrl = data.getDataStore().getUrl();
    String snapUuid = snap.getPath();
    try {
        // snapshots/accountid/volumeid
        String secPoolUuid = pool.setupSecondaryStorage(storeUrl);
        String filePath = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + snapUuid + ".raw";
        StoragePlugin sp = new StoragePlugin(c);
        sp.storagePluginDestroy(secPoolUuid, filePath);
        LOGGER.debug("Snapshot deletion success: " + filePath);
        return new Answer(cmd, true, "Deleted Snapshot " + filePath);
    } catch (Ovm3ResourceException e) {
        LOGGER.info("Snapshot deletion failed: " + e.toString(), e);
        return new CreateObjectAnswer(e.toString());
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) Answer(com.cloud.agent.api.Answer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) SnapshotAndCopyAnswer(org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) DataTO(com.cloud.agent.api.to.DataTO) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin)

Example 9 with Ovm3ResourceException

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

the class Ovm3StorageProcessor method copyTemplateToPrimaryStorage.

/**
     * src is Nfs and Template from secondary storage to primary
     */
@Override
public CopyCmdAnswer copyTemplateToPrimaryStorage(CopyCommand cmd) {
    LOGGER.debug("execute copyTemplateToPrimaryStorage: " + cmd.getClass());
    DataTO srcData = cmd.getSrcTO();
    DataStoreTO srcStore = srcData.getDataStore();
    DataTO destData = cmd.getDestTO();
    NfsTO srcImageStore = (NfsTO) srcStore;
    TemplateObjectTO destTemplate = (TemplateObjectTO) destData;
    try {
        String secPoolUuid = pool.setupSecondaryStorage(srcImageStore.getUrl());
        String primaryPoolUuid = destData.getDataStore().getUuid();
        String destPath = config.getAgentOvmRepoPath() + "/" + ovmObject.deDash(primaryPoolUuid) + "/" + config.getTemplateDir();
        String sourcePath = config.getAgentSecStoragePath() + "/" + secPoolUuid;
        Linux host = new Linux(c);
        String destUuid = destTemplate.getUuid();
        /*
             * Would love to add dynamic formats (tolower), to also support
             * VHD and QCOW2, although Ovm3.2 does not have tapdisk2 anymore
             * so we can forget about that.
             */
        /* TODO: add checksumming */
        String srcFile = sourcePath + "/" + srcData.getPath();
        if (srcData.getPath().endsWith("/")) {
            srcFile = sourcePath + "/" + srcData.getPath() + "/" + destUuid + ".raw";
        }
        String destFile = destPath + "/" + destUuid + ".raw";
        LOGGER.debug("CopyFrom: " + srcData.getObjectType() + "," + srcFile + " to " + destData.getObjectType() + "," + destFile);
        host.copyFile(srcFile, destFile);
        TemplateObjectTO newVol = new TemplateObjectTO();
        newVol.setUuid(destUuid);
        // was destfile
        newVol.setPath(destUuid);
        newVol.setFormat(ImageFormat.RAW);
        return new CopyCmdAnswer(newVol);
    } catch (Ovm3ResourceException e) {
        String msg = "Error while copying template to primary storage: " + e.getMessage();
        LOGGER.info(msg);
        return new CopyCmdAnswer(msg);
    }
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) 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) NfsTO(com.cloud.agent.api.to.NfsTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 10 with Ovm3ResourceException

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

the class Ovm3HypervisorSupport method execute.

/**
     * CheckHealthAnwer: Check the health of an agent on the hypervisor.
     * TODO: should elaborate here with checks...
     *
     * @param cmd
     * @return
     */
public CheckHealthAnswer execute(CheckHealthCommand cmd) {
    Common test = new Common(c);
    String ping = "put";
    String pong;
    try {
        pong = test.echo(ping);
    } catch (Ovm3ResourceException e) {
        LOGGER.debug("CheckHealth went wrong: " + config.getAgentHostname() + ", " + e.getMessage(), e);
        return new CheckHealthAnswer(cmd, false);
    }
    if (ping.contentEquals(pong)) {
        return new CheckHealthAnswer(cmd, true);
    }
    LOGGER.debug("CheckHealth did not receive " + ping + " but got " + pong + " from " + config.getAgentHostname());
    return new CheckHealthAnswer(cmd, false);
}
Also used : CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) Common(com.cloud.hypervisor.ovm3.objects.Common)

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