Example #1
0
    def parse_base_config(pulp2importer, pulp2_config):
        """
        Parse and return basic config.
        """
        base_config = {}
        proxy_url, credentials, host = None, None, None
        pulp2_proxy_host = pulp2_config.get("proxy_host")
        pulp2_proxy_port = pulp2_config.get("proxy_port")
        pulp2_proxy_username = pulp2_config.get("proxy_username")
        pulp2_proxy_password = pulp2_config.get("proxy_password")
        if pulp2_proxy_username:
            credentials = "{}:{}".format(pulp2_proxy_username,
                                         pulp2_proxy_password)
        if pulp2_proxy_host:
            parsed_url = urlparse(pulp2_proxy_host)
            scheme = parsed_url.scheme
            host = parsed_url.hostname
            if pulp2_proxy_port:
                host += ":{}".format(pulp2_proxy_port)
            if credentials:
                proxy_url = "{}://{}@{}".format(scheme, credentials, host)
            else:
                proxy_url = "{}://{}".format(scheme, host)
        remote_name = "{}-{}".format(pulp2importer.pulp2_object_id,
                                     pulp2importer.pulp2_repo_id)
        base_config["proxy_url"] = proxy_url
        username = pulp2_config.get("basic_auth_username")
        password = pulp2_config.get("basic_auth_password")
        feed = pulp2_config.get("feed", "")  # what to do if there is no feed?
        if feed and "@" in feed:
            # move out the credentials from the feed
            parsed_feed = urlparse(feed)
            if not username:
                username = parsed_feed.username
            if not password:
                password = parsed_feed.password
            _, netloc_split = parsed_feed.netloc.rsplit("@", maxsplit=1)
            feed = urlunparse(parsed_feed._replace(netloc=netloc_split))
        base_config["url"] = feed
        base_config["username"] = username
        base_config["password"] = password

        base_config["ca_cert"] = pulp2_config.get("ssl_ca_cert")
        base_config["client_cert"] = pulp2_config.get("ssl_client_cert")
        base_config["client_key"] = pulp2_config.get("ssl_client_key")
        # True by default?
        base_config["tls_validation"] = pulp2_config.get(
            "ssl_validation", True)
        base_config["download_concurrency"] = pulp2_config.get(
            "max_downloads") or 20
        policy = PULP_2TO3_POLICIES.get(
            pulp2_config.get("download_policy", "immediate"))
        base_config["policy"] = policy
        return base_config, remote_name
    def parse_base_config(pulp2importer, pulp2_config):
        """
        Parse and return basic config.
        """
        base_config = {}
        proxy_url, credentials, host = None, None, None
        pulp2_proxy_host = pulp2_config.get('proxy_host')
        pulp2_proxy_port = pulp2_config.get('proxy_port')
        pulp2_proxy_username = pulp2_config.get('proxy_username')
        pulp2_proxy_password = pulp2_config.get('proxy_password')
        if pulp2_proxy_username:
            credentials = '{}:{}'.format(pulp2_proxy_username,
                                         pulp2_proxy_password)
        if pulp2_proxy_host:
            parsed_url = urlparse(pulp2_proxy_host)
            scheme = parsed_url.scheme
            host = parsed_url.hostname
            if pulp2_proxy_port:
                host += ':{}'.format(pulp2_proxy_port)
            if credentials:
                proxy_url = '{}://{}@{}'.format(scheme, credentials, host)
            else:
                proxy_url = '{}://{}'.format(scheme, host)
        remote_name = '{}-{}'.format(pulp2importer.pulp2_object_id,
                                     pulp2importer.pulp2_repo_id)
        base_config['proxy_url'] = proxy_url
        username = pulp2_config.get('basic_auth_username')
        password = pulp2_config.get('basic_auth_password')
        feed = pulp2_config.get('feed', '')  # what to do if there is no feed?
        if feed and '@' in feed:
            # move out the credentials from the feed
            parsed_feed = urlparse(feed)
            if not username:
                username = parsed_feed.username
            if not password:
                password = parsed_feed.password
            _, netloc_split = parsed_feed.netloc.rsplit('@', maxsplit=1)
            feed = urlunparse(parsed_feed._replace(netloc=netloc_split))
        base_config['url'] = feed
        base_config['username'] = username
        base_config['password'] = password

        base_config['ca_cert'] = pulp2_config.get('ssl_ca_cert')
        base_config['client_cert'] = pulp2_config.get('ssl_client_cert')
        base_config['client_key'] = pulp2_config.get('ssl_client_key')
        # True by default?
        base_config['tls_validation'] = pulp2_config.get(
            'ssl_validation', True)
        base_config['download_concurrency'] = pulp2_config.get(
            'max_downloads') or 20
        policy = PULP_2TO3_POLICIES.get(
            pulp2_config.get('download_policy', 'immediate'))
        base_config['policy'] = policy
        return base_config, remote_name
Example #3
0
    async def migrate_to_pulp3(cls, pulp2importer):
        """
        Migrate importer to Pulp 3.

        Args:
            pulp2importer(Pulp2Importer): Pre-migrated pulp2 importer to migrate

        Return:
            remote(FileRemote): FileRemote in Pulp3
            created(bool): True if Remote has just been created; False if Remote is an existing one
        """
        pulp2_config = pulp2importer.pulp2_config
        proxy_url, credentials, host = None, None, None
        pulp2_proxy_host = pulp2_config.get('proxy_host')
        pulp2_proxy_port = pulp2_config.get('proxy_port')
        pulp2_proxy_username = pulp2_config.get('proxy_username')
        pulp2_proxy_password = pulp2_config.get('proxy_password')
        if pulp2_proxy_username:
            credentials = '{}:{}'.format(pulp2_proxy_username,
                                         pulp2_proxy_password)
        if pulp2_proxy_host:
            parsed_url = urlparse(pulp2_proxy_host)
            scheme = parsed_url.scheme
            host = parsed_url.hostname
            if pulp2_proxy_port:
                host += ':{}'.format(pulp2_proxy_port)
            if credentials:
                proxy_url = '{}://{}@{}'.format(scheme, credentials, host)
            else:
                proxy_url = '{}://{}'.format(scheme, host)

        # remote name in Pulp 3 is limited to 255 characters
        remote_name = '{}-{}'.format(
            pulp2importer.pulp2_object_id,
            pulp2importer.pulp2_repository.pulp2_repo_id)[:255]
        return FileRemote.objects.update_or_create(
            name=remote_name,
            url=pulp2_config.get('feed'),  # what to do if there is no feed?
            ssl_ca_certificate=pulp2_config.get('ssl_ca_cert'),
            ssl_client_certificate=pulp2_config.get('ssl_client_cert'),
            ssl_client_key=pulp2_config.get('ssl_client_key'),
            ssl_validation=pulp2_config.get('ssl_validation',
                                            True),  # True by default?
            proxy_url=proxy_url,
            username=pulp2_config.get('basic_auth_username'),
            password=pulp2_config.get('basic_auth_password'),
            download_concurrency=pulp2_config.get('max_downloads') or 20,
            policy=PULP_2TO3_POLICIES.get(
                pulp2_config.get('download_policy', 'immediate')),
        )
Example #4
0
 def parse_base_config(pulp2importer, pulp2_config):
     """
     Parse and return basic config.
     """
     base_config = {}
     proxy_url, credentials, host = None, None, None
     pulp2_proxy_host = pulp2_config.get('proxy_host')
     pulp2_proxy_port = pulp2_config.get('proxy_port')
     pulp2_proxy_username = pulp2_config.get('proxy_username')
     pulp2_proxy_password = pulp2_config.get('proxy_password')
     if pulp2_proxy_username:
         credentials = '{}:{}'.format(pulp2_proxy_username,
                                      pulp2_proxy_password)
     if pulp2_proxy_host:
         parsed_url = urlparse(pulp2_proxy_host)
         scheme = parsed_url.scheme
         host = parsed_url.hostname
         if pulp2_proxy_port:
             host += ':{}'.format(pulp2_proxy_port)
         if credentials:
             proxy_url = '{}://{}@{}'.format(scheme, credentials, host)
         else:
             proxy_url = '{}://{}'.format(scheme, host)
     remote_name = '{}-{}'.format(
         pulp2importer.pulp2_object_id,
         pulp2importer.pulp2_repository.pulp2_repo_id)
     base_config['proxy_url'] = proxy_url
     base_config['name'] = remote_name
     base_config['url'] = pulp2_config.get(
         'feed', '')  # what to do if there is no feed?
     base_config['ca_cert'] = pulp2_config.get('ssl_ca_cert')
     base_config['client_cert'] = pulp2_config.get('ssl_client_cert')
     base_config['client_key'] = pulp2_config.get('ssl_client_key')
     # True by default?
     base_config['tls_validation'] = pulp2_config.get(
         'ssl_validation', True)
     base_config['username'] = pulp2_config.get('basic_auth_username')
     base_config['password'] = pulp2_config.get('basic_auth_password')
     base_config['download_concurrency'] = pulp2_config.get(
         'max_downloads') or 20
     policy = PULP_2TO3_POLICIES.get(
         pulp2_config.get('download_policy', 'immediate'))
     base_config['policy'] = policy
     return base_config