/**
   * 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);
  }
 /**
  * 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;
 }
  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);
  }