Search in sources :

Example 1 with DataStoreTO

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

the class AncientDataMotionStrategy method addFullCloneFlagOnVMwareDest.

/**
     * Adds {@code 'vmware.create.full.clone'} value for a given primary storage, whose HV is VMware, on datastore's {@code fullCloneFlag} field
     * @param dataTO Dest data store TO
     * @return dataTO including fullCloneFlag, if provided
     */
protected DataTO addFullCloneFlagOnVMwareDest(DataTO dataTO) {
    if (dataTO != null && dataTO.getHypervisorType().equals(Hypervisor.HypervisorType.VMware)) {
        DataStoreTO dataStoreTO = dataTO.getDataStore();
        if (dataStoreTO != null && dataStoreTO instanceof PrimaryDataStoreTO) {
            PrimaryDataStoreTO primaryDataStoreTO = (PrimaryDataStoreTO) dataStoreTO;
            Boolean value = CapacityManager.VmwareCreateCloneFull.valueIn(primaryDataStoreTO.getId());
            primaryDataStoreTO.setFullCloneFlag(value);
        }
    }
    return dataTO;
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO)

Example 2 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 3 with DataStoreTO

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

the class VmwareResource method syncDiskChain.

// return the finalized disk chain for startup, from top to bottom
private String[] syncDiskChain(DatacenterMO dcMo, VirtualMachineMO vmMo, VirtualMachineTO vmSpec, DiskTO vol, VirtualMachineDiskInfo diskInfo, HashMap<String, Pair<ManagedObjectReference, DatastoreMO>> dataStoresDetails) throws Exception {
    VolumeObjectTO volumeTO = (VolumeObjectTO) vol.getData();
    DataStoreTO primaryStore = volumeTO.getDataStore();
    Map<String, String> details = vol.getDetails();
    boolean isManaged = false;
    String iScsiName = null;
    if (details != null) {
        isManaged = Boolean.parseBoolean(details.get(DiskTO.MANAGED));
        iScsiName = details.get(DiskTO.IQN);
    }
    // if the storage is managed, iScsiName should not be null
    String datastoreName = isManaged ? VmwareResource.getDatastoreName(iScsiName) : primaryStore.getUuid();
    Pair<ManagedObjectReference, DatastoreMO> volumeDsDetails = dataStoresDetails.get(datastoreName);
    if (volumeDsDetails == null) {
        throw new Exception("Primary datastore " + primaryStore.getUuid() + " is not mounted on host.");
    }
    DatastoreMO dsMo = volumeDsDetails.second();
    // we will honor vCenter's meta if it exists
    if (diskInfo != null) {
        // to deal with run-time upgrade to maintain the new datastore folder structure
        String[] disks = diskInfo.getDiskChain();
        for (int i = 0; i < disks.length; i++) {
            DatastoreFile file = new DatastoreFile(disks[i]);
            if (!isManaged && file.getDir() != null && file.getDir().isEmpty()) {
                s_logger.info("Perform run-time datastore folder upgrade. sync " + disks[i] + " to VM folder");
                disks[i] = VmwareStorageLayoutHelper.syncVolumeToVmDefaultFolder(dcMo, vmMo.getName(), dsMo, file.getFileBaseName());
            }
        }
        return disks;
    }
    final String datastoreDiskPath;
    if (isManaged) {
        if (volumeTO.getVolumeType() == Volume.Type.ROOT) {
            datastoreDiskPath = VmwareStorageLayoutHelper.syncVolumeToVmDefaultFolder(dcMo, vmMo.getName(), dsMo, volumeTO.getName());
        } else {
            datastoreDiskPath = dsMo.getDatastorePath(dsMo.getName() + ".vmdk");
        }
    } else {
        datastoreDiskPath = VmwareStorageLayoutHelper.syncVolumeToVmDefaultFolder(dcMo, vmMo.getName(), dsMo, volumeTO.getPath());
    }
    if (!dsMo.fileExists(datastoreDiskPath)) {
        s_logger.warn("Volume " + volumeTO.getId() + " does not seem to exist on datastore, out of sync? path: " + datastoreDiskPath);
    }
    return new String[] { datastoreDiskPath };
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DatastoreFile(com.cloud.hypervisor.vmware.mo.DatastoreFile) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) 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) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 4 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 5 with DataStoreTO

use of com.cloud.agent.api.to.DataStoreTO in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method deleteVolume.

protected Answer deleteVolume(final DeleteCommand cmd) {
    final DataTO obj = cmd.getData();
    final DataStoreTO dstore = obj.getDataStore();
    if (dstore instanceof NfsTO) {
        final NfsTO nfs = (NfsTO) dstore;
        String relativeVolumePath = obj.getPath();
        String parent = getRootDir(nfs.getUrl());
        if (relativeVolumePath.startsWith(File.separator)) {
            relativeVolumePath = relativeVolumePath.substring(1);
        }
        if (!parent.endsWith(File.separator)) {
            parent += File.separator;
        }
        final String absoluteVolumePath = parent + relativeVolumePath;
        final File volPath = new File(absoluteVolumePath);
        File tmpltParent = null;
        if (volPath.exists() && volPath.isDirectory()) {
            // for vmware, absoluteVolumePath represents a directory where volume files are located.
            tmpltParent = volPath;
        } else {
            // for other hypervisors, the volume .vhd or .qcow2 file path is passed
            tmpltParent = new File(absoluteVolumePath).getParentFile();
        }
        String details = null;
        if (!tmpltParent.exists()) {
            details = "volume parent directory " + tmpltParent.getName() + " doesn't exist";
            s_logger.debug(details);
            return new Answer(cmd, true, details);
        }
        final File[] tmpltFiles = tmpltParent.listFiles();
        if (tmpltFiles == null || tmpltFiles.length == 0) {
            details = "No files under volume parent directory " + tmpltParent.getName();
            s_logger.debug(details);
        } else {
            boolean found = false;
            for (final File f : tmpltFiles) {
                if (!found && f.getName().equals("volume.properties")) {
                    found = true;
                }
                // Don't let this stop us from cleaning up the template
                if (f.isDirectory() && f.getName().equals("KVMHA")) {
                    s_logger.debug("Deleting KVMHA directory contents from template location");
                    final File[] haFiles = f.listFiles();
                    for (final File haFile : haFiles) {
                        haFile.delete();
                    }
                }
                if (!f.delete()) {
                    return new Answer(cmd, false, "Unable to delete file " + f.getName() + " under Volume path " + tmpltParent.getPath());
                }
            }
            if (!found) {
                details = "Can not find volume.properties under " + tmpltParent.getName();
                s_logger.debug(details);
            }
        }
        if (!tmpltParent.delete()) {
            details = "Unable to delete directory " + tmpltParent.getName() + " under Volume path " + tmpltParent.getPath();
            s_logger.debug(details);
            return new Answer(cmd, false, details);
        }
        return new Answer(cmd, true, null);
    } else {
        return new Answer(cmd, false, "Unsupported image data store: " + dstore);
    }
}
Also used : ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) UploadStatusAnswer(com.cloud.storage.command.UploadStatusAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) ListVolumeAnswer(com.cloud.agent.api.storage.ListVolumeAnswer) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) Answer(com.cloud.agent.api.Answer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) NfsTO(com.cloud.agent.api.to.NfsTO) File(java.io.File)

Aggregations

DataStoreTO (com.cloud.agent.api.to.DataStoreTO)154 NfsTO (com.cloud.agent.api.to.NfsTO)110 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)81 DataTO (com.cloud.agent.api.to.DataTO)80 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)59 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)57 InternalErrorException (com.cloud.exception.InternalErrorException)56 Answer (com.cloud.agent.api.Answer)45 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)42 TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)34 IOException (java.io.IOException)32 XmlRpcException (org.apache.xmlrpc.XmlRpcException)31 CopyCmdAnswer (com.cloud.storage.command.CopyCmdAnswer)30 XenAPIException (com.xensource.xenapi.Types.XenAPIException)30 Connection (com.xensource.xenapi.Connection)28 File (java.io.File)28 ConfigurationException (javax.naming.ConfigurationException)28 SR (com.xensource.xenapi.SR)26 VDI (com.xensource.xenapi.VDI)26 URI (java.net.URI)26