use of com.cloud.legacymodel.to.NfsTO 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();
}
}
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);
}
}
}
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");
}
use of com.cloud.legacymodel.to.NfsTO in project cosmic by MissionCriticalCloud.
the class NfsSecondaryStorageResource method deleteSnapshot.
protected Answer deleteSnapshot(final DeleteCommand cmd) {
final DataTO obj = cmd.getData();
final DataStoreTO dstore = obj.getDataStore();
if (dstore instanceof NfsTO) {
final NfsTO nfs = (NfsTO) dstore;
String parent = getRootDir(nfs.getUrl());
if (!parent.endsWith(File.separator)) {
parent += File.separator;
}
String snapshotPath = obj.getPath();
if (snapshotPath.startsWith(File.separator)) {
snapshotPath = snapshotPath.substring(1);
}
// check if the passed snapshot path is a directory or not. For ImageCache, path is stored as a directory instead of
// snapshot file name. If so, since backupSnapshot process has already deleted snapshot in cache, so we just do nothing
// and return true.
final String fullSnapPath = parent + snapshotPath;
final File snapDir = new File(fullSnapPath);
if (snapDir.exists() && snapDir.isDirectory()) {
s_logger.debug("snapshot path " + snapshotPath + " is a directory, already deleted during backup snapshot, so no need to delete");
return new Answer(cmd, true, null);
}
// passed snapshot path is a snapshot file path, then get snapshot directory first
final int index = snapshotPath.lastIndexOf("/");
final String snapshotName = snapshotPath.substring(index + 1);
snapshotPath = snapshotPath.substring(0, index);
final String absoluteSnapshotPath = parent + snapshotPath;
// check if snapshot directory exists
final File snapshotDir = new File(absoluteSnapshotPath);
String details = null;
if (!snapshotDir.exists()) {
details = "snapshot directory " + snapshotDir.getName() + " doesn't exist";
s_logger.debug(details);
return new Answer(cmd, true, details);
}
// delete snapshot in the directory if exists
final String lPath = absoluteSnapshotPath + "/*" + snapshotName + "*";
final String result = deleteLocalFile(lPath);
if (result != null) {
details = "failed to delete snapshot " + lPath + " , err=" + result;
s_logger.warn(details);
return new Answer(cmd, false, details);
}
return new Answer(cmd, true, null);
} else {
return new Answer(cmd, false, "Unsupported image data store: " + dstore);
}
}
use of com.cloud.legacymodel.to.NfsTO in project cosmic by MissionCriticalCloud.
the class NfsSecondaryStorageResource method execute.
private Answer execute(final ListVolumeCommand cmd) {
if (!this._inSystemVM) {
return new ListVolumeAnswer(cmd.getSecUrl(), null);
}
final DataStoreTO store = cmd.getDataStore();
if (store instanceof NfsTO) {
final String root = getRootDir(cmd.getSecUrl());
final Map<Long, TemplateProp> templateInfos = this._dlMgr.gatherVolumeInfo(root);
return new ListVolumeAnswer(cmd.getSecUrl(), templateInfos);
} else {
return new Answer(cmd, false, "Unsupported image data store: " + store);
}
}
Aggregations