/**
   * Create a one time activation key for use with a kickstart
   *
   * @param creator of the key
   * @param ksdata associated with the key
   * @param server being kickstarted (can be null)
   * @param session associated with the kickstart (NOT NULL)
   * @param note to add to key
   * @param usageLimit to apply to the key. null for unlimited.
   * @return ActivationKey that has been saved to the DB.
   */
  public static ActivationKey createKickstartActivationKey(
      User creator,
      KickstartData ksdata,
      Server server,
      KickstartSession session,
      Long usageLimit,
      String note) {

    // Now create ActivationKey
    ActivationKey key =
        ActivationKeyManager.getInstance().createNewReActivationKey(creator, server, note, session);
    key.addEntitlement(ServerConstants.getServerGroupTypeProvisioningEntitled());
    key.setDeployConfigs(false);
    key.setUsageLimit(usageLimit);
    if (KickstartVirtualizationType.paraHost()
        .equals(ksdata.getKickstartDefaults().getVirtualizationType())) {
      // we'll have to setup the key for virt
      key.addEntitlement(ServerConstants.getServerGroupTypeVirtualizationEntitled());
    }
    ActivationKeyFactory.save(key);

    // Add child channels to the key
    if (ksdata.getChildChannels() != null && ksdata.getChildChannels().size() > 0) {
      Iterator i = ksdata.getChildChannels().iterator();
      log.debug("Add the child Channels");
      while (i.hasNext()) {
        key.addChannel((Channel) i.next());
      }
    }

    log.debug("** Saving new token");
    ActivationKeyFactory.save(key);
    log.debug("** Saved new token: " + key.getId());
    return key;
  }
  public void testAddGetKeys() throws Exception {

    ActivationKey k = createTestActivationKey(user);

    for (int i = 0; i < 5; i++) {
      Channel c = ChannelFactoryTest.createTestChannel(user);
      k.addChannel(c);
    }
    assertTrue(k.getChannels().size() == 5);
  }