public static VirtualNetworkFunctionRecord createVirtualNetworkFunctionRecord(
      VirtualNetworkFunctionDescriptor vnfd,
      String flavourKey,
      String nsr_id,
      Set<VirtualLinkRecord> vlr,
      Map<String, Collection<VimInstance>> vimInstances)
      throws NotFoundException, BadFormatException {
    VirtualNetworkFunctionRecord virtualNetworkFunctionRecord = new VirtualNetworkFunctionRecord();
    virtualNetworkFunctionRecord.setLifecycle_event_history(
        new LinkedList<HistoryLifecycleEvent>());
    virtualNetworkFunctionRecord.setParent_ns_id(nsr_id);
    virtualNetworkFunctionRecord.setName(vnfd.getName());
    virtualNetworkFunctionRecord.setType(vnfd.getType());
    Configuration configuration = new Configuration();
    if (vnfd.getConfigurations() != null) {
      configuration.setName(vnfd.getConfigurations().getName());
    } else configuration.setName(virtualNetworkFunctionRecord.getName());

    configuration.setConfigurationParameters(new HashSet<ConfigurationParameter>());
    if (vnfd.getConfigurations() != null) {
      for (ConfigurationParameter configurationParameter :
          vnfd.getConfigurations().getConfigurationParameters()) {
        ConfigurationParameter cp = new ConfigurationParameter();
        cp.setConfKey(configurationParameter.getConfKey());
        cp.setValue(configurationParameter.getValue());
        configuration.getConfigurationParameters().add(cp);
      }
    }
    virtualNetworkFunctionRecord.setConfigurations(configuration);
    virtualNetworkFunctionRecord.setCyclicDependency(vnfd.hasCyclicDependency());

    Configuration requires = new Configuration();
    requires.setName("requires");
    requires.setConfigurationParameters(new HashSet<ConfigurationParameter>());
    virtualNetworkFunctionRecord.setRequires(requires);

    if (vnfd.getRequires() != null) {
      for (String vnfdName : vnfd.getRequires().keySet()) {
        for (String key : vnfd.getRequires().get(vnfdName).getParameters()) {
          ConfigurationParameter configurationParameter = new ConfigurationParameter();
          log.debug("Adding " + key + " to requires");
          configurationParameter.setConfKey(key);
          virtualNetworkFunctionRecord
              .getRequires()
              .getConfigurationParameters()
              .add(configurationParameter);
        }
      }
    }

    Configuration provides = new Configuration();
    provides.setConfigurationParameters(new HashSet<ConfigurationParameter>());
    provides.setName("provides");
    virtualNetworkFunctionRecord.setProvides(provides);

    if (vnfd.getProvides() != null) {
      for (String key : vnfd.getProvides()) {
        ConfigurationParameter configurationParameter = new ConfigurationParameter();
        log.debug("Adding " + key + " to provides");
        configurationParameter.setConfKey(key);
        virtualNetworkFunctionRecord
            .getProvides()
            .getConfigurationParameters()
            .add(configurationParameter);
      }
    }

    //        if (vnfd.getVnfPackageLocation() != null) {
    //            VNFPackage vnfPackage = new VNFPackage();
    //            vnfPackage.setImageLink(vnfd.getVnfPackageLocation().getImageLink());
    //            vnfPackage.setScriptsLink(vnfd.getVnfPackageLocation().getScriptsLink());
    //            vnfPackage.setName(vnfd.getVnfPackageLocation().getName());
    //
    //            //TODO check for ordering
    //            vnfPackage.setScripts(new HashSet<Script>());
    //
    //            for (Script script : vnfd.getVnfPackageLocation().getScripts()) {
    //                Script s = new Script();
    //                s.setName(script.getName());
    //                s.setPayload(script.getPayload());
    //                vnfPackage.getScripts().add(s);
    //            }
    //
    //            vnfPackage.setImage(vnfd.getVnfPackageLocation().getImage());
    //        }
    virtualNetworkFunctionRecord.setPackageId(vnfd.getVnfPackageLocation());

    if (vnfd.getEndpoint() != null) {
      virtualNetworkFunctionRecord.setEndpoint(vnfd.getEndpoint());
    } else virtualNetworkFunctionRecord.setEndpoint(vnfd.getType());

    virtualNetworkFunctionRecord.setMonitoring_parameter(new HashSet<String>());
    virtualNetworkFunctionRecord.getMonitoring_parameter().addAll(vnfd.getMonitoring_parameter());
    virtualNetworkFunctionRecord.setVendor(vnfd.getVendor());
    virtualNetworkFunctionRecord.setAuto_scale_policy(new HashSet<AutoScalePolicy>());
    for (AutoScalePolicy autoScalePolicy : vnfd.getAuto_scale_policy()) {
      AutoScalePolicy newAutoScalePolicy = new AutoScalePolicy();
      newAutoScalePolicy.setName(autoScalePolicy.getName());
      newAutoScalePolicy.setType(autoScalePolicy.getType());
      newAutoScalePolicy.setCooldown(autoScalePolicy.getCooldown());
      newAutoScalePolicy.setPeriod(autoScalePolicy.getPeriod());
      newAutoScalePolicy.setComparisonOperator(autoScalePolicy.getComparisonOperator());
      newAutoScalePolicy.setThreshold(autoScalePolicy.getThreshold());
      newAutoScalePolicy.setMode(autoScalePolicy.getMode());
      newAutoScalePolicy.setActions(new HashSet<ScalingAction>());
      for (ScalingAction action : autoScalePolicy.getActions()) {
        ScalingAction newAction = new ScalingAction();
        newAction.setValue(action.getValue());
        newAction.setType(action.getType());
        if (action.getTarget() == null || action.getTarget().equals("")) {
          newAction.setTarget(vnfd.getType());
        } else {
          newAction.setTarget(action.getTarget());
        }
        newAutoScalePolicy.getActions().add(newAction);
      }
      newAutoScalePolicy.setAlarms(new HashSet<ScalingAlarm>());
      for (ScalingAlarm alarm : autoScalePolicy.getAlarms()) {
        ScalingAlarm newAlarm = new ScalingAlarm();
        newAlarm.setComparisonOperator(alarm.getComparisonOperator());
        newAlarm.setMetric(alarm.getMetric());
        newAlarm.setStatistic(alarm.getStatistic());
        newAlarm.setThreshold(alarm.getThreshold());
        newAlarm.setWeight(alarm.getWeight());
        newAutoScalePolicy.getAlarms().add(newAlarm);
      }
      virtualNetworkFunctionRecord.getAuto_scale_policy().add(newAutoScalePolicy);
    }

    // TODO mange the VirtualLinks and links...
    //
    // virtualNetworkFunctionRecord.setConnected_external_virtual_link(vnfd.getVirtual_link());

    virtualNetworkFunctionRecord.setVdu(new HashSet<VirtualDeploymentUnit>());
    for (VirtualDeploymentUnit virtualDeploymentUnit : vnfd.getVdu()) {
      VirtualDeploymentUnit vdu_new = new VirtualDeploymentUnit();
      vdu_new.setParent_vdu(virtualDeploymentUnit.getId());

      HashSet<VNFComponent> vnfComponents = new HashSet<>();
      for (VNFComponent component : virtualDeploymentUnit.getVnfc()) {
        VNFComponent component_new = new VNFComponent();
        HashSet<VNFDConnectionPoint> connectionPoints = new HashSet<>();
        for (VNFDConnectionPoint connectionPoint : component.getConnection_point()) {
          VNFDConnectionPoint connectionPoint_new = new VNFDConnectionPoint();
          connectionPoint_new.setVirtual_link_reference(
              connectionPoint.getVirtual_link_reference());
          connectionPoint_new.setType(connectionPoint.getType());
          connectionPoint_new.setFloatingIp(connectionPoint.getFloatingIp());
          connectionPoints.add(connectionPoint_new);
        }
        component_new.setConnection_point(connectionPoints);
        vnfComponents.add(component_new);
      }
      vdu_new.setVnfc(vnfComponents);
      vdu_new.setVnfc_instance(new HashSet<VNFCInstance>());
      HashSet<LifecycleEvent> lifecycleEvents = new HashSet<>();
      for (LifecycleEvent lifecycleEvent : virtualDeploymentUnit.getLifecycle_event()) {
        LifecycleEvent lifecycleEvent_new = new LifecycleEvent();
        lifecycleEvent_new.setEvent(lifecycleEvent.getEvent());
        lifecycleEvent_new.setLifecycle_events(lifecycleEvent.getLifecycle_events());
        lifecycleEvents.add(lifecycleEvent_new);
      }
      vdu_new.setLifecycle_event(lifecycleEvents);
      vdu_new.setVimInstanceName(virtualDeploymentUnit.getVimInstanceName());
      vdu_new.setHostname(virtualDeploymentUnit.getHostname());
      vdu_new.setHigh_availability(virtualDeploymentUnit.getHigh_availability());
      vdu_new.setComputation_requirement(virtualDeploymentUnit.getComputation_requirement());
      vdu_new.setScale_in_out(virtualDeploymentUnit.getScale_in_out());
      HashSet<String> monitoringParameters = new HashSet<>();
      monitoringParameters.addAll(virtualDeploymentUnit.getMonitoring_parameter());
      vdu_new.setMonitoring_parameter(monitoringParameters);
      vdu_new.setVdu_constraint(virtualDeploymentUnit.getVdu_constraint());

      // Set Faultmanagement policies
      Set<VRFaultManagementPolicy> vrFaultManagementPolicies = new HashSet<>();
      if (virtualDeploymentUnit.getFault_management_policy() != null) {
        log.debug(
            "Adding the fault management policies: "
                + virtualDeploymentUnit.getFault_management_policy());
        for (VRFaultManagementPolicy vrfmp : virtualDeploymentUnit.getFault_management_policy()) {
          vrFaultManagementPolicies.add(vrfmp);
        }
      }
      vdu_new.setFault_management_policy(vrFaultManagementPolicies);
      // Set Faultmanagement policies end

      HashSet<String> vmImages = new HashSet<>();
      vmImages.addAll(virtualDeploymentUnit.getVm_image());
      vdu_new.setVm_image(vmImages);

      vdu_new.setVirtual_network_bandwidth_resource(
          virtualDeploymentUnit.getVirtual_network_bandwidth_resource());
      vdu_new.setVirtual_memory_resource_element(
          virtualDeploymentUnit.getVirtual_memory_resource_element());
      virtualNetworkFunctionRecord.getVdu().add(vdu_new);
    }
    virtualNetworkFunctionRecord.setVersion(vnfd.getVersion());
    virtualNetworkFunctionRecord.setConnection_point(new HashSet<ConnectionPoint>());
    virtualNetworkFunctionRecord.getConnection_point().addAll(vnfd.getConnection_point());

    // TODO find a way to choose between deployment flavors and create the new one
    virtualNetworkFunctionRecord.setDeployment_flavour_key(flavourKey);
    for (VirtualDeploymentUnit virtualDeploymentUnit : vnfd.getVdu()) {
      for (VimInstance vi : vimInstances.get(virtualDeploymentUnit.getId())) {
        for (String name : virtualDeploymentUnit.getVimInstanceName()) {
          if (name.equals(vi.getName())) {
            if (!existsDeploymentFlavor(
                virtualNetworkFunctionRecord.getDeployment_flavour_key(), vi)) {
              throw new BadFormatException(
                  "no key "
                      + virtualNetworkFunctionRecord.getDeployment_flavour_key()
                      + " found in vim instance: "
                      + vi);
            }
          }
        }
      }
    }

    virtualNetworkFunctionRecord.setDescriptor_reference(vnfd.getId());
    virtualNetworkFunctionRecord.setLifecycle_event(new LinkedHashSet<LifecycleEvent>());
    HashSet<LifecycleEvent> lifecycleEvents = new HashSet<>();
    for (LifecycleEvent lifecycleEvent : vnfd.getLifecycle_event()) {
      LifecycleEvent lifecycleEvent_new = new LifecycleEvent();
      lifecycleEvent_new.setEvent(lifecycleEvent.getEvent());
      lifecycleEvent_new.setLifecycle_events(new ArrayList<String>());
      for (String event : lifecycleEvent.getLifecycle_events()) {
        lifecycleEvent_new.getLifecycle_events().add(event);
      }
      log.debug(
          "Found SCRIPTS for EVENT "
              + lifecycleEvent_new.getEvent()
              + ": "
              + lifecycleEvent_new.getLifecycle_events().size());
      lifecycleEvents.add(lifecycleEvent_new);
    }
    virtualNetworkFunctionRecord.setLifecycle_event(lifecycleEvents);
    virtualNetworkFunctionRecord.setVirtual_link(new HashSet<InternalVirtualLink>());
    HashSet<InternalVirtualLink> internalVirtualLinks = new HashSet<>();
    for (InternalVirtualLink internalVirtualLink : vnfd.getVirtual_link()) {
      InternalVirtualLink internalVirtualLink_new = new InternalVirtualLink();
      internalVirtualLink_new.setName(internalVirtualLink.getName());

      for (VirtualLinkRecord virtualLinkRecord : vlr) {
        if (virtualLinkRecord.getName().equals(internalVirtualLink_new.getName())) {
          internalVirtualLink_new.setExtId(virtualLinkRecord.getExtId());
        }
      }

      internalVirtualLink_new.setLeaf_requirement(internalVirtualLink.getLeaf_requirement());
      internalVirtualLink_new.setRoot_requirement(internalVirtualLink.getRoot_requirement());
      internalVirtualLink_new.setConnection_points_references(new HashSet<String>());
      for (String conn : internalVirtualLink.getConnection_points_references()) {
        internalVirtualLink_new.getConnection_points_references().add(conn);
      }
      internalVirtualLink_new.setQos(new HashSet<String>());
      for (String qos : internalVirtualLink.getQos()) {
        internalVirtualLink_new.getQos().add(qos);
      }
      internalVirtualLink_new.setTest_access(new HashSet<String>());
      for (String test : internalVirtualLink.getTest_access()) {
        internalVirtualLink_new.getTest_access().add(test);
      }
      internalVirtualLink_new.setConnectivity_type(internalVirtualLink.getConnectivity_type());
      internalVirtualLinks.add(internalVirtualLink_new);
    }
    virtualNetworkFunctionRecord.getVirtual_link().addAll(internalVirtualLinks);

    virtualNetworkFunctionRecord.setVnf_address(new HashSet<String>());
    virtualNetworkFunctionRecord.setStatus(Status.NULL);
    return virtualNetworkFunctionRecord;
  }
Exemple #2
0
  private NFVImage getImage(
      VNFPackage vnfPackage,
      VirtualNetworkFunctionDescriptor virtualNetworkFunctionDescriptor,
      String projectId)
      throws NotFoundException, PluginException, VimException, IncompatibleVNFPackage {

    Map<String, Object> metadata;
    NFVImage image = new NFVImage();
    Map<String, Object> imageDetails = new HashMap<>();
    List<String> vimInstances = new ArrayList<>();
    byte[] imageFile = null;

    YamlJsonParser yaml = new YamlJsonParser();
    metadata = yaml.parseMap(new String(this.vnfMetadata.toByteArray()));
    // Get configuration for NFVImage
    String[] REQUIRED_PACKAGE_KEYS = new String[] {"name", "image", "vim_types"};
    for (String requiredKey : REQUIRED_PACKAGE_KEYS) {
      if (!metadata.containsKey(requiredKey)) {
        throw new NotFoundException("Not found " + requiredKey + " of VNFPackage in Metadata.yaml");
      }
      if (metadata.get(requiredKey) == null) {
        throw new NullPointerException(
            "Not defined " + requiredKey + " of VNFPackage in Metadata.yaml");
      }
    }
    vnfPackage.setName((String) metadata.get("name"));
    if (metadata.containsKey("nfvo_version")) {
      String nfvo_version = (String) metadata.get("nfvo_version");
      String actualNfvoVersion = getNfvoVersion();
      if (nfvo_version.equals(actualNfvoVersion)) {
        vnfPackage.setNfvo_version(nfvo_version);
      } else {
        throw new IncompatibleVNFPackage(
            "The NFVO Version: "
                + nfvo_version
                + " specified in the Metadata"
                + " is not compatible with the this NFVOs version: "
                + actualNfvoVersion);
      }
    }
    if (metadata.containsKey("scripts-link"))
      vnfPackage.setScriptsLink((String) metadata.get("scripts-link"));
    if (metadata.containsKey("vim_types")) {
      List<String> vimTypes = (List<String>) metadata.get("vim_types");
      vnfPackage.setVimTypes(vimTypes);
    }
    if (metadata.containsKey("image")) {
      imageDetails = (Map<String, Object>) metadata.get("image");
      String[] REQUIRED_IMAGE_DETAILS = new String[] {"upload"};
      log.debug("image: " + imageDetails);
      for (String requiredKey : REQUIRED_IMAGE_DETAILS) {
        if (!imageDetails.containsKey(requiredKey)) {
          throw new NotFoundException(
              "Not found key: " + requiredKey + "of image in Metadata.yaml");
        }
        if (imageDetails.get(requiredKey) == null) {
          throw new NullPointerException(
              "Not defined value of key: " + requiredKey + " of image in Metadata.yaml");
        }
      }
      // If upload==true -> create a new Image
      if (imageDetails.get("upload").equals("true") || imageDetails.get("upload").equals("check")) {
        vnfPackage.setImageLink((String) imageDetails.get("link"));
        if (metadata.containsKey("image-config")) {
          log.debug("image-config: " + metadata.get("image-config"));
          Map<String, Object> imageConfig = (Map<String, Object>) metadata.get("image-config");
          // Check if all required keys are available
          String[] REQUIRED_IMAGE_CONFIG =
              new String[] {
                "name", "diskFormat", "containerFormat", "minCPU", "minDisk", "minRam", "isPublic"
              };
          for (String requiredKey : REQUIRED_IMAGE_CONFIG) {
            if (!imageConfig.containsKey(requiredKey)) {
              throw new NotFoundException(
                  "Not found key: " + requiredKey + " of image-config in Metadata.yaml");
            }
            if (imageConfig.get(requiredKey) == null) {
              throw new NullPointerException(
                  "Not defined value of key: " + requiredKey + " of image-config in Metadata.yaml");
            }
          }
          image.setName((String) imageConfig.get("name"));
          image.setDiskFormat(((String) imageConfig.get("diskFormat")).toUpperCase());
          image.setContainerFormat(((String) imageConfig.get("containerFormat")).toUpperCase());
          image.setMinCPU(Integer.toString((Integer) imageConfig.get("minCPU")));
          image.setMinDiskSpace((Integer) imageConfig.get("minDisk"));
          image.setMinRam((Integer) imageConfig.get("minRam"));
          image.setIsPublic(
              Boolean.parseBoolean(Integer.toString((Integer) imageConfig.get("minRam"))));
        } else {
          throw new NotFoundException(
              "The image-config is not defined. Please define it to upload a new image");
        }
      }
    } else {
      throw new NotFoundException(
          "The image details are not defined. Please define it to use the right image");
    }
    nsdUtils.fetchVimInstances(virtualNetworkFunctionDescriptor, projectId);
    if (imageDetails.get("upload").equals("true")) {
      log.debug("VNFPackageManagement: Uploading a new Image");
      if (vnfPackage.getImageLink() == null && imageFile == null) {
        throw new NotFoundException(
            "VNFPackageManagement: Neither the image link is defined nor the image file is available. Please define at least one if you want to upload a new image");
      } else if (vnfPackage.getImageLink() != null) {
        log.debug("VNFPackageManagement: Uploading a new Image by using the image link");
        for (VirtualDeploymentUnit vdu : virtualNetworkFunctionDescriptor.getVdu()) {
          if (vdu.getVimInstanceName() != null) {
            for (String vimName : vdu.getVimInstanceName()) {
              VimInstance vimInstance = null;

              for (VimInstance vi : vimInstanceRepository.findByProjectId(projectId)) {
                if (vimName.equals(vi.getName())) vimInstance = vi;
              }

              if (!vimInstances.contains(
                  vimInstance.getId())) { // check if we didn't already upload it
                Vim vim = vimBroker.getVim(vimInstance.getType());
                log.debug(
                    "VNFPackageManagement: Uploading a new Image to VimInstance "
                        + vimInstance.getName());
                image = vim.add(vimInstance, image, vnfPackage.getImageLink());
                if (vdu.getVm_image() == null) vdu.setVm_image(new HashSet<String>());
                vdu.getVm_image().add(image.getExtId());
                vimInstances.add(vimInstance.getId());
              }
            }
          }
        }
      } else if (imageFile != null) {
        log.debug("VNFPackageManagement: Uploading a new Image by using the image file");
        for (VirtualDeploymentUnit vdu : virtualNetworkFunctionDescriptor.getVdu()) {
          if (vdu.getVimInstanceName() != null) {
            for (String vimName : vdu.getVimInstanceName()) {
              VimInstance vimInstance = null;

              for (VimInstance vi : vimInstanceRepository.findByProjectId(projectId)) {
                if (vimName.equals(vi.getName())) vimInstance = vi;
              }

              if (!vimInstances.contains(
                  vimInstance.getId())) { // check if we didn't already upload it
                Vim vim = vimBroker.getVim(vimInstance.getType());
                log.debug(
                    "VNFPackageManagement: Uploading a new Image to VimInstance "
                        + vimInstance.getName());
                image = vim.add(vimInstance, image, imageFile);
                if (vdu.getVm_image() == null) vdu.setVm_image(new HashSet<String>());
                vdu.getVm_image().add(image.getExtId());
                vimInstances.add(vimInstance.getId());
              }
            }
          }
        }
      }
    } else {
      if (!imageDetails.containsKey("ids") && !imageDetails.containsKey("names")) {
        throw new NotFoundException(
            "VNFPackageManagement: Upload option 'false' or 'check' requires at least a list of ids or names to find "
                + " the right image.");
      }
      for (VirtualDeploymentUnit vdu : virtualNetworkFunctionDescriptor.getVdu()) {
        if (vdu.getVimInstanceName() != null) {
          if (vdu.getVimInstanceName().size() != 0) {
            for (String vimName : vdu.getVimInstanceName()) {

              VimInstance vimInstance = null;

              for (VimInstance vi : vimInstanceRepository.findByProjectId(projectId)) {
                if (vimName.equals(vi.getName())) {
                  vimInstance = vi;
                }
              }

              if (vimInstance == null) {
                throw new NotFoundException(
                    "Vim Instance with name "
                        + vimName
                        + " was not found in project: "
                        + projectId);
              }

              boolean found = false;
              // First, check for image ids
              if (imageDetails.containsKey("ids")) {
                for (NFVImage nfvImage : vimInstance.getImages()) {
                  if (((List) imageDetails.get("ids")).contains(nfvImage.getExtId())) {
                    if (!found) {
                      vdu.getVm_image().add(nfvImage.getExtId());
                      found = true;
                    } else {
                      throw new NotFoundException(
                          "VNFPackageManagement: Multiple images found with the defined list of IDs. Do not know "
                              + "which one to choose");
                    }
                  }
                }
              }

              // If no one was found, check for the names
              if (!found) {
                if (imageDetails.containsKey("names")) {
                  for (NFVImage nfvImage : vimInstance.getImages()) {
                    if (((List) imageDetails.get("names")).contains(nfvImage.getName())) {
                      if (!found) {
                        vdu.getVm_image().add(nfvImage.getExtId());
                        found = true;
                      } else {
                        throw new NotFoundException(
                            "VNFPackageManagement: Multiple images found with the same name. Do not know which one to"
                                + " choose. To avoid this, define the id");
                      }
                    }
                  }
                }
              }
              // if no image was found with the defined ids or names, the image doesn't exist
              if (!found) {
                if (imageDetails.get("upload").equals("check")) {
                  if (vnfPackage.getImageLink() == null && imageFile == null) {
                    throw new NotFoundException(
                        "VNFPackageManagement: Neither the image link is defined nor the image file is available. "
                            + "Please define at least one if you want to upload a new image");
                  } else if (vnfPackage.getImageLink() != null) {
                    log.debug(
                        "VNFPackageManagement: Uploading a new Image by using the image link");
                    if (!vimInstances.contains(
                        vimInstance.getId())) { // check if we didn't already upload it
                      Vim vim = vimBroker.getVim(vimInstance.getType());
                      log.debug(
                          "VNFPackageManagement: Uploading a new Image to VimInstance "
                              + vimInstance.getName());
                      image = vim.add(vimInstance, image, vnfPackage.getImageLink());
                      if (vdu.getVm_image() == null) {
                        vdu.setVm_image(new HashSet<String>());
                      }
                      vdu.getVm_image().add(image.getExtId());
                      vimInstances.add(vimInstance.getId());
                    }
                  } else if (imageFile != null) {
                    log.debug(
                        "VNFPackageManagement: Uploading a new Image by using the image file");
                    if (!vimInstances.contains(
                        vimInstance.getId())) { // check if we didn't already upload it
                      Vim vim = vimBroker.getVim(vimInstance.getType());
                      log.debug(
                          "VNFPackageManagement: Uploading a new Image to VimInstance "
                              + vimInstance.getName());
                      image = vim.add(vimInstance, image, imageFile);
                      if (vdu.getVm_image() == null) {
                        vdu.setVm_image(new HashSet<String>());
                      }
                      vimInstances.add(vimInstance.getId());
                      vdu.getVm_image().add(image.getExtId());
                    }
                  }
                } else {
                  throw new NotFoundException(
                      "VNFPackageManagement: Neither the defined ids nor the names were found. Use upload option "
                          + "'check' to get sure that the image will be available");
                }
              } else {
                log.debug("VNFPackageManagement: Found image");
              }
            }
          } else { // vimInstanceName is not defined, just put the name into the vdu
            List names = (List) imageDetails.get("names");
            log.debug("Adding names: " + names);
            vdu.getVm_image().addAll(names);
          }
        } else { // vimInstanceName is not defined, just put the name into the vdu
          List names = (List) imageDetails.get("names");
          log.debug("Adding names: " + names);
          vdu.getVm_image().addAll(names);
        }
      }
    }

    return image;
  }