Search in sources :

Example 11 with VolumeObjectTO

use of org.apache.cloudstack.storage.to.VolumeObjectTO 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 12 with VolumeObjectTO

use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.

the class VmwareStorageManagerImpl method execute.

@Override
public boolean execute(VmwareHostService hostService, CreateEntityDownloadURLCommand cmd) {
    DataTO data = cmd.getData();
    if (data == null) {
        return false;
    }
    String newPath = null;
    if (data.getObjectType() == DataObjectType.VOLUME) {
        newPath = createOvaForVolume((VolumeObjectTO) data);
    } else if (data.getObjectType() == DataObjectType.TEMPLATE) {
        newPath = createOvaForTemplate((TemplateObjectTO) data);
    }
    if (newPath != null) {
        cmd.setInstallPath(newPath);
    }
    return true;
}
Also used : DataTO(com.cloud.agent.api.to.DataTO) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO)

Example 13 with VolumeObjectTO

use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.

the class XenServerStorageMotionStrategy method updateVolumePathsAfterMigration.

private void updateVolumePathsAfterMigration(Map<VolumeInfo, DataStore> volumeToPool, List<VolumeObjectTO> volumeTos, Host srcHost) {
    for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
        VolumeInfo volumeInfo = entry.getKey();
        StoragePool storagePool = (StoragePool) entry.getValue();
        boolean updated = false;
        for (VolumeObjectTO volumeTo : volumeTos) {
            if (volumeInfo.getId() == volumeTo.getId()) {
                if (storagePool.isManaged()) {
                    handleManagedVolumePostMigration(volumeInfo, srcHost, volumeTo);
                } else {
                    VolumeVO volumeVO = volDao.findById(volumeInfo.getId());
                    Long oldPoolId = volumeVO.getPoolId();
                    volumeVO.setPath(volumeTo.getPath());
                    volumeVO.setFolder(storagePool.getPath());
                    volumeVO.setPodId(storagePool.getPodId());
                    volumeVO.setPoolId(storagePool.getId());
                    volumeVO.setLastPoolId(oldPoolId);
                    volDao.update(volumeInfo.getId(), volumeVO);
                }
                updated = true;
                break;
            }
        }
        if (!updated) {
            s_logger.error("The volume path wasn't updated for volume '" + volumeInfo + "' after it was migrated.");
        }
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) VolumeVO(com.cloud.storage.VolumeVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with VolumeObjectTO

use of org.apache.cloudstack.storage.to.VolumeObjectTO 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 15 with VolumeObjectTO

use of org.apache.cloudstack.storage.to.VolumeObjectTO 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)

Aggregations

VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)108 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)59 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)45 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)36 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)36 DataTO (com.cloud.agent.api.to.DataTO)31 NfsTO (com.cloud.agent.api.to.NfsTO)31 InternalErrorException (com.cloud.exception.InternalErrorException)27 TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)20 Connection (com.xensource.xenapi.Connection)19 VDI (com.xensource.xenapi.VDI)17 IOException (java.io.IOException)17 Answer (com.cloud.agent.api.Answer)16 DiskTO (com.cloud.agent.api.to.DiskTO)16 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)16 RemoteException (java.rmi.RemoteException)16 ArrayList (java.util.ArrayList)16 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)16 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14