Search in sources :

Example 1 with AttachDetachVmDiskParameters

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);
}
Also used : ActionType(org.ovirt.engine.core.common.action.ActionType) ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) AttachDetachVmDiskParameters(org.ovirt.engine.core.common.action.AttachDetachVmDiskParameters) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)

Example 2 with AttachDetachVmDiskParameters

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;
}
Also used : AttachDetachVmDiskParameters(org.ovirt.engine.core.common.action.AttachDetachVmDiskParameters) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)

Example 3 with AttachDetachVmDiskParameters

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);
}
Also used : AttachDetachVmDiskParameters(org.ovirt.engine.core.common.action.AttachDetachVmDiskParameters) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Guid(org.ovirt.engine.core.compat.Guid) Disk(org.ovirt.engine.api.model.Disk)

Example 4 with AttachDetachVmDiskParameters

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()));
}
Also used : AttachDetachVmDiskParameters(org.ovirt.engine.core.common.action.AttachDetachVmDiskParameters) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)

Example 5 with AttachDetachVmDiskParameters

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;
}
Also used : AttachDetachVmDiskParameters(org.ovirt.engine.core.common.action.AttachDetachVmDiskParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) LinkedList(java.util.LinkedList)

Aggregations

AttachDetachVmDiskParameters (org.ovirt.engine.core.common.action.AttachDetachVmDiskParameters)6 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)6 ArrayList (java.util.ArrayList)2 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)2 ActionType (org.ovirt.engine.core.common.action.ActionType)2 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)2 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Disk (org.ovirt.engine.api.model.Disk)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1 RemoveDiskParameters (org.ovirt.engine.core.common.action.RemoveDiskParameters)1 VM (org.ovirt.engine.core.common.businessentities.VM)1 Guid (org.ovirt.engine.core.compat.Guid)1 Frontend (org.ovirt.engine.ui.frontend.Frontend)1 ICommandTarget (org.ovirt.engine.ui.uicommonweb.ICommandTarget)1 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)1 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)1 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)1