Search in sources :

Example 16 with CloudstackPlugin

use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin 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)

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