Exemple #1
0
 /**
  * Sets the registration type
  *
  * @param type the refgistration type
  * @param user the user needed to load the profile form cobbler
  */
 public void setRegistrationType(RegistrationType type, User user) {
   Profile prof = getCobblerObject(user);
   Map<String, Object> meta = prof.getKsMeta();
   meta.put(RegistrationType.COBBLER_VAR, type.getType());
   prof.setKsMeta(meta);
   prof.save();
 }
Exemple #2
0
  /**
   * Gets the Registration Type (i.e. the code that determines if the ks script needs to generate a
   * reactivation key or not)
   *
   * @param user the user object needed to load the profile from cobbler
   * @return the registration type
   */
  public RegistrationType getRegistrationType(User user) {
    Profile prof = getCobblerObject(null);
    if (prof == null) {
      return RegistrationType.getDefault();
    }

    return RegistrationType.find((String) prof.getKsMeta().get(RegistrationType.COBBLER_VAR));
  }
Exemple #3
0
  /** @return the cobblerName */
  public String getCobblerFileName() {
    if (getCobblerId() != null) {
      Profile prof =
          Profile.lookupById(
              CobblerXMLRPCHelper.getConnection(ConfigDefaults.get().getCobblerAutomatedUser()),
              getCobblerId());
      if (prof != null && !StringUtils.isBlank(prof.getKickstart())) {
        return prof.getKickstart();
      }
    }

    return null;
  }
  /**
   * Setup the system for provisioning with cobbler.
   *
   * @param mapping ActionMapping for struts
   * @param form DynaActionForm representing the form
   * @param ctx RequestContext request context
   * @param response HttpServletResponse response object
   * @param step WizardStep what step are we on?
   * @return ActionForward struts action forward
   * @throws Exception if something goes amiss
   */
  public ActionForward runFourth(
      ActionMapping mapping,
      DynaActionForm form,
      RequestContext ctx,
      HttpServletResponse response,
      WizardStep step)
      throws Exception {

    log.debug("runFourth");
    if (!validateFirstSelections(form, ctx)) {
      return runFirst(mapping, form, ctx, response, step);
    }
    Long sid = (Long) form.get(RequestContext.SID);
    String cobblerId = form.getString(RequestContext.COBBLER_ID);

    log.debug("runFourth.cobblerId: " + cobblerId);

    User user = ctx.getCurrentUser();
    Server server = SystemManager.lookupByIdAndUser(sid, user);

    Map params = new HashMap();
    params.put(RequestContext.SID, sid);

    log.debug("Creating cobbler system record");
    org.cobbler.Profile profile =
        org.cobbler.Profile.lookupById(CobblerXMLRPCHelper.getConnection(user), cobblerId);

    KickstartData data =
        KickstartFactory.lookupKickstartDataByCobblerIdAndOrg(user.getOrg(), profile.getUid());

    if (showDiskWarning(data, form)) {
      form.set(NEXT_ACTION, "fourth");
      return mapping.findForward("fifth");
    }

    CobblerSystemCreateCommand cmd =
        new CobblerSystemCreateCommand(server, profile.getName(), data);
    cmd.store();
    log.debug("cobbler system record created.");
    String[] args = new String[2];
    args[0] = server.getName();
    args[1] = profile.getName();
    createMessage(ctx.getRequest(), "kickstart.schedule.cobblercreate", args);
    return getStrutsDelegate().forwardParams(mapping.findForward("cobbler-success"), params);
  }
  /**
   * Parses the kernel options or Post kernel options from the given set of params This is a handy
   * method used in both SSM and SDC KS scheduling.
   *
   * @param customOptions the kickstartScheduleWizardForm that holds the form fields.
   * @param paramsType either KERNEL_PARAMS_CUSTOM _DISTRO or _PROFILE
   * @param cobblerId the cobbler profile id
   * @param isPost true if caller is interested in getting the post kernel options and not the pre.
   * @param user the user doing the request
   * @return the kernel options selected by the user.
   */
  public static String parseKernelOptions(
      String customOptions, String paramsType, String cobblerId, boolean isPost, User user) {

    CobblerConnection con = CobblerXMLRPCHelper.getConnection(user);
    if (KERNEL_PARAMS_CUSTOM.equals(paramsType)) {
      return customOptions;
    }
    org.cobbler.Profile profile = org.cobbler.Profile.lookupById(con, cobblerId);
    CobblerObject ret = profile;

    if (KERNEL_PARAMS_DISTRO.equals(paramsType)) {
      ret = profile.getDistro();
    }
    if (!isPost) {
      return ret.getKernelOptionsString();
    }
    return ret.getKernelPostOptionsString();
  }
 /**
  * Returns the kickstart schedule command
  *
  * @param form the dyna aciton form
  * @param ctx the request context
  * @param scheduleTime the schedule time
  * @param host the host url.
  * @return the Ks schedule command
  */
 protected KickstartScheduleCommand getScheduleCommand(
     DynaActionForm form, RequestContext ctx, Date scheduleTime, String host) {
   String cobblerId = form.getString(RequestContext.COBBLER_ID);
   User user = ctx.getCurrentUser();
   KickstartScheduleCommand cmd;
   KickstartData data =
       KickstartFactory.lookupKickstartDataByCobblerIdAndOrg(user.getOrg(), cobblerId);
   if (data != null) {
     cmd =
         new KickstartScheduleCommand(
             (Long) form.get(RequestContext.SID), data, ctx.getCurrentUser(), scheduleTime, host);
   } else {
     org.cobbler.Profile profile =
         org.cobbler.Profile.lookupById(CobblerXMLRPCHelper.getConnection(user), cobblerId);
     cmd =
         KickstartScheduleCommand.createCobblerScheduleCommand(
             (Long) form.get(RequestContext.SID), profile.getName(), user, scheduleTime, host);
   }
   return cmd;
 }
Exemple #7
0
 /**
  * Returns the cobbler object associated to to this profile.
  *
  * @param user the user object needed for connection, enter null if you want to use the automated
  *     connection as provided by taskomatic.
  * @return the Profile associated to this ks data
  */
 public Profile getCobblerObject(User user) {
   if (StringUtils.isBlank(getCobblerId())) {
     return null;
   }
   CobblerConnection con;
   if (user == null) {
     con = CobblerXMLRPCHelper.getAutomatedConnection();
   } else {
     con = CobblerXMLRPCHelper.getConnection(user);
   }
   return Profile.lookupById(con, getCobblerId());
 }
  protected void addRequestAttributes(
      RequestContext ctx, KickstartScheduleCommand cmd, DynaActionForm form) {
    ctx.getRequest().setAttribute(RequestContext.SYSTEM, cmd.getServer());
    ctx.getRequest().setAttribute(RequestContext.KICKSTART, cmd.getKsdata());
    if (cmd.getKsdata() != null) {
      ctx.getRequest().setAttribute("profile", cmd.getKsdata());
      ctx.getRequest().setAttribute("distro", cmd.getKsdata().getTree());
      CobblerConnection con = CobblerXMLRPCHelper.getConnection(ctx.getCurrentUser());

      Distro distro = Distro.lookupById(con, cmd.getKsdata().getTree().getCobblerId());

      ctx.getRequest().setAttribute("distro_kernel_params", distro.getKernelOptionsString());
      ctx.getRequest()
          .setAttribute("distro_post_kernel_params", distro.getKernelPostOptionsString());

      org.cobbler.Profile profile =
          org.cobbler.Profile.lookupById(con, cmd.getKsdata().getCobblerId());
      ctx.getRequest().setAttribute("profile_kernel_params", profile.getKernelOptionsString());
      ctx.getRequest()
          .setAttribute("profile_post_kernel_params", profile.getKernelPostOptionsString());
      if (cmd.getServer().getCobblerId() != null) {
        SystemRecord rec = SystemRecord.lookupById(con, cmd.getServer().getCobblerId());
        if (rec != null && profile.getName().equals(rec.getProfile().getName())) {
          if (StringUtils.isBlank(form.getString(KERNEL_PARAMS_TYPE))) {
            form.set(KERNEL_PARAMS_TYPE, KERNEL_PARAMS_CUSTOM);
            form.set(KERNEL_PARAMS, rec.getKernelOptionsString());
          }
          if (StringUtils.isBlank(form.getString(POST_KERNEL_PARAMS_TYPE))) {
            form.set(POST_KERNEL_PARAMS_TYPE, KERNEL_PARAMS_CUSTOM);
            form.set(POST_KERNEL_PARAMS, rec.getKernelPostOptionsString());
          }
        }
      }
    }
    setupNetworkInfo(form, ctx, cmd);
    setupBondInfo(form, ctx, cmd);
  }
  /** {@inheritDoc} */
  public ValidatorError store() {

    ValidatorError e = this.doValidation();
    if (e != null) {
      return e;
    }

    Server hostServer = getHostServer();
    log.debug("** Server we are operating on: " + hostServer);

    // rhn-kickstart-virtualization conflicts with this package, so we have to
    //  remove it
    List<Map<String, Long>> installed =
        SystemManager.listInstalledPackage(PACKAGE_TO_REMOVE, hostServer);
    Action removal = null;
    if (!installed.isEmpty()) {
      removal = ActionManager.schedulePackageRemoval(user, hostServer, installed, scheduleDate);
    }

    // Install packages on the host server.
    log.debug("** Creating packageAction");
    Action packageAction =
        ActionManager.schedulePackageInstall(
            this.user, hostServer, this.packagesToInstall, scheduleDate);
    packageAction.setPrerequisite(removal);
    log.debug("** Created packageAction ? " + packageAction.getId());

    log.debug("** Cancelling existing sessions.");
    cancelExistingSessions();

    // Make sure we fail all existing sessions for this server since
    // we are scheduling a new one
    if (!cobblerOnly) {
      kickstartSession = this.setupKickstartSession(packageAction);
      storeActivationKeyInfo();
    }
    Action kickstartAction = this.scheduleKickstartAction(packageAction);
    ActionFactory.save(packageAction);

    scheduleRebootAction(kickstartAction);

    String host = this.getKickstartServerName();
    if (!StringUtils.isEmpty(this.getProxyHost())) {
      host = this.getProxyHost();
    }

    CobblerSystemCreateCommand cmd = null;
    if (!cobblerOnly) {
      // Setup Cobbler system profile
      KickstartUrlHelper uhelper = new KickstartUrlHelper(ksdata);
      String tokenList;

      if (ksdata.getRegistrationType(null).equals(RegistrationType.REACTIVATION)) {
        tokenList = KickstartFormatter.generateActivationKeyString(ksdata, kickstartSession);
      } else {
        // RegistrationType.DELETION && RegistrationType.NONE
        CobblerConnection connection =
            CobblerXMLRPCHelper.getConnection(ConfigDefaults.get().getCobblerAutomatedUser());
        tokenList =
            org.cobbler.Profile.lookupById(connection, ksdata.getCobblerId())
                .getRedHatManagementKey();
      }

      cmd =
          getCobblerSystemCreateCommand(
              user,
              server,
              ksdata,
              uhelper.getKickstartMediaPath(kickstartSession, scheduleDate),
              tokenList);
      cmd.setKernelOptions(getExtraOptions());
    } else {
      cmd = new CobblerSystemCreateCommand(user, server, cobblerProfileLabel);
      cmd.setKernelOptions(kernelOptions);
    }
    cmd.setKickstartHost(host);
    cmd.setPostKernelOptions(postKernelOptions);
    cmd.setScheduledAction(kickstartAction);
    cmd.setNetworkInfo(
        isDhcp, networkInterface, this.useIpv6Gateway(), ksdata.getInstallType().getLabel());
    cmd.setBridgeInfo(
        createBond,
        bondInterface,
        bondSlaveInterfaces,
        bondOptions,
        isBondDhcp,
        bondAddress,
        bondNetmask,
        bondGateway);
    ValidatorError cobblerError = cmd.store();
    if (cobblerError != null) {
      return cobblerError;
    }
    SystemRecord rec =
        SystemRecord.lookupById(
            CobblerXMLRPCHelper.getConnection(this.getUser().getLogin()),
            this.getServer().getCobblerId());

    // This is a really really crappy way of doing this, but i don't want to restructure
    //      the actions too much at this point :/
    //      We only want to do this for the non-guest action
    if (kickstartAction instanceof KickstartAction) {
      ((KickstartAction) kickstartAction)
          .getKickstartActionDetails()
          .setCobblerSystemName(rec.getName());
    }

    ActionFactory.save(kickstartAction);
    log.debug("** Created ksaction: " + kickstartAction.getId());

    this.scheduledAction = kickstartAction;

    log.debug("** Done scheduling kickstart session");
    return null;
  }