@Override
 public List<PermissionSubject> getPermissionCheckSubjects() {
   if (permsList == null) {
     permsList = super.getPermissionCheckSubjects();
     Guid diskId = disk == null ? null : disk.getId();
     permsList.add(new PermissionSubject(diskId, VdcObjectType.Disk, ActionGroup.ATTACH_DISK));
   }
   return permsList;
 }
Beispiel #2
0
  private ArrayList<VdcActionParametersBase> createHotPlugDiskToVmParameters(boolean plug) {
    ArrayList<VdcActionParametersBase> parametersList = new ArrayList<VdcActionParametersBase>();
    VM vm = getEntity();

    for (Object item : getSelectedItems()) {
      Disk disk = (Disk) item;
      disk.setPlugged(plug);

      parametersList.add(new HotPlugDiskToVmParameters(vm.getId(), disk.getId()));
    }

    return parametersList;
  }
  private boolean canRemoveVmWithDetachDisks() {
    if (!Guid.Empty.equals(getVm().getVmtGuid())) {
      return failValidation(EngineMessage.VM_CANNOT_REMOVE_WITH_DETACH_DISKS_BASED_ON_TEMPLATE);
    }

    for (Disk disk : getVm().getDiskList()) {
      List<DiskImage> diskImageList = diskImageDao.getAllSnapshotsForImageGroup(disk.getId());
      if (diskImageList.size() > 1) {
        return failValidation(EngineMessage.VM_CANNOT_REMOVE_WITH_DETACH_DISKS_SNAPSHOTS_EXIST);
      }
    }

    return true;
  }
 protected VmDevice createVmDevice() {
   return new VmDevice(
       new VmDeviceId(disk.getId(), getVmId()),
       VmDeviceGeneralType.DISK,
       VmDeviceType.DISK.getName(),
       "",
       0,
       null,
       true,
       getParameters().isPlugUnPlug(),
       getParameters().isReadOnly(),
       "",
       null,
       getParameters().getSnapshotId(),
       null);
 }
Beispiel #5
0
  private void scanAlignment() {
    ArrayList<VdcActionParametersBase> parameterList = new ArrayList<VdcActionParametersBase>();

    for (Disk disk : getSelectedItems()) {
      parameterList.add(new GetDiskAlignmentParameters(disk.getId()));
    }

    Frontend.getInstance()
        .runMultipleAction(
            VdcActionType.GetDiskAlignment,
            parameterList,
            new IFrontendMultipleActionAsyncCallback() {
              @Override
              public void executed(FrontendMultipleActionAsyncResult result) {}
            },
            this);
  }
  @Mapping(
      from = org.ovirt.engine.core.common.businessentities.storage.Disk.class,
      to = DiskSnapshot.class)
  public static DiskSnapshot map(
      org.ovirt.engine.core.common.businessentities.storage.Disk entity, DiskSnapshot template) {
    if (template == null) {
      template = new DiskSnapshot();
    }
    DiskSnapshot model = (DiskSnapshot) DiskMapper.map(entity, template);

    Disk disk = new Disk();
    disk.setId(entity.getId().toString());
    model.setDisk(disk);

    DiskImage diskImage = (DiskImage) entity;
    model.setId(diskImage.getImageId().toString());
    model.setImageId(null);

    return model;
  }
  @Override
  protected Map<String, Pair<String, String>> getExclusiveLocks() {
    if (disk == null) {
      return null;
    }

    Map<String, Pair<String, String>> locks = new HashMap<>();
    if (!disk.isShareable()) {
      locks.put(
          disk.getId().toString(),
          LockMessagesMatchUtil.makeLockingPair(
              LockingGroup.DISK, EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED));
    }

    if (disk.isBoot()) {
      locks.put(
          getParameters().getVmId().toString(),
          LockMessagesMatchUtil.makeLockingPair(
              LockingGroup.VM_DISK_BOOT, EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED));
    }

    return locks;
  }
  @Override
  protected boolean canDoAction() {
    if (disk == null) {
      return failCanDoAction(EngineMessage.ACTION_TYPE_FAILED_VM_IMAGE_DOES_NOT_EXIST);
    }

    DiskValidator oldDiskValidator = new DiskValidator(disk);
    ValidationResult isHostedEngineDisk = oldDiskValidator.validateNotHostedEngineDisk();
    if (!isHostedEngineDisk.isValid()) {
      return validate(isHostedEngineDisk);
    }

    disk.setReadOnly(getParameters().isReadOnly());
    DiskValidator diskValidator = getDiskValidator(disk);

    if (!checkDiskUsedAsOvfStore(diskValidator)) {
      return false;
    }

    if (isOperationPerformedOnDiskSnapshot()
        && (!validate(getSnapshotsValidator().snapshotExists(getSnapshot()))
            || !validate(
                getSnapshotsValidator()
                    .snapshotTypeSupported(
                        getSnapshot(), Collections.singletonList(SnapshotType.REGULAR))))) {
      return false;
    }

    boolean isImageDisk = disk.getDiskStorageType().isInternal();

    if (isImageDisk) {
      // TODO : this load and check of the active disk will be removed
      // after inspecting upgrade
      Disk activeDisk = loadActiveDisk(disk.getId());

      if (((DiskImage) activeDisk).getImageStatus() == ImageStatus.ILLEGAL) {
        return failCanDoAction(EngineMessage.ACTION_TYPE_FAILED_ILLEGAL_DISK_OPERATION);
      }

      if (((DiskImage) disk).getImageStatus() == ImageStatus.LOCKED) {
        addCanDoActionMessage(EngineMessage.ACTION_TYPE_FAILED_DISKS_LOCKED);
        addCanDoActionMessageVariable("diskAliases", disk.getDiskAlias());
        return false;
      }
    }

    if (!isVmExist() || !isVmInUpPausedDownStatus()) {
      return false;
    }

    if (!canRunActionOnNonManagedVm()) {
      return false;
    }

    updateDisksFromDb();
    if (!isDiskCanBeAddedToVm(disk, getVm()) || !isDiskPassPciAndIdeLimit(disk)) {
      return false;
    }

    if (getVmDeviceDao().exists(new VmDeviceId(disk.getId(), getVmId()))) {
      return failCanDoAction(EngineMessage.ACTION_TYPE_FAILED_DISK_ALREADY_ATTACHED);
    }

    if (disk.isShareable()
        && !isVersionSupportedForShareable(
            disk,
            getStoragePoolDao()
                .get(getVm().getStoragePoolId())
                .getCompatibilityVersion()
                .getValue())) {
      return failCanDoAction(EngineMessage.ACTION_NOT_SUPPORTED_FOR_CLUSTER_POOL_LEVEL);
    }

    if (!isOperationPerformedOnDiskSnapshot() && !disk.isShareable() && disk.getNumberOfVms() > 0) {
      return failCanDoAction(EngineMessage.ACTION_TYPE_FAILED_NOT_SHAREABLE_DISK_ALREADY_ATTACHED);
    }

    if (isImageDisk
        && getStoragePoolIsoMapDao()
                .get(
                    new StoragePoolIsoMapId(
                        ((DiskImage) disk).getStorageIds().get(0), getVm().getStoragePoolId()))
            == null) {
      return failCanDoAction(EngineMessage.ACTION_TYPE_FAILED_STORAGE_POOL_NOT_MATCH);
    }
    if (isImageDisk) {
      StorageDomain storageDomain =
          getStorageDomainDao()
              .getForStoragePool(
                  ((DiskImage) disk).getStorageIds().get(0), ((DiskImage) disk).getStoragePoolId());
      StorageDomainValidator storageDomainValidator = getStorageDomainValidator(storageDomain);
      if (!validate(storageDomainValidator.isDomainExistAndActive())) {
        return false;
      }
    }

    if (!validate(diskValidator.isReadOnlyPropertyCompatibleWithInterface())) {
      return false;
    }

    if (!validate(diskValidator.isVirtIoScsiValid(getVm()))) {
      return false;
    }

    if (!validate(diskValidator.isDiskInterfaceSupported(getVm()))) {
      return false;
    }

    if (!isVmNotInPreviewSnapshot()) {
      return false;
    }

    if (getParameters().isPlugUnPlug() && getVm().getStatus() != VMStatus.Down) {
      return canPerformDiskHotPlug(disk);
    }
    return true;
  }