def getAvailableEntitlements(cpserver, consumer_uuid, facts, get_all=False, active_on=None):
    """
    Returns a list of entitlement pools from the server.

    Facts will be updated if appropriate before making the request, to ensure
    the rules on the server will pass if appropriate.

    The 'all' setting can be used to return all pools, even if the rules do
    not pass. (i.e. show pools that are incompatible for your hardware)
    """
    columns = [
        "id",
        "quantity",
        "consumed",
        "endDate",
        "productName",
        "providedProducts",
        "productId",
        "attributes",
        "multi-entitlement",
        "service_level",
        "service_type",
    ]

    dlist = list_pools(cpserver, consumer_uuid, facts, get_all, active_on)

    for pool in dlist:
        pool_wrapper = PoolWrapper(pool)
        if allows_multi_entitlement(pool):
            pool["multi-entitlement"] = "Yes"
        else:
            pool["multi-entitlement"] = "No"

        support_attrs = pool_wrapper.get_product_attributes("support_level", "support_type")
        pool["service_level"] = support_attrs["support_level"]
        pool["service_type"] = support_attrs["support_type"]

    data = [_sub_dict(pool, columns) for pool in dlist]
    for d in data:
        if int(d["quantity"]) < 0:
            d["quantity"] = "unlimited"
        else:
            d["quantity"] = str(int(d["quantity"]) - int(d["consumed"]))

        d["endDate"] = formatDate(parseDate(d["endDate"]))
        del d["consumed"]

    return data
Exemple #2
0
def getAvailableEntitlements(cpserver,
                             consumer_uuid,
                             facts,
                             get_all=False,
                             active_on=None):
    """
    Returns a list of entitlement pools from the server.

    Facts will be updated if appropriate before making the request, to ensure
    the rules on the server will pass if appropriate.

    The 'all' setting can be used to return all pools, even if the rules do
    not pass. (i.e. show pools that are incompatible for your hardware)
    """
    columns = [
        'id', 'quantity', 'consumed', 'endDate', 'productName',
        'providedProducts', 'productId', 'attributes', 'multi-entitlement',
        'service_level', 'service_type'
    ]

    dlist = list_pools(cpserver, consumer_uuid, facts, get_all, active_on)

    for pool in dlist:
        pool_wrapper = PoolWrapper(pool)
        if allows_multi_entitlement(pool):
            pool['multi-entitlement'] = "Yes"
        else:
            pool['multi-entitlement'] = "No"

        support_attrs = pool_wrapper.get_product_attributes(
            "support_level", "support_type")
        pool['service_level'] = support_attrs['support_level']
        pool['service_type'] = support_attrs['support_type']

    data = [_sub_dict(pool, columns) for pool in dlist]
    for d in data:
        if int(d['quantity']) < 0:
            d['quantity'] = 'unlimited'
        else:
            d['quantity'] = str(int(d['quantity']) - int(d['consumed']))

        d['endDate'] = formatDate(parseDate(d['endDate']))
        del d['consumed']

    return data
    def add_pool(self, pool, default_quantity_value):
        self.total_contracts += 1
        self.total_contracts_label.set_text(str(self.total_contracts))
        self.subscription_name_label.set_text(pool['productName'])

        # Use unlimited for -1 quanities
        quantity = pool['quantity']
        if quantity < 0:
            quantity = _('unlimited')
            quantity_available = -1
        else:
            quantity_available = int(pool['quantity']) - int(pool['consumed'])

        row = [pool['contractNumber'],
                "%s / %s" % (pool['consumed'], quantity),
               managerlib.parseDate(pool['startDate']),
               managerlib.parseDate(pool['endDate']),
               default_quantity_value,
               pool['productName'], pool,
               PoolWrapper(pool).is_virt_only(),
               allows_multi_entitlement(pool),
               quantity_available]
        self.model.append(row)
Exemple #4
0
    def test_is_case_insensitive(self):
        pool = self._create_pool_data_with_multi_entitlement_attribute("YeS")
        self.assertTrue(allows_multi_entitlement(pool))

        pool = self._create_pool_data_with_multi_entitlement_attribute("nO")
        self.assertFalse(allows_multi_entitlement(pool))
Exemple #5
0
 def test_does_not_allow_when_any_other_value(self):
     pool = self._create_pool_data_with_multi_entitlement_attribute(
         "not_a_good_value")
     self.assertFalse(allows_multi_entitlement(pool))
Exemple #6
0
 def test_does_not_allow_when_empty_string(self):
     pool = self._create_pool_data_with_multi_entitlement_attribute("")
     self.assertFalse(allows_multi_entitlement(pool))
Exemple #7
0
 def test_does_not_allow_when_not_set(self):
     pool = {"productAttributes": []}
     self.assertFalse(allows_multi_entitlement(pool))
Exemple #8
0
 def test_allows_when_1(self):
     pool = self._create_pool_data_with_multi_entitlement_attribute("1")
     self.assertTrue(allows_multi_entitlement(pool))
    def test_is_case_insensitive(self):
        pool = self._create_pool_data_with_multi_entitlement_attribute("YeS")
        self.assertTrue(allows_multi_entitlement(pool))

        pool = self._create_pool_data_with_multi_entitlement_attribute("nO")
        self.assertFalse(allows_multi_entitlement(pool))
 def test_does_not_allow_when_any_other_value(self):
     pool = self._create_pool_data_with_multi_entitlement_attribute("not_a_good_value")
     self.assertFalse(allows_multi_entitlement(pool))
 def test_does_not_allow_when_empty_string(self):
     pool = self._create_pool_data_with_multi_entitlement_attribute("")
     self.assertFalse(allows_multi_entitlement(pool))
 def test_does_not_allow_when_not_set(self):
     pool = {"productAttributes": []}
     self.assertFalse(allows_multi_entitlement(pool))
 def test_allows_when_1(self):
     pool = self._create_pool_data_with_multi_entitlement_attribute("1")
     self.assertTrue(allows_multi_entitlement(pool))