Search in sources :

Example 11 with DataStoreTO

use of com.cloud.agent.api.to.DataStoreTO in project cloudstack by apache.

the class VmwareStorageManagerImpl method createOvaForTemplate.

@Override
public String createOvaForTemplate(TemplateObjectTO template) {
    DataStoreTO storeTO = template.getDataStore();
    if (!(storeTO instanceof NfsTO)) {
        s_logger.debug("Can only handle NFS storage, while creating OVA from template");
        return null;
    }
    NfsTO nfsStore = (NfsTO) storeTO;
    String secStorageUrl = nfsStore.getUrl();
    assert (secStorageUrl != null);
    String installPath = template.getPath();
    String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, _nfsVersion);
    String installFullPath = secondaryMountPoint + "/" + installPath;
    try {
        if (installFullPath.endsWith(".ova")) {
            if (new File(installFullPath).exists()) {
                s_logger.debug("OVA file found at: " + installFullPath);
            } else {
                if (new File(installFullPath + ".meta").exists()) {
                    createOVAFromMetafile(installFullPath + ".meta");
                } else {
                    String msg = "Unable to find OVA or OVA MetaFile to prepare template.";
                    s_logger.error(msg);
                    throw new Exception(msg);
                }
            }
            return installPath;
        }
    } catch (Throwable e) {
        s_logger.debug("Failed to create OVA: " + e.toString());
    }
    return null;
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) NfsTO(com.cloud.agent.api.to.NfsTO) File(java.io.File) RemoteException(java.rmi.RemoteException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 12 with DataStoreTO

use of com.cloud.agent.api.to.DataStoreTO in project cloudstack by apache.

the class VmwareStorageManagerImpl method setVolumeToPathAndSize.

private void setVolumeToPathAndSize(List<VolumeObjectTO> volumeTOs, Map<String, String> mapNewDisk, VmwareContext context, VmwareHypervisorHost hyperHost, String vmName) throws Exception {
    for (VolumeObjectTO volumeTO : volumeTOs) {
        String oldPath = volumeTO.getPath();
        final String baseName;
        // if this is managed storage
        if (oldPath.startsWith("[-iqn.")) {
            // ex. [-iqn.2010-01.com.company:3y8w.vol-10.64-0] -iqn.2010-01.com.company:3y8w.vol-10.64-0-000001.vmdk
            // ex. [-iqn.2010-01.com.company:3y8w.vol-10.64-0]
            oldPath = oldPath.split(" ")[0];
            // remove '[' and ']'
            baseName = oldPath.substring(1, oldPath.length() - 1);
        } else {
            baseName = VmwareHelper.trimSnapshotDeltaPostfix(volumeTO.getPath());
        }
        String newPath = mapNewDisk.get(baseName);
        // get volume's chain size for this VM snapshot; exclude current volume vdisk
        DataStoreTO store = volumeTO.getDataStore();
        ManagedObjectReference morDs = getDatastoreAsManagedObjectReference(baseName, hyperHost, store);
        long size = getVMSnapshotChainSize(context, hyperHost, baseName + "*.vmdk", morDs, newPath);
        if (volumeTO.getVolumeType() == Volume.Type.ROOT) {
            // add memory snapshot size
            size += getVMSnapshotChainSize(context, hyperHost, vmName + "*.vmsn", morDs, null);
        }
        volumeTO.setSize(size);
        volumeTO.setPath(newPath);
    }
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 13 with DataStoreTO

use of com.cloud.agent.api.to.DataStoreTO in project cloudstack by apache.

the class Ovm3StorageProcessor method execute.

public final Answer execute(final CopyCommand cmd) {
    LOGGER.debug("execute: " + cmd.getClass());
    DataTO srcData = cmd.getSrcTO();
    DataStoreTO srcStore = srcData.getDataStore();
    DataTO destData = cmd.getDestTO();
    DataStoreTO destStore = destData.getDataStore();
    String msg = "Not implemented yet";
    try {
        /* target and source are NFS and TEMPLATE */
        if ((srcStore instanceof NfsTO) && (srcData.getObjectType() == DataObjectType.TEMPLATE) && (destData.getObjectType() == DataObjectType.TEMPLATE)) {
            return copyTemplateToPrimaryStorage(cmd);
        /* we assume the cache for templates is local */
        } else if ((srcData.getObjectType() == DataObjectType.TEMPLATE) && (destData.getObjectType() == DataObjectType.VOLUME)) {
            if (srcStore.getUrl().equals(destStore.getUrl())) {
                return cloneVolumeFromBaseTemplate(cmd);
            } else {
                msg = "Primary to Primary doesn't match";
                LOGGER.debug(msg);
            }
        } else if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) && (destData.getObjectType() == DataObjectType.SNAPSHOT)) {
            return backupSnapshot(cmd);
        } else if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) && (destData.getObjectType() == DataObjectType.TEMPLATE)) {
            return createTemplateFromSnapshot(cmd);
        } else if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) && (destData.getObjectType() == DataObjectType.VOLUME)) {
            return createVolumeFromSnapshot(cmd);
        } else {
            msg = "Unable to do stuff for " + srcStore.getClass() + ":" + srcData.getObjectType() + " to " + destStore.getClass() + ":" + destData.getObjectType();
            LOGGER.debug(msg);
        }
    } catch (Exception e) {
        msg = "Catch Exception " + e.getClass().getName() + " for template due to " + e.toString();
        LOGGER.warn(msg, e);
        return new CopyCmdAnswer(msg);
    }
    LOGGER.warn(msg + " " + cmd.getClass());
    return new CopyCmdAnswer(msg);
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) NfsTO(com.cloud.agent.api.to.NfsTO) URISyntaxException(java.net.URISyntaxException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 14 with DataStoreTO

use of com.cloud.agent.api.to.DataStoreTO 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 15 with DataStoreTO

use of com.cloud.agent.api.to.DataStoreTO in project cloudstack by apache.

the class Ovm3StorageProcessor method createVolumeFromSnapshot.

/**
     * SnapshotObjectTO secondary to VolumeObjectTO primary in xenserver,
     */
@Override
public Answer createVolumeFromSnapshot(CopyCommand cmd) {
    LOGGER.debug("execute createVolumeFromSnapshot: " + cmd.getClass());
    try {
        DataTO srcData = cmd.getSrcTO();
        DataStoreTO srcStore = srcData.getDataStore();
        NfsTO srcImageStore = (NfsTO) srcStore;
        // source, should contain snap dir/filename
        SnapshotObjectTO srcSnap = (SnapshotObjectTO) srcData;
        String secPoolUuid = pool.setupSecondaryStorage(srcImageStore.getUrl());
        String srcFile = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + srcSnap.getPath();
        // dest
        DataTO destData = cmd.getDestTO();
        VolumeObjectTO destVol = (VolumeObjectTO) destData;
        String primaryPoolUuid = destData.getDataStore().getUuid();
        String destFile = getVirtualDiskPath(destVol.getUuid(), ovmObject.deDash(primaryPoolUuid));
        Linux host = new Linux(c);
        host.copyFile(srcFile, destFile);
        VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setUuid(destVol.getUuid());
        // newVol.setPath(destFile);
        newVol.setPath(destVol.getUuid());
        newVol.setFormat(ImageFormat.RAW);
        return new CopyCmdAnswer(newVol);
    /* we assume the cache for templates is local */
    } catch (Ovm3ResourceException e) {
        LOGGER.debug("Failed to createVolumeFromSnapshot: ", e);
        return new CopyCmdAnswer(e.toString());
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) 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) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Aggregations

DataStoreTO (com.cloud.agent.api.to.DataStoreTO)91 NfsTO (com.cloud.agent.api.to.NfsTO)66 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)54 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)50 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)47 DataTO (com.cloud.agent.api.to.DataTO)46 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)36 InternalErrorException (com.cloud.exception.InternalErrorException)30 TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)28 Answer (com.cloud.agent.api.Answer)26 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)20 UnsupportedEncodingException (java.io.UnsupportedEncodingException)19 IOException (java.io.IOException)17 S3TO (com.cloud.agent.api.to.S3TO)16 ConfigurationException (javax.naming.ConfigurationException)16 XmlRpcException (org.apache.xmlrpc.XmlRpcException)16 XenAPIException (com.xensource.xenapi.Types.XenAPIException)15 RemoteException (java.rmi.RemoteException)15 SwiftTO (com.cloud.agent.api.to.SwiftTO)14 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)14