Search in sources :

Example 41 with DataStoreTO

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

the class VmwareResource method inferDatastoreDetailsFromDiskInfo.

private HashMap<String, Pair<ManagedObjectReference, DatastoreMO>> inferDatastoreDetailsFromDiskInfo(VmwareHypervisorHost hyperHost, VmwareContext context, DiskTO[] disks, Command cmd) throws Exception {
    HashMap<String, Pair<ManagedObjectReference, DatastoreMO>> mapIdToMors = new HashMap<String, Pair<ManagedObjectReference, DatastoreMO>>();
    assert (hyperHost != null) && (context != null);
    for (DiskTO vol : disks) {
        if (vol.getType() != Volume.Type.ISO) {
            VolumeObjectTO volumeTO = (VolumeObjectTO) vol.getData();
            DataStoreTO primaryStore = volumeTO.getDataStore();
            String poolUuid = primaryStore.getUuid();
            if (mapIdToMors.get(poolUuid) == null) {
                boolean isManaged = false;
                Map<String, String> details = vol.getDetails();
                if (details != null) {
                    isManaged = Boolean.parseBoolean(details.get(DiskTO.MANAGED));
                }
                if (isManaged) {
                    // details should not be null for managed storage (it may or may not be null for non-managed storage)
                    String iScsiName = details.get(DiskTO.IQN);
                    String datastoreName = VmwareResource.getDatastoreName(iScsiName);
                    ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, datastoreName);
                    // create the datastore, and create a VMDK file in the datastore
                    if (morDatastore == null) {
                        morDatastore = _storageProcessor.prepareManagedStorage(context, hyperHost, null, iScsiName, details.get(DiskTO.STORAGE_HOST), Integer.parseInt(details.get(DiskTO.STORAGE_PORT)), volumeTO.getVolumeType() == Volume.Type.ROOT ? volumeTO.getName() : null, details.get(DiskTO.CHAP_INITIATOR_USERNAME), details.get(DiskTO.CHAP_INITIATOR_SECRET), details.get(DiskTO.CHAP_TARGET_USERNAME), details.get(DiskTO.CHAP_TARGET_SECRET), Long.parseLong(details.get(DiskTO.VOLUME_SIZE)), cmd);
                        DatastoreMO dsMo = new DatastoreMO(getServiceContext(), morDatastore);
                        String datastoreVolumePath = dsMo.getDatastorePath((volumeTO.getVolumeType() == Volume.Type.ROOT ? volumeTO.getName() : dsMo.getName()) + ".vmdk");
                        volumeTO.setPath(datastoreVolumePath);
                        vol.setPath(datastoreVolumePath);
                    }
                    mapIdToMors.put(datastoreName, new Pair<ManagedObjectReference, DatastoreMO>(morDatastore, new DatastoreMO(context, morDatastore)));
                } else {
                    ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, poolUuid);
                    if (morDatastore == null) {
                        String msg = "Failed to get the mounted datastore for the volume's pool " + poolUuid;
                        s_logger.error(msg);
                        throw new Exception(msg);
                    }
                    mapIdToMors.put(poolUuid, new Pair<ManagedObjectReference, DatastoreMO>(morDatastore, new DatastoreMO(context, morDatastore)));
                }
            }
        }
    }
    return mapIdToMors;
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) HashMap(java.util.HashMap) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Pair(com.cloud.utils.Pair) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 42 with DataStoreTO

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

the class VmwareResource method getDatastoreThatRootDiskIsOn.

private DatastoreMO getDatastoreThatRootDiskIsOn(HashMap<String, Pair<ManagedObjectReference, DatastoreMO>> dataStoresDetails, DiskTO[] disks) {
    Pair<ManagedObjectReference, DatastoreMO> rootDiskDataStoreDetails = null;
    for (DiskTO vol : disks) {
        if (vol.getType() == Volume.Type.ROOT) {
            Map<String, String> details = vol.getDetails();
            boolean managed = false;
            if (details != null) {
                managed = Boolean.parseBoolean(details.get(DiskTO.MANAGED));
            }
            if (managed) {
                String datastoreName = VmwareResource.getDatastoreName(details.get(DiskTO.IQN));
                rootDiskDataStoreDetails = dataStoresDetails.get(datastoreName);
                break;
            } else {
                DataStoreTO primaryStore = vol.getData().getDataStore();
                rootDiskDataStoreDetails = dataStoresDetails.get(primaryStore.getUuid());
                break;
            }
        }
    }
    if (rootDiskDataStoreDetails != null) {
        return rootDiskDataStoreDetails.second();
    }
    return null;
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 43 with DataStoreTO

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

the class KVMStorageProcessor method cloneVolumeFromBaseTemplate.

@Override
public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) {
    final DataTO srcData = cmd.getSrcTO();
    final DataTO destData = cmd.getDestTO();
    final TemplateObjectTO template = (TemplateObjectTO) srcData;
    final DataStoreTO imageStore = template.getDataStore();
    final VolumeObjectTO volume = (VolumeObjectTO) destData;
    final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore();
    KVMPhysicalDisk BaseVol = null;
    KVMStoragePool primaryPool = null;
    KVMPhysicalDisk vol = null;
    try {
        primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
        String templatePath = template.getPath();
        if (primaryPool.getType() == StoragePoolType.CLVM) {
            templatePath = ((NfsTO) imageStore).getUrl() + File.separator + templatePath;
            vol = templateToPrimaryDownload(templatePath, primaryPool, volume.getUuid(), volume.getSize(), cmd.getWaitInMillSeconds());
        } else {
            if (templatePath.contains("/mnt")) {
                //upgrade issue, if the path contains path, need to extract the volume uuid from path
                templatePath = templatePath.substring(templatePath.lastIndexOf(File.separator) + 1);
            }
            BaseVol = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), templatePath);
            vol = storagePoolMgr.createDiskFromTemplate(BaseVol, volume.getUuid(), volume.getProvisioningType(), BaseVol.getPool(), volume.getSize(), cmd.getWaitInMillSeconds());
        }
        if (vol == null) {
            return new CopyCmdAnswer(" Can't create storage volume on storage pool");
        }
        final VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setPath(vol.getName());
        newVol.setSize(volume.getSize());
        if (vol.getFormat() == PhysicalDiskFormat.RAW) {
            newVol.setFormat(ImageFormat.RAW);
        } else if (vol.getFormat() == PhysicalDiskFormat.QCOW2) {
            newVol.setFormat(ImageFormat.QCOW2);
        } else if (vol.getFormat() == PhysicalDiskFormat.DIR) {
            newVol.setFormat(ImageFormat.DIR);
        }
        return new CopyCmdAnswer(newVol);
    } catch (final CloudRuntimeException e) {
        s_logger.debug("Failed to create volume: ", e);
        return new CopyCmdAnswer(e.toString());
    }
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 44 with DataStoreTO

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

the class SimulatorStorageProcessor method attachIso.

@Override
public Answer attachIso(AttachCommand cmd) {
    DiskTO disk = cmd.getDisk();
    TemplateObjectTO isoTO = (TemplateObjectTO) disk.getData();
    DataStoreTO store = isoTO.getDataStore();
    if (!(store instanceof NfsTO)) {
        return new AttachAnswer("unsupported protocol");
    }
    return new Answer(cmd);
}
Also used : CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) Answer(com.cloud.agent.api.Answer) DettachAnswer(org.apache.cloudstack.storage.command.DettachAnswer) SnapshotAndCopyAnswer(org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO) DiskTO(com.cloud.agent.api.to.DiskTO) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer)

Example 45 with DataStoreTO

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

the class SimulatorStorageProcessor method backupSnapshot.

@Override
public Answer backupSnapshot(CopyCommand cmd) {
    DataTO srcData = cmd.getSrcTO();
    DataTO destData = cmd.getDestTO();
    SnapshotObjectTO snapshot = (SnapshotObjectTO) srcData;
    DataStoreTO imageStore = destData.getDataStore();
    if (!(imageStore instanceof NfsTO)) {
        return new CopyCmdAnswer("unsupported protocol");
    }
    int index = snapshot.getPath().lastIndexOf("/");
    String snapshotName = snapshot.getPath().substring(index + 1);
    String snapshotRelPath = "snapshots";
    SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
    newSnapshot.setPath(snapshotRelPath + File.separator + snapshotName);
    return new CopyCmdAnswer(newSnapshot);
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) 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