def get_product_ids(subscribedchannels): """ For the subscribed base and child channels look up product ids """ global CERT_DIR if CERT_DIR is None: CERT_DIR = CertificateDirectory(CERT_DIR_PATH) mapping_file = os.path.join( os.path.join(constants.CHANNEL_PRODUCT_ID_MAPPING_DIR, utils.get_release()), constants.CHANNEL_PRODUCT_ID_MAPPING_FILE) channel_mappings = utils.read_mapping_file(mapping_file) product_ids = [] for channel in subscribedchannels.split(';'): origin_channel = channel if origin_channel in channel_mappings: cert = channel_mappings[origin_channel] product_ids.append(cert.split('-')[-1].split('.')[0]) _LOG.debug("mapped subscribed channels %s to installed products %s" % (subscribedchannels, product_ids)) # reformat to how candlepin expects the product id list installed_products = [] for p in product_ids: product_cert = CERT_DIR.findByProduct(str(p)) installed_products.append({"productId": product_cert.products[0].id, "productName": product_cert.products[0].name}) return installed_products
"net.interface.eth0.mac_address" : "52:54:00:CD:2F:D6", "network.hostname" : "localhost.localdomain", "system.certificate_version" : "3.0", "uname.machine" : "x86_64", "uname.release" : "2.6.18-348.el5", "uname.sysname" : "Linux", "uname.version" : "#1 SMP Wed Nov 28 21:22:00 EST 2012", "virt.host_type" : "kvm", "virt.is_guest" : "true", "virt.uuid" : "6882755d-2297-5f2d-219b-f33e59df959d" } print "initializing connection" cc = CandlepinConnection() cc.cp.ping() cert_dir = CertificateDirectory("/usr/share/rhsm/product/RHEL-6/") product_cert = cert_dir.findByProduct("69") installed_products = [{"productId": product_cert.products[0].id, "productName": product_cert.products[0].name}] print "installed products: %s" % installed_products uuid = cc.createConsumer("foobar", facts, installed_products) print "updating" product_cert = cert_dir.findByProduct("83") installed_products = [{"productId": product_cert.products[0].id, "productName": product_cert.products[0].name}] cc.updateConsumer(uuid, facts, installed_products) print "done"