Beispiel #1
0
  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);
    }
  }
  private void canDoActionMakeDiskBootableOnOtherVm(boolean boot) {
    UpdateVmDiskParameters parameters = createParameters();
    Disk newDisk = parameters.getDiskInfo();
    newDisk.setBoot(true);

    Guid otherVmId = Guid.newGuid();
    VM otherVm = new VM();
    otherVm.setId(otherVmId);

    DiskImage otherDisk = new DiskImage();
    otherDisk.setId(Guid.newGuid());
    otherDisk.setActive(true);
    otherDisk.setBoot(boot);
    if (boot) {
      when(diskDao.getVmBootActiveDisk(otherVmId)).thenReturn(otherDisk);
    }
    when(diskDao.get(diskImageGuid)).thenReturn(createDiskImage());

    initializeCommand(parameters, Arrays.asList(createVmStatusDown(), otherVm));

    mockInterfaceList();

    // The command should only succeed if there is no other bootable disk
    assertEquals(!boot, command.canDoAction());
  }
 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;
 }
 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;
 }
Beispiel #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;
 }
 /** The following method will create a new DiskImage */
 private DiskImage createDiskImage() {
   DiskImage disk = new DiskImage();
   disk.setId(diskImageGuid);
   disk.setSize(100000L);
   disk.setDiskInterface(DiskInterface.VirtIO);
   disk.setStorageIds(new ArrayList<>(Collections.singleton(sdId)));
   disk.setStoragePoolId(spId);
   disk.setDescription(RandomUtils.instance().nextString(10));
   return disk;
 }
Beispiel #7
0
  @Before
  public void setUp() {
    vmId = Guid.newGuid();
    diskId = Guid.newGuid();
    poolId = Guid.newGuid();
    storageDomainId = Guid.newGuid();
    groupId = Guid.newGuid();
    vdsId = Guid.newGuid();

    disk = new DiskImage();
    disk.setId(diskId);
    disk.setVmEntityType(VmEntityType.VM);
    disk.setImageStatus(ImageStatus.OK);
    disk.setStorageIds(new ArrayList<>(Arrays.asList(storageDomainId)));

    vm = new VM();
    vm.setId(vmId);
    vm.setStatus(VMStatus.Down);
    vm.setStoragePoolId(poolId);
    vm.setClusterId(groupId);

    VmDeviceId vmDeviceId = new VmDeviceId(diskId, vmId);
    vmDevice = new VmDevice();
    vmDevice.setId(vmDeviceId);

    cluster = new Cluster();
    cluster.setId(groupId);

    vds = new VDS();
    vds.setId(vdsId);

    storagePool = new StoragePool();
    storagePool.setStatus(StoragePoolStatus.Up);

    storageDomain = new StorageDomain();
    storageDomain.setStorageType(StorageType.ISCSI);

    when(vmDao.getVmsListForDisk(diskId, Boolean.FALSE)).thenReturn(Collections.singletonList(vm));
    when(vmDeviceDao.get(vmDeviceId)).thenReturn(vmDevice);
    when(vdsDao.getAllForClusterWithStatus(groupId, VDSStatus.Up))
        .thenReturn(Collections.singletonList(vds));
    when(spDao.get(poolId)).thenReturn(storagePool);
    when(clusterDao.get(groupId)).thenReturn(cluster);
    when(storageDomainStaticDao.get(storageDomainId))
        .thenReturn(storageDomain.getStorageStaticData());

    cmd = spy(new GetDiskAlignmentCommand<>(new GetDiskAlignmentParameters(diskId), null));

    doReturn(disk).when(cmd).getDisk();
    doReturn(vdsDao).when(cmd).getVdsDao();
    doReturn(vmDao).when(cmd).getVmDao();
    doReturn(spDao).when(cmd).getStoragePoolDao();
    doReturn(clusterDao).when(cmd).getClusterDao();
    doReturn(storageDomainStaticDao).when(cmd).getStorageDomainStaticDao();
  }
Beispiel #8
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;
 }
  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;
  }
  @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;
  }
  @Override
  protected void readDiskImageItem(XmlNode node) {
    final Guid guid = new Guid(node.SelectSingleNode("rasd:InstanceId", _xmlNS).innerText);

    DiskImage image =
        LinqUtils.firstOrNull(
            _images,
            new Predicate<DiskImage>() {
              @Override
              public boolean eval(DiskImage diskImage) {
                return diskImage.getImageId().equals(guid);
              }
            });
    image.setId(
        OvfParser.GetImageGrupIdFromImageFile(
            node.SelectSingleNode("rasd:HostResource", _xmlNS).innerText));
    if (StringUtils.isNotEmpty(node.SelectSingleNode("rasd:Parent", _xmlNS).innerText)) {
      image.setParentId(new Guid(node.SelectSingleNode("rasd:Parent", _xmlNS).innerText));
    }
    if (StringUtils.isNotEmpty(node.SelectSingleNode("rasd:Template", _xmlNS).innerText)) {
      image.setImageTemplateId(new Guid(node.SelectSingleNode("rasd:Template", _xmlNS).innerText));
    }
    image.setAppList(node.SelectSingleNode("rasd:ApplicationList", _xmlNS).innerText);
    if (StringUtils.isNotEmpty(node.SelectSingleNode("rasd:StorageId", _xmlNS).innerText)) {
      image.setStorageIds(
          new ArrayList<Guid>(
              Arrays.asList(new Guid(node.SelectSingleNode("rasd:StorageId", _xmlNS).innerText))));
    }
    if (StringUtils.isNotEmpty(node.SelectSingleNode("rasd:StoragePoolId", _xmlNS).innerText)) {
      image.setStoragePoolId(
          new Guid(node.SelectSingleNode("rasd:StoragePoolId", _xmlNS).innerText));
    }
    final Date creationDate =
        OvfParser.UtcDateStringToLocaDate(
            node.SelectSingleNode("rasd:CreationDate", _xmlNS).innerText);
    if (creationDate != null) {
      image.setCreationDate(creationDate);
    }
    final Date lastModified =
        OvfParser.UtcDateStringToLocaDate(
            node.SelectSingleNode("rasd:LastModified", _xmlNS).innerText);
    if (lastModified != null) {
      image.setLastModified(lastModified);
    }
    readManagedVmDevice(node, image.getId());
  }
  @Test
  public void getOtherVmDisks() {
    UpdateVmDiskParameters parameters = createParameters();

    DiskImage otherDisk = new DiskImage();
    otherDisk.setId(Guid.newGuid());
    otherDisk.setActive(true);
    when(diskDao.getAllForVm(vmId))
        .thenReturn(new LinkedList<>(Arrays.asList(parameters.getDiskInfo(), otherDisk)));
    when(diskDao.get(diskImageGuid)).thenReturn(createDiskImage());
    initializeCommand(parameters);

    VM vm = createVmStatusDown();
    mockCtorRelatedDaoCalls(Collections.singletonList(vm));
    List<Disk> otherDisks = command.getOtherVmDisks(vm.getId());
    assertEquals("Wrong number of other disks", 1, otherDisks.size());
    assertFalse("Wrong other disk", otherDisks.contains(parameters.getDiskInfo()));
  }
  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;
  }
 private DiskImage createDiskImage(Guid diskImageId, Guid imageGroupId) {
   DiskImage diskImage = new DiskImage();
   diskImage.setImageId(diskImageId);
   diskImage.setId(imageGroupId);
   return diskImage;
 }