/**
   * Get the id of the Package installed for this KS. Here we'll verify that the kickstart package
   * exists in the host server's tools channel. The host server will need it to perform necessary
   * actions on either itself or the target system (if different).
   *
   * @return Long id of Package used for this KS.
   */
  public ValidatorError validateKickstartPackage() {
    if (cobblerOnly) {
      return null;
    }

    Server hostServer = getHostServer();
    Set<Long> serverChannelIds = new HashSet<Long>();
    Iterator<Channel> i = hostServer.getChannels().iterator();
    while (i.hasNext()) {
      Channel c = i.next();
      serverChannelIds.add(c.getId());
    }

    // check for package among channels the server is subscribed to.
    // If one is found, return
    Map<String, Long> pkgToInstall = findKickstartPackageToInstall(hostServer, serverChannelIds);
    if (pkgToInstall != null) {
      this.packagesToInstall.add(pkgToInstall);
      log.debug("    packagesToInstall: " + packagesToInstall);
      return null;
    }

    // otherwise search in channels that can be subscribed.
    // If one is found, subscribe channel and return
    Set<Long> subscribableChannelIds =
        SystemManager.subscribableChannelIds(
            hostServer.getId(), this.user.getId(), hostServer.getBaseChannel().getId());
    pkgToInstall = findKickstartPackageToInstall(hostServer, subscribableChannelIds);

    if (pkgToInstall != null) {
      this.packagesToInstall.add(pkgToInstall);
      log.debug("    packagesToInstall: " + packagesToInstall);
      Long cid = pkgToInstall.get("channel_id");
      log.debug("    Subscribing to: " + cid);
      Channel c = ChannelFactory.lookupById(cid);
      try {
        SystemManager.subscribeServerToChannel(this.user, server, c);
        log.debug("    Subscribed: " + cid);
      } catch (PermissionException pe) {
        return new ValidatorError("kickstart.schedule.cantsubscribe");
      } catch (Exception e) {
        return new ValidatorError(
            "kickstart.schedule.cantsubscribe.channel", c.getName(), server.getName());
      }
      return null;
    }

    return new ValidatorError(
        "kickstart.schedule.nopackage", this.getKsdata().getChannel().getName());
  }