private boolean canPerformQuotaValidation() {
   if (DiskStorageType.IMAGE == _oldDisk.getDiskStorageType()) {
     if (!((DiskImage) _oldDisk).getQuotaId().equals(getQuotaId())) {
       return true;
     }
   }
   return false;
 }
  /**
   * Validate whether a disk can be shareable. Disk can be shareable if it is not based on qcow FS,
   * which means it should not be based on a template image with thin provisioning, it also should
   * not contain snapshots and it is not bootable.
   *
   * @return Indication whether the disk can be shared or not.
   */
  protected boolean validateShareableDisk() {
    if (DiskStorageType.LUN == _oldDisk.getDiskStorageType()) {
      return true;
    }
    boolean isDiskUpdatedToShareable = getParameters().getDiskInfo().isShareable();
    boolean isDiskShareable = _oldDisk.isShareable();

    // Check if VM is not during snapshot.
    if (getSnapshotDao().exists(getVmId(), SnapshotStatus.IN_PREVIEW)) {
      addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_VM_IN_PREVIEW);
      return false;
    }

    // If user want to update the disk to be shareable then update the vm snapshot id to be null.
    if (!isDiskShareable && isDiskUpdatedToShareable) {
      List<DiskImage> diskImageList =
          getDiskImageDao().getAllSnapshotsForImageGroup(_oldDisk.getId());

      // If disk image list is more then one then we assume that it has a snapshot, since one image
      // is the active
      // disk and all the other images are the snapshots.
      if ((diskImageList.size() > 1) || !Guid.Empty.equals(((DiskImage) _oldDisk).getit_guid())) {
        addCanDoActionMessage(VdcBllMessages.SHAREABLE_DISK_IS_NOT_SUPPORTED_FOR_DISK);
        return false;
      }
      if (!isVersionSupportedForShareable(
          _oldDisk,
          getStoragePoolDAO()
              .get(getVm().getstorage_pool_id())
              .getcompatibility_version()
              .getValue())) {
        addCanDoActionMessage(VdcBllMessages.ACTION_NOT_SUPPORTED_FOR_CLUSTER_POOL_LEVEL);
        return false;
      }

      DiskImage diskImage = (DiskImage) getParameters().getDiskInfo();
      if (!isVolumeFormatSupportedForShareable(diskImage.getvolume_format())) {
        addCanDoActionMessage(VdcBllMessages.SHAREABLE_DISK_IS_NOT_SUPPORTED_BY_VOLUME_FORMAT);
        return false;
      }

      diskImage.setvm_snapshot_id(null);
    } else if (isDiskShareable && !isDiskUpdatedToShareable) {
      if (getVmDAO().getVmsListForDisk(_oldDisk.getId()).size() > 1) {
        addCanDoActionMessage(VdcBllMessages.DISK_IS_ALREADY_SHARED_BETWEEN_VMS);
        return false;
      }

      // If disk is not floating, then update its vm snapshot id to the active VM snapshot.
      ((DiskImage) _oldDisk)
          .setvm_snapshot_id(
              DbFacade.getInstance()
                  .getSnapshotDao()
                  .getId(getVmId(), SnapshotType.ACTIVE)
                  .getValue());
    }
    return true;
  }
  @SuppressWarnings("rawtypes")
  @Override
  public void setItems(Iterable value) {
    ArrayList<Disk> disks = value != null ? Linq.<Disk>Cast(value) : new ArrayList<Disk>();
    ArrayList<Disk> filteredDisks = new ArrayList<Disk>();
    DiskStorageType diskStorageType = (DiskStorageType) getDiskViewType().getEntity();

    for (Disk disk : disks) {
      if (diskStorageType == null || diskStorageType == disk.getDiskStorageType()) {
        filteredDisks.add(disk);
      }
    }

    super.setItems(filteredDisks);
  }
Пример #4
0
  public static DiskModel DiskToModel(Disk disk) {
    DiskModel diskModel = new DiskModel();
    diskModel.setIsNew(true);
    diskModel.getAlias().setEntity(disk.getDiskAlias());

    if (disk.getDiskStorageType() == DiskStorageType.IMAGE) {
      DiskImage diskImage = (DiskImage) disk;
      EntityModel sizeEntity = new EntityModel();
      sizeEntity.setEntity(diskImage.getSizeInGigabytes());
      diskModel.setSize(sizeEntity);
      ListModel volumeList = new ListModel();
      volumeList.setItems(
          (diskImage.getvolume_type() == VolumeType.Preallocated
              ? new ArrayList<VolumeType>(Arrays.asList(new VolumeType[] {VolumeType.Preallocated}))
              : DataProvider.GetVolumeTypeList()));
      volumeList.setSelectedItem(diskImage.getvolume_type());
      diskModel.setVolumeType(volumeList);
    }

    diskModel.setDisk(disk);

    return diskModel;
  }