def add_repo(data, username="******", password="******"):
    config = _load_configuration(filename="/etc/rhui/rhui-tools.conf")
    prompt = Prompt()
    pulp_api = _pulp_api(config, prompt, username, password)
    cdn_api = _cdn_api(config)
    certificate_manager = _cert_manager(config, prompt)
    candidate_repo_manager = CandidateRepoManager(config, cdn_api, pulp_api, certificate_manager)
    candidate_repo_manager.translate_entitlements()
    repos, products = candidate_repo_manager.resolve_undeployed()

    undeployed_repos = {}
    for k,v in repos.items():
        key = v.real_url
        undeployed_repos[key] = v

    for product_name, repos in data.items():
        for repo_data in repos:
            repo_path = repo_data['real_url'].strip()
            repo_cds_enabled = repo_data['cds_enabled'].strip()
            repo_rhua_enabled = repo_data['rhua_enabled'].strip()
            matched_repo = search_path(undeployed_repos, repo_path)
            if matched_repo is not None:
                print "Found %s in undeployed_repos.\n" % repo_path
                if repo_rhua_enabled == '1':
                    print 'Attempting to add %s to RHUA\n' % (matched_repo.label)
                    cert = certificate_manager.cert_for_entitlement(matched_repo.entitlement)
                    result = pulp_api.create_redhat_repo(matched_repo, cert.cert_filename, config.get('rhui', 'repo_sync_frequency'))
                    print 'Adding %s to RHUA is %s\n' % (matched_repo.label, result)
            else:
                print 'Could not find %s in undeployed repo list...skipping.\n' % repo_path
                continue
Example #2
0
def add_repo(data, username="******", password="******"):
    config = _load_configuration(filename="/etc/rhui/rhui-tools.conf")
    prompt = Prompt()
    pulp_api = _pulp_api(config, prompt, username, password)
    cdn_api = _cdn_api(config)
    certificate_manager = _cert_manager(config, prompt)
    candidate_repo_manager = CandidateRepoManager(config, cdn_api, pulp_api, certificate_manager)
    candidate_repo_manager.translate_entitlements()
    repos, products = candidate_repo_manager.resolve_undeployed()
    cds_cluster = pulp_api.cds_clusters()["cluster1"]
    cds_hostnames = [c[1] for c in cds_cluster["cds"]]

    undeployed_repos = {}
    for k, v in repos.items():
        key = v.real_url
        undeployed_repos[key] = v

    for product_name, repos in data.items():
        for repo_data in repos:
            repo_path = repo_data["real_url"].strip()
            repo_cds_enabled = repo_data["cds_enabled"].strip()
            repo_rhua_enabled = repo_data["rhua_enabled"].strip()
            if undeployed_repos.has_key(repo_path):
                print "Found %s in undeployed_repos.\n" % repo_path
                if repo_rhua_enabled == "1":
                    matched_repo = undeployed_repos[repo_path]
                    cert = certificate_manager.cert_for_entitlement(matched_repo.entitlement)
                    result = pulp_api.create_redhat_repo(
                        config.get("redhat", "server_url"),
                        matched_repo,
                        cert.cert_filename,
                        config.get("rhui", "repo_sync_frequency"),
                    )
                    print "Adding %s to RHUA is %s\n" % (matched_repo.label, result)
                if repo_cds_enabled == "1":
                    matched_repo = undeployed_repos[repo_path]
                    print "Adding %s to CDS cluster\n" % matched_repo.label
                    for cds in cds_hostnames:
                        pulp_api.associate_repo(cds, matched_repo.label)
            else:
                print "Could not find %s in undeployed repo list...skipping.\n" % repo_path
                continue