Exemplo n.º 1
0
  /** Adds the given vm metadata to the given map */
  private String buildMetadataDictionaryForVm(VM vm) {
    ArrayList<DiskImage> AllVmImages = new ArrayList<DiskImage>();
    List<DiskImage> filteredDisks =
        ImagesHandler.filterImageDisks(vm.getDiskList(), false, true, true);

    for (DiskImage diskImage : filteredDisks) {
      List<DiskImage> images = ImagesHandler.getAllImageSnapshots(diskImage.getImageId());
      AllVmImages.addAll(images);
    }

    return ovfManager.ExportVm(vm, AllVmImages, ClusterUtils.getCompatibilityVersion(vm));
  }
Exemplo n.º 2
0
  private void setupGlusterMock(boolean clusterHasServers, VDS upServer, boolean hasPeers)
      throws Exception {
    setupCommonMock(true);

    when(commandMock.createReturnValue()).thenCallRealMethod();
    when(commandMock.getReturnValue()).thenCallRealMethod();
    doCallRealMethod().when(commandMock).addCanDoActionMessage(any(EngineMessage.class));

    when(commandMock.getGlusterUtil()).thenReturn(glusterUtil);
    when(glusterUtil.getPeers(any(EngineSSHClient.class)))
        .thenReturn(hasPeers ? Collections.singleton(PEER_1) : Collections.<String>emptySet());

    when(commandMock.getGlusterDBUtils()).thenReturn(glusterDBUtils);

    when(clusterUtils.hasServers(any(Guid.class))).thenReturn(clusterHasServers);
    when(vdsDaoMock.getAllForVdsGroup(any(Guid.class)))
        .thenReturn(
            mockVdsInDb(clusterHasServers ? VDSStatus.Maintenance : VDSStatus.Initializing));
    when(clusterUtils.getUpServer(any(Guid.class))).thenReturn(upServer);

    // commandMock.log = log;
  }
  /**
   * Prepare a single {@link org.ovirt.engine.core.common.businessentities.Snapshot} object
   * representing a snapshot of a given VM without the given disk, substituting a new disk in its
   * place if a new disk is provided to the method.
   */
  public static Snapshot prepareSnapshotConfigWithAlternateImage(
      Snapshot snapshot, Guid oldImageId, DiskImage newImage) {
    try {
      OvfManager ovfManager = new OvfManager();
      String snapConfig = snapshot.getVmConfiguration();

      if (snapshot.isVmConfigurationAvailable() && snapConfig != null) {
        VM vmSnapshot = new VM();
        ArrayList<DiskImage> snapshotImages = new ArrayList<>();

        ovfManager.importVm(snapConfig, vmSnapshot, snapshotImages, new ArrayList<>());

        // Remove the image from the disk list
        Iterator<DiskImage> diskIter = snapshotImages.iterator();
        while (diskIter.hasNext()) {
          DiskImage imageInList = diskIter.next();
          if (imageInList.getImageId().equals(oldImageId)) {
            log.debug(
                "Recreating vmSnapshot '{}' without the image '{}'", snapshot.getId(), oldImageId);
            diskIter.remove();
            break;
          }
        }

        if (newImage != null) {
          log.debug(
              "Adding image '{}' to vmSnapshot '{}'", newImage.getImageId(), snapshot.getId());
          snapshotImages.add(newImage);
        }

        String newOvf =
            ovfManager.exportVm(
                vmSnapshot, snapshotImages, ClusterUtils.getCompatibilityVersion(vmSnapshot));
        snapshot.setVmConfiguration(newOvf);
      }
    } catch (OvfReaderException e) {
      log.error("Can't remove image '{}' from snapshot '{}'", oldImageId, snapshot.getId());
    }
    return snapshot;
  }
Exemplo n.º 4
0
 protected ClusterUtils getClusterUtils() {
   return ClusterUtils.getInstance();
 }