Esempio n. 1
0
  private void prepDropdowns(RequestContext ctx) {
    User loggedInUser = ctx.getCurrentUser();
    // populate parent base channels
    List<Map<String, String>> baseChannels = new ArrayList<Map<String, String>>();
    List<Channel> bases = ChannelManager.findAllBaseChannelsForOrg(loggedInUser);

    LocalizationService ls = LocalizationService.getInstance();
    addOption(baseChannels, ls.getMessage("generic.jsp.none"), "");
    for (Channel c : bases) {
      addOption(baseChannels, c.getName(), c.getId().toString());
    }
    ctx.getRequest().setAttribute("parentChannels", baseChannels);

    Map<Long, String> parentChannelArches = new HashMap<Long, String>();
    for (Channel c : bases) {
      parentChannelArches.put(c.getId(), c.getChannelArch().getLabel());
    }
    ctx.getRequest().setAttribute("parentChannelArches", parentChannelArches);

    Map<Long, String> parentChannelChecksums = new HashMap<Long, String>();
    for (Channel c : bases) {
      parentChannelChecksums.put(c.getId(), c.getChecksumTypeLabel());
    }
    ctx.getRequest().setAttribute("parentChannelChecksums", parentChannelChecksums);

    // base channel arches
    List<Map<String, String>> channelArches = new ArrayList<Map<String, String>>();
    List<ChannelArch> arches = ChannelManager.getChannelArchitectures();
    for (ChannelArch arch : arches) {
      addOption(channelArches, arch.getName(), arch.getLabel());
    }
    ctx.getRequest().setAttribute("channelArches", channelArches);
    // set the list of yum supported checksums
    List<Map<String, String>> checksums = new ArrayList<Map<String, String>>();
    addOption(checksums, ls.getMessage("generic.jsp.none"), "");
    for (ChecksumType chType : ChannelFactory.listYumSupportedChecksums()) {
      addOption(checksums, chType.getLabel(), chType.getLabel());
    }
    ctx.getRequest().setAttribute("checksums", checksums);
  }
  /**
   * Looks up a list of applicable kickstart profiles. The list is generated based on matches
   * between the server's base channel arch and the profile's channel arch
   *
   * @return DataResult, else null if the server does not exist or does not have a base channel
   *     assigned
   */
  public DataResult<KickstartDto> getKickstartProfiles() {
    log.debug("getKickstartProfiles()");
    DataResult<KickstartDto> retval = new DataResult<KickstartDto>(Collections.EMPTY_LIST);

    // Profiles are associated with the host; the target system might not be created
    // yet.  Also, the host will be the one performing the kickstart, so the profile
    // is relative to that system.

    Server hostServer = getHostServer();
    if (hostServer != null) {
      log.debug("getKickstartProfiles(): hostServer isnt null");
      Channel baseChannel = hostServer.getBaseChannel();
      if (baseChannel != null) {
        log.debug("getKickstartProfiles(): hostServer.baseChannel isnt null");
        ChannelArch arch = baseChannel.getChannelArch();
        SelectMode mode = getMode();
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("org_id", this.user.getOrg().getId());
        params.put("prim_arch_id", arch.getId());
        if (arch.getName().equals("x86_64")) {
          log.debug("    Adding IA-32 to search list.");
          ChannelArch ia32arch = ChannelFactory.lookupArchByName("IA-32");
          params.put("sec_arch_id", ia32arch.getId());
        } else if (arch.getName().equals("IA-32")
            && (hostServer.getServerArch().getName().equals(ServerConstants.getArchI686().getName())
                || hostServer
                    .getServerArch()
                    .getName()
                    .equals(ServerConstants.getArchATHLON().getName()))) {
          log.debug("    Adding x86_64 to search list.");
          ChannelArch x86Arch = ChannelFactory.lookupArchByName("x86_64");
          params.put("sec_arch_id", x86Arch.getId());
        } else if (arch.getName().equals("PPC")) {
          log.debug("    Adding ppc64le to search list.");
          ChannelArch ppc64le = ChannelFactory.lookupArchByName("PPC64LE");
          params.put("sec_arch_id", ppc64le.getId());
        } else if (arch.getName().equals("PPC64LE")) {
          log.debug("    Adding ppc to search list.");
          ChannelArch ppc = ChannelFactory.lookupArchByName("PPC");
          params.put("sec_arch_id", ppc.getId());
        } else {
          params.put("sec_arch_id", arch.getId());
        }
        retval = mode.execute(params);
        if (log.isDebugEnabled()) {
          log.debug("got back from DB: " + retval);
        }
        KickstartLister.getInstance().setKickstartUrls(retval, user);
        KickstartLister.getInstance().pruneInvalid(user, retval);
        retval.setTotalSize(retval.size());
      }
    }

    List<CobblerProfileDto> dtos = KickstartLister.getInstance().listCobblerProfiles(user);
    if (log.isDebugEnabled()) {
      log.debug("got back from cobbler: " + dtos);
    }
    retval.setTotalSize(retval.getTotalSize() + dtos.size());
    retval.addAll(dtos);

    return retval;
  }