Example #1
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());
 }
Example #2
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;
 }
  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);
  }
 @Override
 protected CobblerObject getCobblerObject(String cobblerId, User user) {
   return SystemRecord.lookupById(CobblerXMLRPCHelper.getConnection(user), cobblerId);
 }
  /** {@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;
  }
  /**
   * The first step in the wizard
   *
   * @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 runFirst(
      ActionMapping mapping,
      DynaActionForm form,
      RequestContext ctx,
      HttpServletResponse response,
      WizardStep step)
      throws Exception {
    log.debug("runFirst");
    Long sid = (Long) form.get(RequestContext.SID);
    User user = ctx.getCurrentUser();

    KickstartScheduleCommand cmd = getKickstartScheduleCommand(sid, user);

    Server system = SystemManager.lookupByIdAndUser(sid, user);
    if (system.isVirtualGuest()
        && VirtualInstanceFactory.getInstance()
            .getParaVirtType()
            .equals(system.getVirtualInstance().getType())) {
      ctx.getRequest().setAttribute(IS_VIRTUAL_GUEST, Boolean.TRUE.toString());

      ctx.getRequest().setAttribute(VIRT_HOST_IS_REGISTERED, Boolean.FALSE.toString());
      if (system.getVirtualInstance().getHostSystem() != null) {
        Long hostSid = system.getVirtualInstance().getHostSystem().getId();
        ctx.getRequest().setAttribute(VIRT_HOST_IS_REGISTERED, Boolean.TRUE.toString());
        ctx.getRequest().setAttribute(HOST_SID, hostSid);
      }
    } else {
      ctx.getRequest().setAttribute(IS_VIRTUAL_GUEST, Boolean.FALSE.toString());
    }

    addRequestAttributes(ctx, cmd, form);
    checkForKickstart(form, cmd, ctx);
    setupProxyInfo(ctx);
    if (StringUtils.isBlank(form.getString(PROXY_HOST))) {
      form.set(PROXY_HOST, "");
    }
    // create and prepopulate the date picker.
    getStrutsDelegate()
        .prepopulateDatePicker(ctx.getRequest(), form, "date", DatePicker.YEAR_RANGE_POSITIVE);

    SdcHelper.ssmCheck(ctx.getRequest(), system.getId(), user);
    Map params = new HashMap<String, String>();
    params.put(RequestContext.SID, sid);
    ListHelper helper = new ListHelper(new Profiles(), ctx.getRequest(), params);
    helper.execute();
    if (!StringUtils.isBlank(form.getString(RequestContext.COBBLER_ID))) {
      ListTagHelper.selectRadioValue(
          ListHelper.LIST, form.getString(RequestContext.COBBLER_ID), ctx.getRequest());
    } else if (system.getCobblerId() != null) {
      // if nothing is selected by the user yet, use the cobbler
      //  system record to pre-select something.
      SystemRecord rec =
          SystemRecord.lookupById(
              CobblerXMLRPCHelper.getConnection(ConfigDefaults.get().getCobblerAutomatedUser()),
              system.getCobblerId());
      if (rec != null) {
        ListTagHelper.selectRadioValue(ListHelper.LIST, rec.getProfile().getId(), ctx.getRequest());
      }
    }

    ActionForward retval = mapping.findForward("first");
    return retval;
  }