use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.
the class OvfOvaReader method readDisk.
@Override
protected void readDisk(XmlNode node, DiskImage image) {
String diskId = node.attributes.get("ovf:diskId").getValue();
String fileRef = node.attributes.get("ovf:fileRef").getValue();
// If the disk storage type is Cinder then override the disk image with Cinder object,
// otherwise use the disk image.
image = new DiskImage();
// image.
if (node.attributes.get("ovf:disk_storage_type") != null) {
String diskStorageType = node.attributes.get("ovf:disk_storage_type").getValue();
if (diskStorageType != null && diskStorageType.equals(DiskStorageType.CINDER.name())) {
image = new CinderDisk();
if (node.attributes.get("ovf:cinder_volume_type") != null) {
String cinderVolumeType = node.attributes.get("ovf:cinder_volume_type").getValue();
image.setCinderVolumeType(cinderVolumeType);
}
}
}
try {
image.setImageId(new Guid(fileRef));
} catch (Exception ex) {
log.warn("could not retrieve volume id of {} from ovf, generating new guid", fileRef);
image.setImageId(Guid.newGuid());
}
try {
image.setId(new Guid(diskId));
} catch (Exception ex) {
log.warn("could not retrieve disk id of {} from ovf, generating new guid", diskId);
image.setId(Guid.newGuid());
}
XmlAttribute description = node.attributes.get("ovf:description");
if (description != null) {
image.setDescription(description.getValue());
} else {
image.setDescription(diskId);
}
XmlAttribute virtualSize = node.attributes.get("ovf:capacity");
if (virtualSize != null) {
// TODO take ovf:capacityAllocationUnits into account
image.setSize(convertGigabyteToBytes(Long.parseLong(virtualSize.getValue())));
}
XmlAttribute populatedSize = node.attributes.get("ovf:populatedSize");
if (populatedSize != null) {
image.setActualSizeInBytes(Long.parseLong(populatedSize.getValue()));
} else {
Long actualSize = Long.parseLong(fileIdToFileAttributes.get(fileRef).get("ovf:size").getValue());
image.setActualSizeInBytes(actualSize);
}
super.readDisk(node, image);
if (StringUtils.isEmpty(image.getDiskAlias())) {
image.setDiskAlias(diskId);
}
image.setRemotePath(fileIdToFileAttributes.get(fileRef).get("ovf:href").getValue());
_images.add(image);
}
use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.
the class RestoreAllCinderSnapshotsCommand method executeVmCommand.
@Override
protected void executeVmCommand() {
for (CinderDisk cinderDisk : getParameters().getCinderDisksToRestore()) {
ImagesContainterParametersBase params = getRestoreFromSnapshotParams(cinderDisk);
restoreCinderDisk(cinderDisk, params);
// In case we want to undo the previewed snapshot.
if (getParameters().getSnapshot().getType() == Snapshot.SnapshotType.STATELESS) {
Guid activeSnapshotId = snapshotDao.get(getParameters().getVmId(), Snapshot.SnapshotType.ACTIVE).getId();
updateCinderDiskSnapshot(cinderDisk.getId(), activeSnapshotId, cinderDisk.getVmSnapshotId());
} else if (getParameters().getSnapshot().getType() != Snapshot.SnapshotType.REGULAR) {
updateCinderDiskSnapshot(cinderDisk.getId(), getParameters().getSnapshot().getId(), null);
}
}
List<CinderDisk> cinderDisksToRemove = getParameters().getCinderDisksToRemove();
for (CinderDisk cinderDisk : cinderDisksToRemove) {
RemoveCinderDiskParameters removeDiskParam = new RemoveCinderDiskParameters(cinderDisk.getImageId());
removeDiskParam.setRemovedVolume(cinderDisk);
removeDiskParam.setParentCommand(getActionType());
removeDiskParam.setStorageDomainId(cinderDisk.getStorageIds().get(0));
removeDiskParam.setParentParameters(getParameters());
removeDiskParam.setEndProcedure(EndProcedure.COMMAND_MANAGED);
Future<ActionReturnValue> future = commandCoordinatorUtil.executeAsyncCommand(ActionType.RemoveCinderDisk, removeDiskParam, cloneContextAndDetachFromParent());
try {
future.get();
} catch (InterruptedException | ExecutionException e) {
log.error("Error removing Cinder disk", e);
}
}
List<CinderDisk> cinderVolumesToRemove = getParameters().getCinderVolumesToRemove();
for (CinderDisk cinderVolume : cinderVolumesToRemove) {
RemoveCinderDiskVolumeParameters removeDiskVolumeParam = new RemoveCinderDiskVolumeParameters(cinderVolume);
removeDiskVolumeParam.setParentCommand(getActionType());
removeDiskVolumeParam.setParentParameters(getParameters());
removeDiskVolumeParam.setEndProcedure(EndProcedure.COMMAND_MANAGED);
Future<ActionReturnValue> future = commandCoordinatorUtil.executeAsyncCommand(ActionType.RemoveCinderDiskVolume, removeDiskVolumeParam, cloneContextAndDetachFromParent());
try {
future.get();
} catch (InterruptedException | ExecutionException e) {
log.error("Error removing Cinder disk", e);
}
}
setSucceeded(true);
}
use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.
the class TryBackToCinderSnapshotCommand method createVolumeFromSnapshotInCinder.
private CinderDisk createVolumeFromSnapshotInCinder() {
Guid newVolumeId = cinderCloneDiskFromSnapshot();
CinderDisk clonedDiskFromSnapshot = initializeNewCinderVolumeDisk(newVolumeId);
// Setting this for the callback from coco.
getParameters().setDestinationImageId(newVolumeId);
return clonedDiskFromSnapshot;
}
use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.
the class RegisterCinderDiskCommand method executeCommand.
@Override
public void executeCommand() {
QueryReturnValue returnValue = runInternalQuery(QueryType.GetUnregisteredCinderDiskByIdAndStorageDomainId, new GetCinderEntityByStorageDomainIdParameters(getCinderDisk().getId(), getParameters().getStorageDomainId()));
CinderDisk cinderDisk = returnValue.getReturnValue();
if (cinderDisk != null) {
addCinderDiskToDB(cinderDisk);
getReturnValue().setActionReturnValue(cinderDisk.getId());
setSucceeded(true);
}
}
use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.
the class RegisterCinderDiskCommand method validate.
@Override
public boolean validate() {
CinderDisk cinderDisk = getCinderDisk();
cinderDisk.setStorageIds(new ArrayList<>(Arrays.asList(getParameters().getStorageDomainId())));
CinderDisksValidator cinderDiskValidator = getCinderDisksValidator(cinderDisk);
return validate(cinderDiskValidator.validateCinderDisksAlreadyRegistered());
}
Aggregations