Ejemplo n.º 1
0
 private void postBindVirtLimit(
     PoolHelper postHelper,
     Entitlement entitlement,
     Pool pool,
     Consumer c,
     Map<String, String> attributes) {
   log.debug("Running virt_limit post-bind.");
   if (!c.isManifest() && (config.standalone() || attributes.containsKey("host_limited"))) {
     String productId = pool.getProductId();
     String virtLimit = attributes.get("virt_limit");
     if ("unlimited".equals(virtLimit)) {
       postHelper.createHostRestrictedPool(productId, pool, "unlimited");
     } else {
       int virtQuantity = Integer.parseInt(virtLimit) * entitlement.getQuantity();
       if (virtQuantity > 0) {
         postHelper.createHostRestrictedPool(productId, pool, String.valueOf(virtQuantity));
       }
     }
   } else {
     if (!config.standalone() && c.isManifest()) {
       String virtLimit = attributes.get("virt_limit");
       if (!"unlimited".equals(virtLimit)) {
         // if the bonus pool is not unlimited, then the bonus pool
         // quantity
         // needs to be adjusted based on the virt limit
         int virtQuantity = Integer.parseInt(virtLimit) * entitlement.getQuantity();
         if (virtQuantity > 0) {
           List<Pool> pools = postHelper.lookupBySubscriptionId(pool.getSubscriptionId());
           for (int idex = 0; idex < pools.size(); idex++) {
             Pool derivedPool = pools.get(idex);
             if (derivedPool.getAttributeValue("pool_derived") != null) {
               derivedPool = postHelper.updatePoolQuantity(derivedPool, -1 * virtQuantity);
             }
           }
         }
       } else {
         // if the bonus pool is unlimited, then the quantity needs
         // to go to 0
         // when the physical pool is exhausted completely by export.
         // A quantity of 0 will block future binds, whereas -1 does
         // not.
         if (pool.getQuantity().equals(pool.getExported())) {
           // getting all pools matching the sub id. Filtering out
           // the 'parent'.
           List<Pool> pools = postHelper.lookupBySubscriptionId(pool.getSubscriptionId());
           for (int idex = 0; idex < pools.size(); idex++) {
             Pool derivedPool = pools.get(idex);
             if (derivedPool.getAttributeValue("pool_derived") != null) {
               derivedPool = postHelper.setPoolQuantity(derivedPool, 0);
             }
           }
         }
       }
     }
   }
 }
Ejemplo n.º 2
0
  private void postBindUserLicense(
      PoolHelper postHelper, Pool pool, Consumer c, Map<String, String> attributes) {
    log.debug("Running user_license post-bind.");
    if (!c.isManifest()) {
      // Default to using the same product from the pool.
      String productId = pool.getProductId();

      // Check if the sub-pool should be for a different product:
      if (attributes.containsKey("user_license_product")) {
        productId = attributes.get("user_license_product");
      }

      // Create a sub-pool for this user
      postHelper.createUserRestrictedPool(productId, pool, attributes.get("user_license"));
    }
  }
Ejemplo n.º 3
0
 private void postUnbindVirtLimit(
     PoolHelper postHelper,
     Entitlement entitlement,
     Pool pool,
     Consumer c,
     Map<String, String> attributes) {
   log.debug("Running virt_limit post unbind.");
   if (!config.standalone() && c.isManifest()) {
     String virtLimit = attributes.get("virt_limit");
     if (!"unlimited".equals(virtLimit)) {
       // As we have unbound an entitlement from a physical pool that
       // was previously
       // exported, we need to add back the reduced bonus pool
       // quantity.
       int virtQuantity = Integer.parseInt(virtLimit) * entitlement.getQuantity();
       if (virtQuantity > 0) {
         List<Pool> pools = postHelper.lookupBySubscriptionId(pool.getSubscriptionId());
         for (int idex = 0; idex < pools.size(); idex++) {
           Pool derivedPool = pools.get(idex);
           if (derivedPool.getAttributeValue("pool_derived") != null) {
             postHelper.updatePoolQuantity(derivedPool, virtQuantity);
           }
         }
       }
     } else {
       // As we have unbound an entitlement from a physical pool that
       // was previously
       // exported, we need to set the unlimited bonus pool quantity to
       // -1.
       List<Pool> pools = postHelper.lookupBySubscriptionId(pool.getSubscriptionId());
       for (int idex = 0; idex < pools.size(); idex++) {
         Pool derivedPool = pools.get(idex);
         if (derivedPool.getAttributeValue("pool_derived") != null) {
           if (derivedPool.getQuantity() == 0) {
             postHelper.setPoolQuantity(derivedPool, -1);
           }
         }
       }
     }
   }
 }