use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class VdsBrokerObjectsBuilder method buildDiskImagesFromDevices.
/**
* Convert the devices map and make a list of {@linkplain DiskImage}
* Mainly used to import the Hosted Engine Vm disks.
*
* @return A List of Disk Images {@linkplain DiskImage}
*/
public static ArrayList<DiskImage> buildDiskImagesFromDevices(Map<String, Object> vmStruct, Guid vmId) {
ArrayList<DiskImage> diskImages = new ArrayList<>();
Object[] devices = (Object[]) vmStruct.get("devices");
if (devices != null) {
for (Object device : devices) {
Map<String, Object> deviceMap = (Map<String, Object>) device;
if (VdsProperties.Disk.equals(deviceMap.get(VdsProperties.Device))) {
DiskImage image = new DiskImage();
image.setDiskAlias((String) deviceMap.get(VdsProperties.Alias));
Long size = assignLongValue(deviceMap, VdsProperties.disk_apparent_size);
image.setSize(size != null ? size : 0);
Double actualSize = assignDoubleValue(deviceMap, VdsProperties.disk_true_size);
image.setActualSize(actualSize != null ? actualSize : 0);
image.setVolumeFormat(VolumeFormat.valueOf(((String) deviceMap.get(VdsProperties.Format)).toUpperCase()));
image.setShareable(false);
String id = assignStringValue(deviceMap, VdsProperties.DeviceId);
if (id == null) {
id = assignStringValue(deviceMap, VdsProperties.ImageId);
}
image.setId(Guid.createGuidFromString(id));
image.setImageId(Guid.createGuidFromString((String) deviceMap.get(VdsProperties.VolumeId)));
Guid domainId = Guid.createGuidFromString((String) deviceMap.get(VdsProperties.DomainId));
List<Guid> domainIds = Collections.singletonList(domainId);
image.setStorageIds(new ArrayList<>(domainIds));
// TODO not sure how to extract that info
image.setVolumeType(VolumeType.Preallocated);
DiskVmElement dve = new DiskVmElement(image.getId(), vmId);
image.setDiskVmElements(Collections.singletonList(dve));
switch((String) deviceMap.get("iface")) {
case "virtio":
dve.setDiskInterface(DiskInterface.VirtIO);
break;
case "iscsi":
case "scsi":
dve.setDiskInterface(DiskInterface.VirtIO_SCSI);
break;
case "ide":
dve.setDiskInterface(DiskInterface.IDE);
break;
}
diskImages.add(image);
}
}
}
return diskImages;
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class VdsBrokerObjectsBuilder method buildDiskImageFromExternalProvider.
private static DiskImage buildDiskImageFromExternalProvider(Map<String, Object> map, Guid vmId) {
DiskImage image = new DiskImage();
image.setDiskAlias((String) map.get(VdsProperties.Alias));
image.setSize(Long.parseLong((String) map.get(VdsProperties.DISK_VIRTUAL_SIZE)));
image.setActualSizeInBytes(Long.parseLong((String) map.get(VdsProperties.DISK_ALLOCATION)));
image.setId(Guid.newGuid());
if (map.containsKey(VdsProperties.Format)) {
image.setVolumeFormat(VolumeFormat.valueOf(((String) map.get(VdsProperties.Format)).toUpperCase()));
}
DiskVmElement dve = buildDiskVmElementWithDiskInterfaceFromExternalProvider(map, image, vmId);
image.setDiskVmElements(Collections.singletonList(dve));
return image;
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class AttachDiskModel method store.
@Override
public void store(IFrontendActionAsyncCallback callback) {
if (getProgress() != null || !validate()) {
return;
}
ArrayList<ActionType> actionTypes = new ArrayList<>();
ArrayList<ActionParametersBase> paramerterList = new ArrayList<>();
ArrayList<IFrontendActionAsyncCallback> callbacks = new ArrayList<>();
IFrontendActionAsyncCallback onFinishCallback = callback != null ? callback : result -> {
NewDiskModel diskModel = (NewDiskModel) result.getState();
diskModel.stopProgress();
diskModel.cancel();
};
List<EntityModel<DiskModel>> disksToAttach = getSelectedDisks();
for (int i = 0; i < disksToAttach.size(); i++) {
DiskModel disk = disksToAttach.get(i).getEntity();
/*
IDE disks can be activated only when the VM is down.
Other disks can be hot plugged.
*/
boolean activate = false;
if (getIsPlugged().getEntity()) {
activate = disk.getDiskInterface().getSelectedItem() == DiskInterface.IDE ? getVm().getStatus() == VMStatus.Down : true;
}
DiskVmElement dve = new DiskVmElement(disk.getDisk().getId(), getVm().getId());
dve.setBoot(disk.getIsBootable().getEntity());
dve.setDiskInterface(disk.getDiskInterface().getSelectedItem());
dve.setReadOnly(disk.isReadOnly());
AttachDetachVmDiskParameters parameters = new AttachDetachVmDiskParameters(dve, activate);
actionTypes.add(ActionType.AttachDiskToVm);
paramerterList.add(parameters);
callbacks.add(i == disksToAttach.size() - 1 ? onFinishCallback : null);
}
startProgress();
Frontend.getInstance().runMultipleActions(actionTypes, paramerterList, callbacks, null, this);
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class NewDiskModel method initialize.
@Override
public void initialize(List<DiskModel> currentDisks) {
super.initialize(currentDisks);
setDiskVmElement(new DiskVmElement(new VmDeviceId(null, getIsFloating() ? null : getVm().getId())));
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class SnapshotsManager method populateDisksWithVmData.
private void populateDisksWithVmData(List<? extends Disk> disks, Guid vmId) {
for (Disk disk : disks) {
DiskVmElement dve = diskVmElementDao.get(new VmDeviceId(disk.getId(), vmId));
disk.setDiskVmElements(Collections.singletonList(dve));
}
}
Aggregations