Search in sources :

Example 6 with DataTO

use of com.cloud.legacymodel.to.DataTO 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.legacymodel.communication.answer.ListTemplateAnswer) GetStorageStatsAnswer(com.cloud.legacymodel.communication.answer.GetStorageStatsAnswer) ReadyAnswer(com.cloud.legacymodel.communication.answer.ReadyAnswer) ListVolumeAnswer(com.cloud.legacymodel.communication.answer.ListVolumeAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) CheckHealthAnswer(com.cloud.legacymodel.communication.answer.CheckHealthAnswer) UploadStatusAnswer(com.cloud.legacymodel.communication.answer.UploadStatusAnswer) SecStorageSetupAnswer(com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) DataTO(com.cloud.legacymodel.to.DataTO) NfsTO(com.cloud.legacymodel.to.NfsTO) File(java.io.File)

Example 7 with DataTO

use of com.cloud.legacymodel.to.DataTO in project cosmic by MissionCriticalCloud.

the class AncientDataMotionStrategy method needCacheStorage.

protected boolean needCacheStorage(final DataObject srcData, final DataObject destData) {
    final DataTO srcTO = srcData.getTO();
    final DataStoreTO srcStoreTO = srcTO.getDataStore();
    if (srcStoreTO instanceof NfsTO || srcStoreTO.getRole() == DataStoreRole.ImageCache) {
        // (srcStoreTO instanceof PrimaryDataStoreTO && ((PrimaryDataStoreTO)srcStoreTO).getPoolType() == StoragePoolType.NetworkFilesystem)) {
        return false;
    }
    final DataTO destTO = destData.getTO();
    final DataStoreTO destStoreTO = destTO.getDataStore();
    if (destStoreTO instanceof NfsTO || destStoreTO.getRole() == DataStoreRole.ImageCache) {
        return false;
    }
    if (srcData.getType() == DataObjectType.TEMPLATE) {
        final TemplateInfo template = (TemplateInfo) srcData;
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("needCacheStorage true, dest at " + destTO.getPath() + " dest role " + destStoreTO.getRole().toString() + srcTO.getPath() + " src role " + srcStoreTO.getRole().toString());
    }
    return true;
}
Also used : DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) DataTO(com.cloud.legacymodel.to.DataTO) NfsTO(com.cloud.legacymodel.to.NfsTO)

Example 8 with DataTO

use of com.cloud.legacymodel.to.DataTO in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResource method createVbd.

public void createVbd(final Connect conn, final VirtualMachineTO vmSpec, final String vmName, final LibvirtVmDef vm) throws InternalErrorException, LibvirtException, URISyntaxException {
    final List<DiskTO> disks = Arrays.asList(vmSpec.getDisks());
    Collections.sort(disks, new Comparator<DiskTO>() {

        @Override
        public int compare(final DiskTO arg0, final DiskTO arg1) {
            return arg0.getDiskSeq() > arg1.getDiskSeq() ? 1 : -1;
        }
    });
    for (final DiskTO volume : disks) {
        KvmPhysicalDisk physicalDisk = null;
        KvmStoragePool pool = null;
        final DataTO data = volume.getData();
        if (volume.getType() == VolumeType.ISO && data.getPath() != null) {
            final NfsTO nfsStore = (NfsTO) data.getDataStore();
            final String volPath = nfsStore.getUrl() + File.separator + data.getPath();
            final int index = volPath.lastIndexOf("/");
            final String volDir = volPath.substring(0, index);
            final String volName = volPath.substring(index + 1);
            final KvmStoragePool secondaryStorage = this.storagePoolMgr.getStoragePoolByUri(volDir);
            physicalDisk = secondaryStorage.getPhysicalDisk(volName);
        } else if (volume.getType() != VolumeType.ISO) {
            final PrimaryDataStoreTO store = (PrimaryDataStoreTO) data.getDataStore();
            physicalDisk = this.storagePoolMgr.getPhysicalDisk(store.getPoolType(), store.getUuid(), data.getPath());
            pool = physicalDisk.getPool();
        }
        String volPath = null;
        if (physicalDisk != null) {
            volPath = physicalDisk.getPath();
        }
        // check for disk activity, if detected we should exit because vm is running elsewhere
        if (this.diskActivityCheckEnabled && physicalDisk != null && physicalDisk.getFormat() == PhysicalDiskFormat.QCOW2) {
            logger.debug("Checking physical disk file at path " + volPath + " for disk activity to ensure vm is not running elsewhere");
            try {
                HypervisorUtils.checkVolumeFileForActivity(volPath, this.diskActivityCheckTimeoutSeconds, this.diskActivityInactiveThresholdMilliseconds, this.diskActivityCheckFileSizeMin);
            } catch (final IOException ex) {
                throw new CloudRuntimeException("Unable to check physical disk file for activity", ex);
            }
            logger.debug("Disk activity check cleared");
        }
        final LibvirtDiskDef disk = new LibvirtDiskDef();
        if (volume.getType() == VolumeType.ISO) {
            if (volPath == null) {
                /* Add iso as placeholder */
                disk.defIsoDisk(null);
            } else {
                disk.defIsoDisk(volPath);
            }
        } else {
            final int devId = volume.getDiskSeq().intValue();
            if (volume.getDiskController() == DiskControllerType.SCSI) {
                disk.setQemuDriver(true);
                disk.setDiscard(DiscardType.UNMAP);
            }
            disk.setImageFormat(volume.getDiskFormat());
            if (pool.getType() == StoragePoolType.RBD) {
                /*
                     * For RBD pools we use the secret mechanism in libvirt. We store the secret under the UUID of the pool,
                     * that's why we pass the pool's UUID as the authSecret
                     */
                disk.defNetworkBasedDisk(physicalDisk.getPath().replace("rbd:", ""), pool.getSourceHost(), pool.getSourcePort(), pool.getAuthUserName(), pool.getUuid(), devId, volume.getDiskController(), DiskProtocol.RBD, ImageFormat.RAW);
            } else if (pool.getType() == StoragePoolType.Gluster) {
                final String mountpoint = pool.getLocalPath();
                final String path = physicalDisk.getPath();
                final String glusterVolume = pool.getSourceDir().replace("/", "");
                disk.defNetworkBasedDisk(glusterVolume + path.replace(mountpoint, ""), pool.getSourceHost(), pool.getSourcePort(), null, null, devId, volume.getDiskController(), DiskProtocol.GLUSTER, ImageFormat.QCOW2);
            } else if (pool.getType() == StoragePoolType.CLVM || pool.getType() == StoragePoolType.LVM) {
                disk.defBlockBasedDisk(physicalDisk.getPath(), devId, volume.getDiskController());
            } else if (pool.getType() == StoragePoolType.NetworkFilesystem) {
                disk.defFileBasedDisk(physicalDisk.getPath(), devId, volume.getDiskController(), volume.getDiskFormat());
            } else {
                disk.defFileBasedDisk(physicalDisk.getPath(), devId, volume.getDiskController(), volume.getDiskFormat());
            }
        }
        if (data instanceof VolumeObjectTO) {
            final VolumeObjectTO volumeObjectTo = (VolumeObjectTO) data;
            disk.setSerial(volumeObjectTo.getDeviceId() + "-" + diskUuidToSerial(volumeObjectTo.getUuid()));
            disk.setDeviceId(volumeObjectTo.getDeviceId().intValue());
            if (volumeObjectTo.getBytesReadRate() != null && volumeObjectTo.getBytesReadRate() > 0) {
                disk.setBytesReadRate(volumeObjectTo.getBytesReadRate());
            }
            if (volumeObjectTo.getBytesWriteRate() != null && volumeObjectTo.getBytesWriteRate() > 0) {
                disk.setBytesWriteRate(volumeObjectTo.getBytesWriteRate());
            }
            if (volumeObjectTo.getIopsReadRate() != null && volumeObjectTo.getIopsReadRate() > 0) {
                disk.setIopsReadRate(volumeObjectTo.getIopsReadRate());
            }
            if (volumeObjectTo.getIopsWriteRate() != null && volumeObjectTo.getIopsWriteRate() > 0) {
                disk.setIopsWriteRate(volumeObjectTo.getIopsWriteRate());
            }
            if (volumeObjectTo.getIopsTotalRate() != null && volumeObjectTo.getIopsTotalRate() > 0) {
                disk.setIopsTotalRate(volumeObjectTo.getIopsTotalRate());
            }
            if (volumeObjectTo.getCacheMode() != null) {
                disk.setCacheMode(LibvirtDiskDef.DiskCacheMode.valueOf(volumeObjectTo.getCacheMode().toString().toUpperCase()));
            }
            if (volumeObjectTo.getFormat() != null) {
                physicalDisk.setFormat(physicalDisk.getPhysicalDiskFormatFromImageFormat(volumeObjectTo.getFormat()));
            }
        }
        logger.debug("Adding disk: " + disk.toString());
        vm.getDevices().addDevice(disk);
    }
    if (vmSpec.getType() != VirtualMachineType.User) {
        final String sysvmIsoPath = getSysvmIsoPath();
        if (sysvmIsoPath != null) {
            final LibvirtDiskDef iso = new LibvirtDiskDef();
            iso.defIsoDisk(sysvmIsoPath);
            vm.getDevices().addDevice(iso);
        }
    }
}
Also used : KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) IOException(java.io.IOException) NfsTO(com.cloud.legacymodel.to.NfsTO) DataTO(com.cloud.legacymodel.to.DataTO) LibvirtDiskDef(com.cloud.agent.resource.kvm.xml.LibvirtDiskDef) PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) DiskTO(com.cloud.legacymodel.to.DiskTO)

Example 9 with DataTO

use of com.cloud.legacymodel.to.DataTO in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResource method getVolumePath.

public String getVolumePath(final Connect conn, final DiskTO volume) throws LibvirtException, URISyntaxException {
    final DataTO data = volume.getData();
    final DataStoreTO store = data.getDataStore();
    if (volume.getType() == VolumeType.ISO && data.getPath() != null) {
        final NfsTO nfsStore = (NfsTO) store;
        final String isoPath = nfsStore.getUrl() + File.separator + data.getPath();
        final int index = isoPath.lastIndexOf("/");
        final String path = isoPath.substring(0, index);
        final String name = isoPath.substring(index + 1);
        final KvmStoragePool secondaryPool = this.storagePoolMgr.getStoragePoolByUri(path);
        final KvmPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
        return isoVol.getPath();
    } else {
        return data.getPath();
    }
}
Also used : PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) DataTO(com.cloud.legacymodel.to.DataTO) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) NfsTO(com.cloud.legacymodel.to.NfsTO)

Example 10 with DataTO

use of com.cloud.legacymodel.to.DataTO in project cosmic by MissionCriticalCloud.

the class CitrixResourceBase method mount.

protected VDI mount(final Connection conn, final String vmName, final DiskTO volume) throws XmlRpcException, XenAPIException {
    final DataTO data = volume.getData();
    final VolumeType type = volume.getType();
    if (type == VolumeType.ISO) {
        final TemplateObjectTO iso = (TemplateObjectTO) data;
        final DataStoreTO store = iso.getDataStore();
        if (store == null) {
            // It's a fake iso
            return null;
        }
        // corer case, xenserver pv driver iso
        final String templateName = iso.getName();
        if (templateName.startsWith("xs-tools")) {
            try {
                final Set<VDI> vdis = VDI.getByNameLabel(conn, templateName);
                if (vdis.isEmpty()) {
                    throw new CloudRuntimeException("Could not find ISO with URL: " + templateName);
                }
                return vdis.iterator().next();
            } catch (final XenAPIException e) {
                throw new CloudRuntimeException("Unable to get pv iso: " + templateName + " due to " + e.toString());
            } catch (final Exception e) {
                throw new CloudRuntimeException("Unable to get pv iso: " + templateName + " due to " + e.toString());
            }
        }
        if (!(store instanceof NfsTO)) {
            throw new CloudRuntimeException("only support mount iso on nfs");
        }
        final NfsTO nfsStore = (NfsTO) store;
        final String isoPath = nfsStore.getUrl() + File.separator + iso.getPath();
        final int index = isoPath.lastIndexOf("/");
        final String mountpoint = isoPath.substring(0, index);
        final URI uri;
        try {
            uri = new URI(mountpoint);
        } catch (final URISyntaxException e) {
            throw new CloudRuntimeException("Incorrect uri " + mountpoint, e);
        }
        final SR isoSr = createIsoSRbyURI(conn, uri, vmName, false);
        final String isoname = isoPath.substring(index + 1);
        final VDI isoVdi = getVDIbyLocationandSR(conn, isoname, isoSr);
        if (isoVdi == null) {
            throw new CloudRuntimeException("Unable to find ISO " + isoPath);
        }
        return isoVdi;
    } else {
        final VolumeObjectTO vol = (VolumeObjectTO) data;
        return VDI.getByUuid(conn, vol.getPath());
    }
}
Also used : DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) XenAPIException(com.xensource.xenapi.Types.XenAPIException) URISyntaxException(java.net.URISyntaxException) NfsTO(com.cloud.legacymodel.to.NfsTO) URI(java.net.URI) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DataTO(com.cloud.legacymodel.to.DataTO) VolumeType(com.cloud.model.enumeration.VolumeType) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) VDI(com.xensource.xenapi.VDI) TemplateObjectTO(com.cloud.legacymodel.to.TemplateObjectTO) SR(com.xensource.xenapi.SR)

Aggregations

DataTO (com.cloud.legacymodel.to.DataTO)49 DataStoreTO (com.cloud.legacymodel.to.DataStoreTO)30 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)29 NfsTO (com.cloud.legacymodel.to.NfsTO)26 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)25 PrimaryDataStoreTO (com.cloud.legacymodel.to.PrimaryDataStoreTO)20 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)19 XenAPIException (com.xensource.xenapi.Types.XenAPIException)18 XmlRpcException (org.apache.xmlrpc.XmlRpcException)18 Connection (com.xensource.xenapi.Connection)17 VDI (com.xensource.xenapi.VDI)17 VolumeObjectTO (com.cloud.legacymodel.to.VolumeObjectTO)16 SR (com.xensource.xenapi.SR)12 Answer (com.cloud.legacymodel.communication.answer.Answer)11 DiskTO (com.cloud.legacymodel.to.DiskTO)11 TemplateObjectTO (com.cloud.legacymodel.to.TemplateObjectTO)11 URI (java.net.URI)10 SnapshotObjectTO (com.cloud.legacymodel.to.SnapshotObjectTO)9 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)7 IOException (java.io.IOException)5