How to use the pulp.server.config.config.get function in PuLP

To help you get started, we’ve selected a few PuLP examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pulp / pulpcore / server / pulp / server / db / connection.py View on Github external
def initialize(name=None, seeds=None, max_pool_size=None, replica_set=None, max_timeout=32):
    """
    Initialize the connection pool and top-level database for pulp.

    :param max_timeout: the maximum number of seconds to wait between
                        connection retries
    :type  max_timeout: int
    """
    global _CONNECTION, _DATABASE

    try:
        connection_kwargs = {}

        if name is None:
            name = config.config.get('database', 'name')

        if seeds is None:
            seeds = config.config.get('database', 'seeds')

        if seeds != '':
            first_seed = seeds.split(',')[0]
            seed = first_seed.strip().split(':')
            if len(seed) == 2:
                connection_kwargs.update({'host': seed[0], 'port': int(seed[1])})
            else:
                connection_kwargs.update({'host': seed[0]})

        if max_pool_size is None:
            # we may want to make this configurable, but then again, we may not
            max_pool_size = _DEFAULT_MAX_POOL_SIZE
        connection_kwargs['max_pool_size'] = max_pool_size
github pulp / pulp / nodes / common / pulp_node / conduit.py View on Github external
    @staticmethod
    def associated_unit(typedef, unit, metadata):
        unit_key = {}
        for key in typedef['unit_key']:
            unit_key[key] = metadata.pop(key, None)
        metadata.pop('_id', None)
        storage_dir = pulp_conf.get('server', 'storage_dir')
        storage_path = metadata.pop('_storage_path', None)
        last_updated = metadata.pop('_last_updated', 0.0)
        if storage_path:
            relative_path = storage_path[len(storage_dir):].lstrip('/')
        else:
            relative_path = None
        return dict(
            unit_id=unit['unit_id'],
            type_id=unit['unit_type_id'],
            unit_key=unit_key,
            storage_path=storage_path,
            relative_path=relative_path,
            last_updated=last_updated,
            metadata=metadata)
github pulp / pulpcore / platform / src / pulp / server / async.py View on Github external
def __call__(self, *args, **kwargs):
        """
        On invocation, perform the async RMI to the agent.
        @param args: Invocation args.
        @type args: list
        @param kwargs: keyword invocation args.
        @type kwargs: dict
        @return: Whatever is returned by the async RMI.
        @rtype: object
        """
        url = config.config.get('messaging', 'url')
        watchdog = WatchDog(url=url)
        agent = Agent(
            self.id,
            url=url,
            secret=self.secret,
            any=self.taskid,
            ctag=self.CTAG,
            watchdog=watchdog,
            **self.options)
        classobj = getattr(agent, self.classname)()
        if isinstance(self.cntr, tuple):
            classobj(*self.cntr[0], **self.cntr[1])
        method = getattr(classobj, self.name)
        return method(*args, **kwargs)
github pulp / pulpcore / server / pulp / server / controllers / content.py View on Github external
def _get_streamer_url(catalog_entry):
    """
    Translate a content unit into a URL where the content unit is cached.

    :param catalog_entry: The catalog entry to get the URL for.
    :type  catalog_entry: pulp.server.db.model.LazyCatalogEntry

    :return: The signed streamer URL which corresponds to the content unit.
    :rtype:  str
    """
    scheme = 'https'
    host = pulp_conf.get('lazy', 'redirect_host')
    port = pulp_conf.get('lazy', 'redirect_port')
    path_prefix = pulp_conf.get('lazy', 'redirect_path')
    unsigned_url = ContentView.urljoin(scheme, host, port, path_prefix,
                                       catalog_entry.path, '')
    # Sign the URL for a year to avoid the URL expiring before the task completes
    return str(URL(unsigned_url).sign(URL_SIGNING_KEY, expiration=31536000))
github pulp / pulp / src / pulp / server / api / repo_sync.py View on Github external
if len(pieces) < 2:
            raise PulpException('Feed format for RHN type must be /. Feed: %s',
                                repo_source['url'])

        host = 'http://' + pieces[0]
        channel = pieces[1]

        log.info('Synchronizing from RHN. Host [%s], Channel [%s]' % (host, channel))

        # Create and configure the grinder hook to RHN
        s = RHNSync()
        s.setURL(host)
        s.setParallel(config.config.getint('rhn', 'threads'))
        s.setFetchAllPackages(config.config.getboolean('rhn', 'fetch_all_packages'))
        s.setRemoveOldPackages(config.config.getboolean('rhn', 'remove_old_packages'))
        s.certFile = config.config.get('rhn', 'cert_file')
        s.systemidFile = config.config.get('rhn', 'systemid_file')

        # Perform the sync
        dest_dir = '%s/%s/' % (config.config.get('paths', 'local_storage'), repo['id'])
        if not skip_dict.has_key('packages') or skip_dict['packages'] != 1:
            s.syncPackages(channel, savePath=dest_dir, callback=progress_callback)
            s.createRepo(dest_dir)
        if not skip_dict.has_key('errata') or skip_dict['errata'] != 1:
            updateinfo_path = os.path.join(dest_dir, "updateinfo.xml")
            if os.path.isfile(updateinfo_path):
                log.info("updateinfo_path is found, calling updateRepo")
                s.updateRepo(updateinfo_path, os.path.join(dest_dir, "repodata"))

        return dest_dir
github pulp / pulpcore / nodes / common / pulp_node / resources.py View on Github external
def pulp_bindings():
    """
    Get a pulp bindings object for this node.
    Properties defined in the pulp server configuration are used
    when not defined in the node configuration.
    :return: A pulp bindings object.
    :rtype: Bindings
    """
    node_conf = node_configuration()
    oauth = node_conf.oauth
    verify_ssl = False if node_conf.main.verify_ssl.lower() == 'false' else True
    ca_path = node_conf.main.ca_path
    host = pulp_conf.get('server', 'server_name')
    key = pulp_conf.get('oauth', 'oauth_key')
    secret = pulp_conf.get('oauth', 'oauth_secret')
    connection = PulpConnection(
        host=host,
        port=443,
        oauth_key=key,
        oauth_secret=secret,
        oauth_user=oauth.user_id,
        validate_ssl_ca=verify_ssl,
        ca_path=ca_path)
    bindings = Bindings(connection)
    return bindings
github pulp / pulp / src / pulp / server / api / distribution.py View on Github external
def __make_ks_url(self, distribution):
        """
        construct a kickstart url for distribution
        """
        distribution['url'] = []
        server_name = config.config.get("server", "server_name")
        ks_url = config.config.get("server", "ks_url")
        collection = model.Repo.get_collection()
        repos = collection.find({"distributionid":distribution['id']}, fields=["id", "relative_path"])
        for repo in repos:
            url = "%s://%s%s/%s/" % ("http", server_name, ks_url, repo['relative_path'])
            distribution['url'].append(url)
        return distribution
github pulp / pulp / platform / src / pulp / server / event / mail.py View on Github external
def _send_email(subject, body, to_address):
    """
    Send a text email to one recipient

    :param subject: email subject
    :type  subject: basestring
    :param body:    text body of the email
    :type  body:    basestring
    :param to_address:  email address to send to
    :type  to_address:  basestring

    :return: None
    """
    host = config.get('email', 'host')
    port = config.getint('email', 'port')
    from_address = config.get('email', 'from')

    message = MIMEText(body)
    message['Subject'] = subject
    message['From'] = from_address
    message['To'] = to_address

    try:
        connection = smtplib.SMTP(host=host, port=port)
    except smtplib.SMTPConnectError:
        logger.error('SMTP connection failed to %s on %s' % (host, port))
        return

    try:
        connection.sendmail(from_address, to_address, message.as_string())
    except smtplib.SMTPException, e:
        try:
github pulp / pulp / server / pulp / server / db / connection.py View on Github external
if config.config.has_option('database', 'replica_set'):
                replica_set = config.config.get('database', 'replica_set')

        if replica_set is not None:
            connection_kwargs['replicaSet'] = replica_set

        write_concern = config.config.get('database', 'write_concern')
        if write_concern not in ['majority', 'all']:
            raise PulpCodedException(error_code=error_codes.PLP0043)
        elif write_concern == 'all':
            write_concern = len(seeds_list)

        # Process SSL settings
        if config.config.getboolean('database', 'ssl'):
            connection_kwargs['ssl'] = True
            ssl_keyfile = config.config.get('database', 'ssl_keyfile')
            ssl_certfile = config.config.get('database', 'ssl_certfile')
            if ssl_keyfile:
                connection_kwargs['ssl_keyfile'] = ssl_keyfile
            if ssl_certfile:
                connection_kwargs['ssl_certfile'] = ssl_certfile
            verify_ssl = config.config.getboolean('database', 'verify_ssl')
            connection_kwargs['ssl_cert_reqs'] = ssl.CERT_REQUIRED if verify_ssl else ssl.CERT_NONE
            connection_kwargs['ssl_ca_certs'] = config.config.get('database', 'ca_path')

        # If username & password have been specified in the database config,
        # attempt to authenticate to the database
        username = config.config.get('database', 'username')
        password = config.config.get('database', 'password')
        if username:
            _logger.debug(_('Attempting username and password authentication.'))
            connection_kwargs['username'] = username
github pulp / pulpcore / server / pulp / server / auth / ldap_connection.py View on Github external
        @param username:  Username to be added
        @param userdata: tuple of user data as returned by lookup_user

        Adds a user to the pulp user database with no password and
        returns a pulp.server.db.model.User object
        """
        user = model.User.objects(login=username).first()
        if user is None:
            attrs = userdata[1]
            if 'gecos' in attrs and isinstance(attrs['gecos'], basestring):
                name = attrs['gecos']
            else:
                name = username
            user = user_controller.create_user(login=username, name=name)
            if config.has_option('ldap', 'default_role'):
                role_id = config.get('ldap', 'default_role')
                self.role_manager.add_user_to_role(role_id, username)

        return user