Search in sources :

Example 6 with NfsTO

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

the class NfsSecondaryStorageResource method createTemplateFromSnapshot.

protected Answer createTemplateFromSnapshot(final CopyCommand cmd) {
    final DataTO srcData = cmd.getSrcTO();
    final DataTO destData = cmd.getDestTO();
    final DataStoreTO srcDataStore = srcData.getDataStore();
    final DataStoreTO destDataStore = destData.getDataStore();
    if (srcDataStore.getRole() == DataStoreRole.Image || srcDataStore.getRole() == DataStoreRole.ImageCache || srcDataStore.getRole() == DataStoreRole.Primary) {
        if (!(srcDataStore instanceof NfsTO)) {
            s_logger.debug("only support nfs storage as src, when create template from snapshot");
            return Answer.createUnsupportedCommandAnswer(cmd);
        }
        if (destDataStore instanceof NfsTO) {
            return copySnapshotToTemplateFromNfsToNfs(cmd, (SnapshotObjectTO) srcData, (NfsTO) srcDataStore, (TemplateObjectTO) destData, (NfsTO) destDataStore);
        }
    }
    s_logger.debug("Failed to create templat from snapshot");
    return new CopyCmdAnswer("Unsupported prototcol");
}
Also used : DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) DataTO(com.cloud.legacymodel.to.DataTO) NfsTO(com.cloud.legacymodel.to.NfsTO) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer)

Example 7 with NfsTO

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

the class NfsSecondaryStorageResource method execute.

private Answer execute(final ComputeChecksumCommand cmd) {
    String relativeTemplatePath = cmd.getTemplatePath();
    final DataStoreTO store = cmd.getStore();
    if (!(store instanceof NfsTO)) {
        return new Answer(cmd, false, "can't handle non nfs data store");
    }
    final NfsTO nfsStore = (NfsTO) store;
    String parent = getRootDir(nfsStore.getUrl());
    if (relativeTemplatePath.startsWith(File.separator)) {
        relativeTemplatePath = relativeTemplatePath.substring(1);
    }
    if (!parent.endsWith(File.separator)) {
        parent += File.separator;
    }
    final String absoluteTemplatePath = parent + relativeTemplatePath;
    final MessageDigest digest;
    String checksum = null;
    final File f = new File(absoluteTemplatePath);
    InputStream is = null;
    final byte[] buffer = new byte[8192];
    int read = 0;
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("parent path " + parent + " relative template path " + relativeTemplatePath);
    }
    try {
        digest = MessageDigest.getInstance("MD5");
        is = new FileInputStream(f);
        while ((read = is.read(buffer)) > 0) {
            digest.update(buffer, 0, read);
        }
        final byte[] md5sum = digest.digest();
        final BigInteger bigInt = new BigInteger(1, md5sum);
        checksum = bigInt.toString(16);
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Successfully calculated checksum for file " + absoluteTemplatePath + " - " + checksum);
        }
    } catch (final IOException e) {
        final String logMsg = "Unable to process file for MD5 - " + absoluteTemplatePath;
        s_logger.error(logMsg);
        return new Answer(cmd, false, checksum);
    } catch (final NoSuchAlgorithmException e) {
        return new Answer(cmd, false, checksum);
    } finally {
        try {
            if (is != null) {
                is.close();
            }
        } catch (final IOException e) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Could not close the file " + absoluteTemplatePath);
            }
            return new Answer(cmd, false, checksum);
        }
    }
    return new Answer(cmd, true, checksum);
}
Also used : DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NfsTO(com.cloud.legacymodel.to.NfsTO) FileInputStream(java.io.FileInputStream) 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) BigInteger(java.math.BigInteger) MessageDigest(java.security.MessageDigest) File(java.io.File)

Example 8 with NfsTO

use of com.cloud.legacymodel.to.NfsTO 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 9 with NfsTO

use of com.cloud.legacymodel.to.NfsTO 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 10 with NfsTO

use of com.cloud.legacymodel.to.NfsTO 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)

Aggregations

NfsTO (com.cloud.legacymodel.to.NfsTO)46 DataStoreTO (com.cloud.legacymodel.to.DataStoreTO)36 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)32 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)28 DataTO (com.cloud.legacymodel.to.DataTO)26 PrimaryDataStoreTO (com.cloud.legacymodel.to.PrimaryDataStoreTO)26 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)21 XenAPIException (com.xensource.xenapi.Types.XenAPIException)18 XmlRpcException (org.apache.xmlrpc.XmlRpcException)18 Connection (com.xensource.xenapi.Connection)17 SR (com.xensource.xenapi.SR)17 VDI (com.xensource.xenapi.VDI)17 URI (java.net.URI)17 VolumeObjectTO (com.cloud.legacymodel.to.VolumeObjectTO)16 TemplateObjectTO (com.cloud.legacymodel.to.TemplateObjectTO)14 Answer (com.cloud.legacymodel.communication.answer.Answer)13 SnapshotObjectTO (com.cloud.legacymodel.to.SnapshotObjectTO)10 SecStorageSetupAnswer (com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer)9 CheckHealthAnswer (com.cloud.legacymodel.communication.answer.CheckHealthAnswer)8 GetStorageStatsAnswer (com.cloud.legacymodel.communication.answer.GetStorageStatsAnswer)8