def enrich_mpu(self, marketing_product_usage): dt = transforms.DataTransforms() def _mpu_enrich_worker(mpu): mpu.update({'product_info': dt.transform_entitlements_to_rcs(self.katello_client.get_entitlements(mpu['instance_identifier']))}) return mpu enriched_mpu = utils.queued_work(_mpu_enrich_worker, marketing_product_usage, self.num_threads) return enriched_mpu
def get_consumers(self, owner=None, with_details=True): # TODO: this has a lot of logic and could be refactored into katello_sync # the API wants "orgId" but they mean "label" org_ids = map(lambda x: x['label'], self.orgapi.organizations()) # some katello-specific query params for pagination query_params = {'paged': 'true', 'sort_by': 'name', 'offset': 0, 'sort_order': 'ASC'} consumer_list = [] # TODO: this could be done in parallel for org_id in org_ids: # we need to grab the system list in sets of 25 so we don't time out on especially large queries query_params['offset'] = 0 while True: _LOG.debug("retrieving systems for org %s, offset %s" % (org_id, query_params['offset'])) system_subset = self.systemapi.systems_by_org(orgId=org_id, query=query_params)['systems'] _LOG.debug("found %s systems" % len(system_subset)) consumer_list.append(system_subset) # if we didn't get 25 results, stop here if len(system_subset) < 25: break query_params['offset'] += 25 # flatten the list consumer_list = list(itertools.chain.from_iterable(consumer_list)) # return what we have, if we don't need the detailed list if not with_details: return consumer_list consumer_uuids = map(lambda x: x['uuid'], consumer_list) def _get_full_consumer_worker(uuid): full_consumer = self._get_consumer(uuid) full_consumer['entitlement_status'] = self.get_subscription_status(uuid) return full_consumer full_consumers_list = utils.queued_work(_get_full_consumer_worker, consumer_uuids, CONFIG.getint('main', 'num_threads')) if len(consumer_uuids) != len(full_consumers_list): raise Exception("unable to fetch all consumer records (expected %s, found %s), see log for more detail" % (len(consumer_uuids), len(full_consumers_list))) return full_consumers_list
def enrich_mpu(self, marketing_product_usage): enriched_mpu = utils.queued_work(self._mpu_enrich_worker, marketing_product_usage, self.num_threads) return enriched_mpu
def upload_to_katello(self, consumers): """ Uploads consumer data to katello """ utils.queued_work(self._upload_consumer_to_katello, consumers, self.num_threads)