use of org.ovirt.engine.core.common.action.AttachDetachVmDiskParameters 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.action.AttachDetachVmDiskParameters in project ovirt-engine by oVirt.
the class AttachDiskToVmCommandTest method createParameters.
private AttachDetachVmDiskParameters createParameters() {
DiskVmElement dve = new DiskVmElement(diskId, vmId);
dve.setReadOnly(true);
AttachDetachVmDiskParameters parameters = new AttachDetachVmDiskParameters(dve);
return parameters;
}
use of org.ovirt.engine.core.common.action.AttachDetachVmDiskParameters in project ovirt-engine by oVirt.
the class BackendDiskAttachmentsResource method attachDiskToVm.
protected Response attachDiskToVm(AbstractBackendCollectionResource resource, DiskAttachment attachment, IResolver entityResolver) {
Guid diskId = Guid.createGuidFromStringDefaultEmpty(attachment.getDisk().getId());
DiskVmElement dve = map(attachment);
dve.getId().setVmId(vmId);
dve.getId().setDeviceId(diskId);
AttachDetachVmDiskParameters params = new AttachDetachVmDiskParameters(dve);
Disk disk = attachment.getDisk();
boolean isDiskActive = false;
if (attachment.isSetActive()) {
isDiskActive = BooleanUtils.toBoolean(attachment.isActive());
}
params.setPlugUnPlug(isDiskActive);
if (disk.isSetReadOnly()) {
dve.setReadOnly(BooleanUtils.toBoolean(disk.isReadOnly()));
}
if (disk.isSetSnapshot()) {
validateParameters(disk, "snapshot.id");
params.setSnapshotId(asGuid(disk.getSnapshot().getId()));
}
return resource.performCreate(ActionType.AttachDiskToVm, params, entityResolver);
}
use of org.ovirt.engine.core.common.action.AttachDetachVmDiskParameters in project ovirt-engine by oVirt.
the class CloneVmCommand method attachDetachDisk.
private void attachDetachDisk(Disk disk, ActionType actionType) {
DiskVmElement oldDve = disk.getDiskVmElementForVm(oldVmId);
runInternalAction(actionType, new AttachDetachVmDiskParameters(new DiskVmElement(disk.getId(), getParameters().getNewVmGuid()), oldDve.isPlugged()));
}
use of org.ovirt.engine.core.common.action.AttachDetachVmDiskParameters in project ovirt-engine by oVirt.
the class ImportVmFromConfigurationCommand method attemptToAttachDisksToImportedVm.
private AuditLogType attemptToAttachDisksToImportedVm(Collection<Disk> disks) {
List<String> failedDisks = new LinkedList<>();
for (Disk disk : disks) {
DiskVmElement dve = disk.getDiskVmElements().iterator().next();
AttachDetachVmDiskParameters params = new AttachDetachVmDiskParameters(dve, dve.isPlugged());
ActionReturnValue returnVal = runInternalAction(ActionType.AttachDiskToVm, params, cloneContextAndDetachFromParent());
if (!returnVal.getSucceeded()) {
failedDisks.add(disk.getDiskAlias());
}
}
if (!failedDisks.isEmpty()) {
this.addCustomValue("DiskAliases", StringUtils.join(failedDisks, ","));
return AuditLogType.VM_IMPORT_FROM_CONFIGURATION_ATTACH_DISKS_FAILED;
}
return AuditLogType.VM_IMPORT_FROM_CONFIGURATION_EXECUTED_SUCCESSFULLY;
}
Aggregations