Exemplo n.º 1
0
 /**
  * Get the default virt bridge for this KickstartData object.
  *
  * @return String virt bridge (xenbr0, virbr0)
  */
 public String getDefaultVirtBridge() {
   if (this.getKickstartDefaults()
       .getVirtualizationType()
       .getLabel()
       .equals(KickstartVirtualizationType.KVM_FULLYVIRT)) {
     return ConfigDefaults.get().getDefaultKVMVirtBridge();
   }
   return ConfigDefaults.get().getDefaultXenVirtBridge();
 }
  public void testPackageNamesByCapabilityAndChannel() throws Exception {
    Channel channel1 = ChannelFactoryTest.createTestChannel(user);
    addKickstartPackageToChannel(ConfigDefaults.get().getKickstartPackageName(), channel1);

    // Add a regular non-kickstart package as well:
    PackageManagerTest.addPackageToChannel("Another package", channel1);

    DataResult dr =
        PackageManager.packageNamesByCapabilityAndChannel(
            user.getOrg(), BaseTreeEditOperation.KICKSTART_CAPABILITY, channel1);
    assertNotNull(dr);
    assertEquals(1, dr.size());
    PackageListItem item = (PackageListItem) dr.get(0);
    assertEquals(ConfigDefaults.get().getKickstartPackageName(), item.getName());
  }
  /**
   * @return if we should force unentitlement if current members is greater then proposed
   *     entitlement count
   */
  private boolean forceUnentitlement(Long orgCur, Long orgProposedMax) {
    boolean retval = true;
    if (orgCur == null) {
      orgCur = 0L;
    }

    if (orgCur > orgProposedMax && !ConfigDefaults.get().forceUnentitlement()) {
      retval = false;
    }
    return retval;
  }
Exemplo n.º 4
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;
  }
  private void setupNetworkInfo(
      DynaActionForm form, RequestContext context, KickstartScheduleCommand cmd) {
    Server server = cmd.getServer();
    List<NetworkInterface> nics = getPublicNetworkInterfaces(server);

    if (nics.isEmpty()) {
      return;
    }

    context.getRequest().setAttribute(NETWORK_INTERFACES, nics);

    if (StringUtils.isBlank(form.getString(NETWORK_INTERFACE))) {
      String defaultInterface = ConfigDefaults.get().getDefaultKickstartNetworkInterface();
      for (NetworkInterface nic : nics) {
        if (nic.getName().equals(defaultInterface)) {
          form.set(NETWORK_INTERFACE, ConfigDefaults.get().getDefaultKickstartNetworkInterface());
        }
      }
      if (StringUtils.isBlank(form.getString(NETWORK_INTERFACE))) {
        form.set(NETWORK_INTERFACE, server.findPrimaryNetworkInterface().getName());
      }
    }
  }
 /**
  * Create ExtraOptions string
  *
  * @return extraOptions that will be appended to the Kickstart.
  */
 public String getExtraOptions() {
   StringBuilder retval = new StringBuilder();
   String kOptions = StringUtils.defaultString(kernelOptions);
   /**
    * Some examples: dhcp:eth0 , dhcp:eth2, static:10.1.4.75 static:146.108.30.184, static:auto,
    * static:eth0
    */
   if (!StringUtils.isBlank(networkInterface)) {
     if (!LINK_NETWORK_TYPE.equals(networkInterface)) {
       // Get rid of the dhcp:
       String params = " ksdevice=" + networkInterface;
       if (!kOptions.contains("ksdevice")) {
         retval.append(params);
       }
     }
   } else if (!kOptions.contains("ksdevice")) {
     retval.append("ksdevice=" + ConfigDefaults.get().getDefaultKickstartNetworkInterface());
   }
   retval.append(" ").append(kOptions);
   return retval.toString();
 }
  /** {@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;
  }
Exemplo n.º 9
0
 /**
  * Get the name of the kickstart package this KS will use.
  *
  * @return String kickstart package like auto-kickstart-ks-rhel-i386-as-4
  */
 public String getKickstartPackageName() {
   return ConfigDefaults.get().getKickstartPackageName();
 }