コード例 #1
0
ファイル: OvfReader.java プロジェクト: oVirt/ovirt-engine
  private void buildImageReference() {
    XmlNodeList list = selectNodes(_document, "//*/File", _xmlNS);
    for (XmlNode node : list) {
      // If the disk storage type is Cinder then override the disk image with Cinder object,
      // otherwise use the disk image.
      DiskImage disk = new DiskImage();

      // If the OVF is old and does not contain any storage type reference then we assume we can
      // only have disk image.
      if (node.attributes.get("ovf:disk_storage_type") != null) {
        String diskStorageType = node.attributes.get("ovf:disk_storage_type").getValue();
        if (diskStorageType != null && diskStorageType.equals(DiskStorageType.CINDER.name())) {
          disk = new CinderDisk();
          if (node.attributes.get("ovf:cinder_volume_type") != null) {
            String cinderVolumeType = node.attributes.get("ovf:cinder_volume_type").getValue();
            disk.setCinderVolumeType(cinderVolumeType);
          }
        }
      }
      disk.setImageId(new Guid(node.attributes.get("ovf:id").getValue()));
      disk.setId(
          OvfParser.getImageGroupIdFromImageFile(node.attributes.get("ovf:href").getValue()));
      // Default values:
      disk.setActive(true);
      disk.setImageStatus(ImageStatus.OK);
      disk.setDescription(node.attributes.get("ovf:description").getValue());

      disk.setDiskVmElements(
          Collections.singletonList(new DiskVmElement(disk.getId(), vmBase.getId())));

      _images.add(disk);
    }
  }
コード例 #2
0
 private static DiskImage createDiskImageTemplate() {
   DiskImage i = new DiskImage();
   i.setSizeInGigabytes(USED_SPACE_GB + AVAILABLE_SPACE_GB);
   i.setActualSizeInBytes(REQUIRED_DISK_SIZE_GB * 1024L * 1024L * 1024L);
   i.setImageId(Guid.newGuid());
   i.setStorageIds(new ArrayList<>(Collections.singletonList(STORAGE_DOMAIN_ID_1)));
   return i;
 }
コード例 #3
0
 private DiskImage createDiskSnapshot(Guid diskId) {
   DiskImage di = new DiskImage();
   di.setActive(false);
   di.setId(diskId);
   di.setImageId(Guid.newGuid());
   di.setParentId(Guid.newGuid());
   di.setImageStatus(ImageStatus.OK);
   return di;
 }
コード例 #4
0
 private DiskImage createDiskImage(boolean active) {
   DiskImage di = new DiskImage();
   di.setId(Guid.newGuid());
   di.setImageId(Guid.newGuid());
   di.setParentId(Guid.newGuid());
   di.setImageStatus(ImageStatus.OK);
   di.setActive(active);
   return di;
 }
コード例 #5
0
 private static DiskImage createDiskImage(int size) {
   DiskImage diskImage = new DiskImage();
   diskImage.setSizeInGigabytes(size);
   diskImage.setActualSize(size);
   diskImage.setId(Guid.newGuid());
   diskImage.setImageId(Guid.newGuid());
   diskImage.setStorageIds(new ArrayList<>(Collections.singletonList(STORAGE_DOMAIN_ID_1)));
   return diskImage;
 }
コード例 #6
0
 protected List<DiskImage> createDiskSnapshot(Guid diskId, int numOfImages) {
   List<DiskImage> disksList = new ArrayList<>();
   for (int i = 0; i < numOfImages; ++i) {
     DiskImage diskImage = new DiskImage();
     diskImage.setActive(false);
     diskImage.setId(diskId);
     diskImage.setImageId(Guid.newGuid());
     diskImage.setParentId(Guid.newGuid());
     diskImage.setImageStatus(ImageStatus.OK);
     disksList.add(diskImage);
   }
   return disksList;
 }
コード例 #7
0
  private DiskImage mockDiskImage(DiskInterface iface) {
    disk.setImageId(diskImageGuid);
    ArrayList<Guid> storageIdList = new ArrayList<>();
    storageIdList.add(storageDomainId);
    disk.setStorageIds(storageIdList);
    disk.setStoragePoolId(storagePoolId);
    disk.setActive(true);
    disk.setId(Guid.newGuid());

    when(diskDao.get(diskImageGuid)).thenReturn(disk);
    DiskVmElement dve = new DiskVmElement(disk.getId(), vmId);
    dve.setDiskInterface(iface);
    when(diskVmElementDao.get(new VmDeviceId(disk.getId(), vmId))).thenReturn(dve);
    return disk;
  }
コード例 #8
0
  @Mapping(
      from = DiskSnapshot.class,
      to = org.ovirt.engine.core.common.businessentities.storage.Disk.class)
  public static org.ovirt.engine.core.common.businessentities.storage.Disk map(
      DiskSnapshot diskSnapshot,
      org.ovirt.engine.core.common.businessentities.storage.Disk template) {
    DiskImage engineDisk = (DiskImage) DiskMapper.map(diskSnapshot, template);

    engineDisk.setImageId(GuidUtils.asGuid(diskSnapshot.getId()));

    if (diskSnapshot.isSetDisk()) {
      engineDisk.setId(GuidUtils.asGuid(diskSnapshot.getDisk().getId()));
    }

    return engineDisk;
  }
コード例 #9
0
  public static DiskImage cloneDiskImage(
      Guid storageDomainId,
      Guid newImageGroupId,
      Guid newImageGuid,
      DiskImage srcDiskImage,
      Guid diskProfileId,
      Guid snapshotId,
      DiskImage diskImageFromClient) {

    DiskImage clonedDiskImage = DiskImage.copyOf(srcDiskImage);
    clonedDiskImage.setImageId(newImageGuid);
    clonedDiskImage.setParentId(Guid.Empty);
    clonedDiskImage.setImageTemplateId(Guid.Empty);
    clonedDiskImage.setVmSnapshotId(snapshotId);
    clonedDiskImage.setId(newImageGroupId);
    clonedDiskImage.setLastModifiedDate(new Date());
    clonedDiskImage.setvolumeFormat(srcDiskImage.getVolumeFormat());
    clonedDiskImage.setVolumeType(srcDiskImage.getVolumeType());
    ArrayList<Guid> storageIds = new ArrayList<>();
    storageIds.add(storageDomainId);
    clonedDiskImage.setStorageIds(storageIds);
    clonedDiskImage.setDiskProfileId(diskProfileId);

    // If volume information was changed at client , use its volume information.
    // If volume information was not changed at client - use the volume information of the ancestral
    // image
    if (diskImageFromClient != null) {
      if (volumeInfoChanged(diskImageFromClient, srcDiskImage)) {
        changeVolumeInfo(clonedDiskImage, diskImageFromClient);
      } else {
        DiskImage ancestorDiskImage = getDiskImageDao().getAncestor(srcDiskImage.getImageId());
        changeVolumeInfo(clonedDiskImage, ancestorDiskImage);
      }
    } else {
      DiskImage ancestorDiskImage = getDiskImageDao().getAncestor(srcDiskImage.getImageId());
      changeVolumeInfo(clonedDiskImage, ancestorDiskImage);
    }

    return clonedDiskImage;
  }
コード例 #10
0
 private DiskImage createDiskImage(Guid diskImageId, Guid imageGroupId) {
   DiskImage diskImage = new DiskImage();
   diskImage.setImageId(diskImageId);
   diskImage.setId(imageGroupId);
   return diskImage;
 }