def request_entitlement(self, identity, cert_length_in_min=None): """ Will request an entitlement certificate for all engineering_ids associated to this 'identity'. @param identity: the identity requesting an entitlement certificate @type identity: checkin_service.entitlement.models.ConsumerIdentity @param cert_length_in_min: optional param, if specified will ask candlepin for a cert that will live for this many minutes @type cert_length_in_min: int @return: Certificate and the time it took for entitlement server to process the call @rtype: str, int """ cp_config = config.get_entitlement_config_info() start_date=None end_date=None if cert_length_in_min: start_date = datetime.now(tz=pytz.utc) end_date = start_date + timedelta(minutes=cert_length_in_min) start_date = start_date.isoformat() end_date = end_date.isoformat() _LOG.info("Request entitlement certificate from external service: %s:%s%s for RHIC <%s> with products <%s>" %\ (cp_config["host"], cp_config["port"], cp_config["url"], identity.uuid, identity.engineering_ids)) start_time = time.time() cert_info = candlepin_client.get_entitlement( host=cp_config["host"], port=cp_config["port"], url=cp_config["url"], requested_products=identity.engineering_ids, identity=str(identity.uuid), username=cp_config["username"], password=cp_config["password"], start_date=start_date, end_date=end_date) end_time = time.time() return cert_info, end_time - start_time
for prov_prod in item["providedProducts"]: entry = dict() entry["id"] = prov_prod["productId"] entry["name"] = prov_prod["productName"] provided_products.append(entry) p.provided_products = provided_products pools.append(p) return pools if __name__ == "__main__": import datetime import pytz from django.conf import settings from splice.common import config config.init(settings.SPLICE_CONFIG_FILE) cfg = config.get_entitlement_config_info() start_date = datetime.datetime.now(tz=pytz.utc) end_date = (start_date + datetime.timedelta(minutes=15)) print "Start Date: %s" % (start_date.isoformat()) print "End Date: %s" % (end_date.isoformat()) certs = get_entitlement(host=cfg["host"], port=cfg["port"], url=cfg["url"], requested_products=["69","83"], identity="1234", username=cfg["username"], password=cfg["password"], start_date=start_date.isoformat(), end_date=end_date.isoformat()) print "---\n\n" print "certs = \n%s" % (certs)