use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.
the class CreateCinderSnapshotCommand method cloneDisk.
private CinderDisk cloneDisk() {
boolean isStateless = isStatelessSnapshot();
CinderDisk cinderDependentVolume = getDisk();
initCinderDependentVolume(cinderDependentVolume);
cinderDependentVolume.setActive(isStateless);
String volumeId = isStateless ? getCinderBroker().cloneDisk(cinderDependentVolume) : getCinderBroker().createSnapshot(cinderDependentVolume, getParameters().getDescription());
cinderDependentVolume.setVolumeClassification(isStateless ? VolumeClassification.Volume : VolumeClassification.Snapshot);
Guid destinationImageId = Guid.createGuidFromString(volumeId);
getParameters().setDestinationImageId(destinationImageId);
cinderDependentVolume.setImageId(destinationImageId);
return cinderDependentVolume;
}
use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.
the class CreateCinderSnapshotCommand method executeCommand.
@Override
protected void executeCommand() {
final CinderDisk newCinderVolume;
newCinderVolume = cloneDisk();
if (!isStatelessSnapshot()) {
getDiskImage().setVmSnapshotId(getParameters().getVmSnapshotId());
}
TransactionSupport.executeInNewTransaction(() -> {
processOldImageFromDb();
addDiskImageToDb(newCinderVolume, getCompensationContext(), isStatelessSnapshot());
setActionReturnValue(newCinderVolume);
setSucceeded(true);
return null;
});
getReturnValue().setActionReturnValue(newCinderVolume.getImageId());
persistCommand(getParameters().getParentCommand(), true);
setSucceeded(true);
}
use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.
the class ExtendCinderDiskCommand method performDiskUpdate.
protected void performDiskUpdate() {
CinderDisk cinderDisk = (CinderDisk) getNewDisk();
imageDao.updateImageSize(cinderDisk.getImageId(), cinderDisk.getSize());
performDiskUpdate(true);
}
use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.
the class LibvirtVmXmlBuilder method writeDiskSource.
private void writeDiskSource(Disk disk, String dev) {
writer.writeStartElement("source");
switch(disk.getDiskStorageType()) {
case IMAGE:
DiskImage diskImage = (DiskImage) disk;
// Change parameters for the HE disk
if (vm.isHostedEngine()) {
// Hosted engine disk images have to have empty storage pool ID,
// so they can be mounted even if storage pool is not connected.
diskImage.setStoragePoolId(Guid.Empty);
diskImage.setPropagateErrors(PropagateErrors.Off);
// The disk requires a lease
addVolumeLease(diskImage.getImageId(), diskImage.getStorageIds().get(0));
}
String diskType = this.vmInfoBuildUtils.getDiskType(this.vm, diskImage);
switch(diskType) {
case "block":
writer.writeAttributeString("dev", vmInfoBuildUtils.getPathToImage(diskImage));
break;
case "network":
String[] volInfo = vmInfoBuildUtils.getGlusterVolInfo(disk);
// drop to the 'file' case as a fallback.
if (volInfo != null) {
writer.writeAttributeString("protocol", "gluster");
writer.writeAttributeString("name", String.format("%s/%s/images/%s/%s", volInfo[1], diskImage.getStorageIds().get(0), diskImage.getId(), diskImage.getImageId()));
writer.writeStartElement("host");
writer.writeAttributeString("name", volInfo[0]);
writer.writeAttributeString("port", "0");
writer.writeEndElement();
break;
}
case "file":
writer.writeAttributeString("file", vmInfoBuildUtils.getPathToImage(diskImage));
break;
}
diskMetadata.put(dev, createDiskParams(diskImage));
break;
case LUN:
LunDisk lunDisk = (LunDisk) disk;
writer.writeAttributeString("dev", String.format("/dev/mapper/%s", lunDisk.getLun().getLUNId()));
diskMetadata.put(dev, Collections.singletonMap("GUID", lunDisk.getLun().getLUNId()));
break;
case CINDER:
// case RBD
CinderDisk cinderDisk = (CinderDisk) disk;
Map<String, Object> connectionInfoData = cinderDisk.getCinderConnectionInfo().getData();
writer.writeAttributeString("protocol", cinderDisk.getCinderConnectionInfo().getDriverVolumeType());
writer.writeAttributeString("name", connectionInfoData.get("name").toString());
List<String> hostAddresses = (List<String>) connectionInfoData.get("hosts");
List<String> hostPorts = (List<String>) connectionInfoData.get("ports");
// (Cinder should ensure that the addresses and ports lists are synced in order).
for (int i = 0; i < hostAddresses.size(); i++) {
writer.writeStartElement("host");
writer.writeAttributeString("name", hostAddresses.get(i));
writer.writeAttributeString("port", hostPorts.get(i));
// If no transport is specified, "tcp" is assumed.
writer.writeEndElement();
}
break;
}
writer.writeEndElement();
}
use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.
the class UpdateVmDiskCommand method performDiskUpdate.
protected void performDiskUpdate(final boolean unlockImage) {
if (shouldPerformMetadataUpdate()) {
updateMetaDataDescription((DiskImage) getNewDisk());
}
final Disk diskForUpdate = diskDao.get(getParameters().getDiskInfo().getId());
final DiskVmElement diskVmElementForUpdate = diskVmElementDao.get(new VmDeviceId(getOldDisk().getId(), getVmId()));
applyUserChanges(diskForUpdate, diskVmElementForUpdate);
TransactionSupport.executeInNewTransaction(new TransactionMethod<Object>() {
@Override
public Object runInTransaction() {
vmStaticDao.incrementDbGeneration(getVm().getId());
updateDeviceProperties();
baseDiskDao.update(diskForUpdate);
diskVmElementDao.update(diskVmElementForUpdate);
switch(diskForUpdate.getDiskStorageType()) {
case IMAGE:
DiskImage diskImage = (DiskImage) diskForUpdate;
diskImage.setQuotaId(getQuotaId());
if (unlockImage && diskImage.getImageStatus() == ImageStatus.LOCKED) {
diskImage.setImageStatus(ImageStatus.OK);
}
imageDao.update(diskImage.getImage());
updateQuota(diskImage);
updateDiskProfile();
break;
case CINDER:
CinderDisk cinderDisk = (CinderDisk) diskForUpdate;
cinderDisk.setQuotaId(getQuotaId());
setStorageDomainId(cinderDisk.getStorageIds().get(0));
getCinderBroker().updateDisk(cinderDisk);
if (unlockImage && cinderDisk.getImageStatus() == ImageStatus.LOCKED) {
cinderDisk.setImageStatus(ImageStatus.OK);
}
imageDao.update(cinderDisk.getImage());
updateQuota(cinderDisk);
break;
case LUN:
// No specific update for LUN disk
break;
}
reloadDisks();
setSucceeded(true);
// If necessary set the new Storage QoS values on running VMs asynchronously
liveUpdateDiskProfile();
return null;
}
private void updateDeviceProperties() {
if (updateReadOnlyRequested()) {
vmDeviceForVm.setReadOnly(getDiskVmElement().isReadOnly());
vmDeviceDao.update(vmDeviceForVm);
}
if ((getOldDiskVmElement().getDiskInterface() != getDiskVmElement().getDiskInterface()) || ((getOldDiskVmElement().isBoot() != getDiskVmElement().isBoot()) && (getDiskVmElement().getDiskInterface() == DiskInterface.IDE))) {
vmDeviceForVm.setAddress("");
vmDeviceDao.clearDeviceAddress(getOldDisk().getId());
}
}
});
}
Aggregations