Exemple #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);
    }
  }
Exemple #2
0
  private void setDefaultBootDevice() {
    // In the time of disk creation the VM ID is an empty Guid, this is changed to the real ID only
    // after the reading
    // of the OS properties which comes after the disks creation so the disk VM elements are set to
    // the wrong VM ID
    // this part sets them to the correct VM ID
    for (DiskImage disk : _images) {
      disk.getDiskVmElements()
          .stream()
          .forEach(dve -> dve.setId(new VmDeviceId(disk.getId(), vmBase.getId())));
      disk.setDiskVmElements(disk.getDiskVmElements());
    }

    boolean hasBootDevice =
        vmBase
            .getManagedDeviceMap()
            .values()
            .stream()
            .anyMatch(device -> device.getBootOrder() > 0);
    if (hasBootDevice) {
      return;
    }

    AtomicInteger order =
        new AtomicInteger(1); // regular non-final variable cannot be used in lambda expression
    _images
        .stream()
        .filter(d -> d.getDiskVmElementForVm(vmBase.getId()).isBoot())
        .map(image -> vmBase.getManagedDeviceMap().get(image.getId()))
        .filter(Objects::nonNull)
        .forEachOrdered(device -> device.setBootOrder(order.getAndIncrement()));
  }