public static void fillImagesMapBasedOnTemplate(
      VmTemplate template,
      List<StorageDomain> domains,
      Map<Guid, DiskImage> diskInfoDestinationMap,
      Map<Guid, StorageDomain> destStorages) {
    Map<Guid, StorageDomain> storageDomainsMap = new HashMap<>();
    for (StorageDomain storageDomain : domains) {
      StorageDomainValidator validator = new StorageDomainValidator(storageDomain);
      if (validator.isDomainExistAndActive().isValid()
          && validator.domainIsValidDestination().isValid()) {
        storageDomainsMap.put(storageDomain.getId(), storageDomain);
      }
    }
    for (DiskImage image : template.getDiskTemplateMap().values()) {
      for (Guid storageId : image.getStorageIds()) {
        if (storageDomainsMap.containsKey(storageId)) {
          ArrayList<Guid> storageIds = new ArrayList<>();
          storageIds.add(storageId);
          image.setStorageIds(storageIds);
          diskInfoDestinationMap.put(image.getId(), image);
          break;
        }
      }
    }

    if (destStorages != null) {
      for (DiskImage diskImage : diskInfoDestinationMap.values()) {
        Guid storageDomainId = diskImage.getStorageIds().get(0);
        destStorages.put(storageDomainId, storageDomainsMap.get(storageDomainId));
      }
    }
  }
  @Override
  public void updateTabsData(ImportEntityData<VmTemplate> importEntityData) {
    VmTemplate vmTemplate = ((ImportTemplateData) importEntityData).getTemplate();

    templateGeneralModel.setEntity(vmTemplate);
    generalView.setMainTabSelectedItem(vmTemplate);

    disksTable.setRowData((List) Arrays.asList(vmTemplate.getDiskTemplateMap().values().toArray()));
    nicsTable.setRowData((List) Arrays.asList(vmTemplate.getInterfaces().toArray()));
  }
Beispiel #3
0
 /**
  * parses a given ovf to a VmTemplate, initialized with images and interfaces.
  *
  * @param ovf
  * @return VmTemplate that represents the given ovf data
  * @throws OvfReaderException
  */
 public VmTemplate readVmTemplateFromOvf(String ovf) throws OvfReaderException {
   ArrayList<DiskImage> diskImages = new ArrayList<DiskImage>();
   ArrayList<VmNetworkInterface> interfaces = new ArrayList<VmNetworkInterface>();
   VmTemplate template = new VmTemplate();
   ovfManager.ImportTemplate(ovf, template, diskImages, interfaces);
   template.setInterfaces(interfaces);
   // add disk map
   for (DiskImage disk : diskImages) {
     template.getDiskTemplateMap().put(disk.getId(), disk);
   }
   return template;
 }
Beispiel #4
0
 private VmTemplate createVmTemplate() {
   if (vmTemplate == null) {
     vmTemplate = new VmTemplate();
     vmTemplate.setStoragePoolId(STORAGE_POOL_ID);
     DiskImage image = createDiskImageTemplate();
     vmTemplate.getDiskTemplateMap().put(image.getImageId(), image);
     HashMap<Guid, DiskImage> diskImageMap = new HashMap<>();
     DiskImage diskImage = createDiskImage(REQUIRED_DISK_SIZE_GB);
     diskImageMap.put(diskImage.getId(), diskImage);
     vmTemplate.setDiskImageMap(diskImageMap);
   }
   return vmTemplate;
 }