python类ConfigParser()的实例源码

ec2_mod.py 文件源码 项目:ansible-tower-automated-deployment 作者: OliverCable 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def assume_role(self, region, profile):
        # assume role

        global connect_args

        if six.PY3:
            aws_creds  = configparser.ConfigParser()
            aws_config = configparser.ConfigParser()
        else:
            aws_creds  = configparser.SafeConfigParser()
            aws_config = configparser.SafeConfigParser()

        aws_creds.read(os.path.expanduser("~/.aws/credentials"))
        aws_config.read(os.path.expanduser("~/.aws/config"))

        source_profile = self.get_option(aws_config, profile, 'source_profile')
        arn            = self.get_option(aws_config, profile, 'role_arn')
        aws_access_key = self.get_option(aws_creds, source_profile, 'aws_access_key_id')
        aws_secret_key = self.get_option(aws_creds, source_profile, 'aws_secret_access_key')
        session_name   = "role_session_name_" + self.boto_profile

        sts_conn = sts.STSConnection(aws_access_key, aws_secret_key)
        assume_role = sts_conn.assume_role(role_arn=arn, role_session_name=session_name)
        connect_args['aws_access_key_id']     = assume_role.credentials.access_key
        connect_args['aws_secret_access_key'] = assume_role.credentials.secret_key
        connect_args['security_token']        = assume_role.credentials.session_token
utils.py 文件源码 项目:glog-cli 作者: globocom 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_config(config_file_path="~/.glogcli.cfg"):
    config = configparser.ConfigParser()
    try:
        open(os.path.expanduser(config_file_path))
    except Exception:
        click.echo("[WARNING] - Could not find %s file. Please create the configuration file like:" % config_file_path)
        click.echo("\n[environment:default]\n"
                   "host=mygraylogserver.com\n"
                   "port=443\n"
                   "username=john.doe\n"
                   "default_stream=*\n"
                   "\n"
                   "[environment:dev]\n"
                   "host=mygraylogserver.dev.com\n"
                   "port=443\n"
                   "proxy=mycompanyproxy.com\n"
                   "username=john.doe\n"
                   "default_stream=57e14cde6fb78216a60d35e8\n"
                   "\n"
                   "[format:default]\n"
                   "format={host} {level} {facility} {timestamp} {message}\n"
                   "\n"
                   "[format:short]\n"
                   "format=[{timestamp}] {level} {message}\n"
                   "\n"
                   "[format:long]\n"
                   "format=time: [{timestamp}] level: {level} msg: {message} tags: {tags}\n"
                   "color=false\n"
                   "\n")

    config.read(os.path.expanduser(config_file_path))
    return config
manager.py 文件源码 项目:virtualbmc 作者: openstack 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def add(self, username, password, port, address, domain_name, libvirt_uri,
            libvirt_sasl_username, libvirt_sasl_password):

        # check libvirt's connection and if domain exist prior to adding it
        utils.check_libvirt_connection_and_domain(
            libvirt_uri, domain_name,
            sasl_username=libvirt_sasl_username,
            sasl_password=libvirt_sasl_password)

        domain_path = os.path.join(self.config_dir, domain_name)
        try:
            os.makedirs(domain_path)
        except OSError as e:
            if e.errno == errno.EEXIST:
                raise exception.DomainAlreadyExists(domain=domain_name)
            raise exception.VirtualBMCError(
                'Failed to create domain %(domain)s. Error: %(error)s' %
                {'domain': domain_name, 'error': e})

        config_path = os.path.join(domain_path, 'config')
        with open(config_path, 'w') as f:
            config = configparser.ConfigParser()
            config.add_section(DEFAULT_SECTION)
            config.set(DEFAULT_SECTION, 'username', username)
            config.set(DEFAULT_SECTION, 'password', password)
            config.set(DEFAULT_SECTION, 'port', six.text_type(port))
            config.set(DEFAULT_SECTION, 'address', address)
            config.set(DEFAULT_SECTION, 'domain_name', domain_name)
            config.set(DEFAULT_SECTION, 'libvirt_uri', libvirt_uri)

            if libvirt_sasl_username and libvirt_sasl_password:
                config.set(DEFAULT_SECTION, 'libvirt_sasl_username',
                           libvirt_sasl_username)
                config.set(DEFAULT_SECTION, 'libvirt_sasl_password',
                           libvirt_sasl_password)

            config.write(f)
config.py 文件源码 项目:virtualbmc 作者: openstack 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def initialize(self):
        config = configparser.ConfigParser()
        config.read(CONFIG_FILE)
        self._conf_dict = self._as_dict(config)
        self._validate()
utils.py 文件源码 项目:charm-nova-compute 作者: openstack 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def _get_config(self, unit, filename):
        """Get a ConfigParser object for parsing a unit's config file."""
        file_contents = unit.file_contents(filename)

        # NOTE(beisner):  by default, ConfigParser does not handle options
        # with no value, such as the flags used in the mysql my.cnf file.
        # https://bugs.python.org/issue7005
        config = configparser.ConfigParser(allow_no_value=True)
        config.readfp(io.StringIO(file_contents))
        return config
cli.py 文件源码 项目:osfclient 作者: osfclient 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def config_from_file():
    if os.path.exists(".osfcli.config"):
        config_ = configparser.ConfigParser()
        config_.read(".osfcli.config")

        # for python2 compatibility
        config = dict(config_.items('osf'))

    else:
        config = {}

    return config
cli.py 文件源码 项目:osfclient 作者: osfclient 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def init(args):
    """Initialize or edit an existing .osfcli.config file."""
    # reading existing config file, convert to configparser object
    config = config_from_file()
    config_ = configparser.ConfigParser()
    config_.add_section('osf')
    if 'username' not in config.keys():
        config_.set('osf', 'username', '')
    else:
        config_.set('osf', 'username', config['username'])
    if 'project' not in config.keys():
        config_.set('osf', 'project', '')
    else:
        config_.set('osf', 'project', config['project'])

    # now we can start asking for new values
    print('Provide a username for the config file [current username: {}]:'.format(
          config_.get('osf', 'username')))
    username = input()
    if username:
        config_.set('osf', 'username', username)

    print('Provide a project for the config file [current project: {}]:'.format(
          config_.get('osf', 'project')))
    project = input()
    if project:
        config_.set('osf', 'project', project)

    cfgfile = open(".osfcli.config", "w")
    config_.write(cfgfile)
    cfgfile.close()
test_util.py 文件源码 项目:RPoint 作者: george17-meet 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def config_from_ini(self, ini):
        config = {}
        if sys.version_info >= (3, 2):
            parser = configparser.ConfigParser()
        else:
            parser = configparser.SafeConfigParser()
        ini = textwrap.dedent(six.u(ini))
        parser.readfp(io.StringIO(ini))
        for section in parser.sections():
            config[section] = dict(parser.items(section))
        return config
utils.py 文件源码 项目:charm-ceph-osd 作者: openstack 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def _get_config(self, unit, filename):
        """Get a ConfigParser object for parsing a unit's config file."""
        file_contents = unit.file_contents(filename)

        # NOTE(beisner):  by default, ConfigParser does not handle options
        # with no value, such as the flags used in the mysql my.cnf file.
        # https://bugs.python.org/issue7005
        config = configparser.ConfigParser(allow_no_value=True)
        config.readfp(io.StringIO(file_contents))
        return config
__init__.py 文件源码 项目:aws-sudo 作者: voytek-solutions 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def update_credentials(profile, credentials):
    credentials_file = os.path.expanduser('~/.aws/credentials')
    config = configparser.ConfigParser()
    config.read(credentials_file)

    # Create profile section in credentials file
    if not config.has_section(profile):
        config.add_section(profile)

    # Set access credentials
    # `aws_security_token` is used by boto
    # `aws_session_token` is used by aws cli
    config.set(
        profile, 'aws_access_key_id', credentials['AccessKeyId'])
    config.set(
        profile, 'aws_secret_access_key', credentials['SecretAccessKey'])
    config.set(
        profile, 'aws_session_token', credentials['SessionToken'])
    config.set(
        profile, 'aws_security_token', credentials['SessionToken'])

    # Update credentials file
    with open(credentials_file, 'w') as credentials_file:
        config.write(credentials_file)

    print(
        "# Aws credentials file got updated with temporary access for profile %s"
        % profile
    )
utils.py 文件源码 项目:charm-glance 作者: openstack 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def _get_config(self, unit, filename):
        """Get a ConfigParser object for parsing a unit's config file."""
        file_contents = unit.file_contents(filename)

        # NOTE(beisner):  by default, ConfigParser does not handle options
        # with no value, such as the flags used in the mysql my.cnf file.
        # https://bugs.python.org/issue7005
        config = configparser.ConfigParser(allow_no_value=True)
        config.readfp(io.StringIO(file_contents))
        return config
utils.py 文件源码 项目:charm-neutron-api 作者: openstack 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def _get_config(self, unit, filename):
        """Get a ConfigParser object for parsing a unit's config file."""
        file_contents = unit.file_contents(filename)

        # NOTE(beisner):  by default, ConfigParser does not handle options
        # with no value, such as the flags used in the mysql my.cnf file.
        # https://bugs.python.org/issue7005
        config = configparser.ConfigParser(allow_no_value=True)
        config.readfp(io.StringIO(file_contents))
        return config
utils.py 文件源码 项目:charm-ceph-mon 作者: openstack 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def _get_config(self, unit, filename):
        """Get a ConfigParser object for parsing a unit's config file."""
        file_contents = unit.file_contents(filename)

        # NOTE(beisner):  by default, ConfigParser does not handle options
        # with no value, such as the flags used in the mysql my.cnf file.
        # https://bugs.python.org/issue7005
        config = configparser.ConfigParser(allow_no_value=True)
        config.readfp(io.StringIO(file_contents))
        return config
utils.py 文件源码 项目:charm-openstack-dashboard 作者: openstack 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def _get_config(self, unit, filename):
        """Get a ConfigParser object for parsing a unit's config file."""
        file_contents = unit.file_contents(filename)

        # NOTE(beisner):  by default, ConfigParser does not handle options
        # with no value, such as the flags used in the mysql my.cnf file.
        # https://bugs.python.org/issue7005
        config = configparser.ConfigParser(allow_no_value=True)
        config.readfp(io.StringIO(file_contents))
        return config
utils.py 文件源码 项目:charm-ceilometer 作者: openstack 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def _get_config(self, unit, filename):
        """Get a ConfigParser object for parsing a unit's config file."""
        file_contents = unit.file_contents(filename)

        # NOTE(beisner):  by default, ConfigParser does not handle options
        # with no value, such as the flags used in the mysql my.cnf file.
        # https://bugs.python.org/issue7005
        config = configparser.ConfigParser(allow_no_value=True)
        config.readfp(io.StringIO(file_contents))
        return config
utils.py 文件源码 项目:charm-hacluster 作者: openstack 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def _get_config(self, unit, filename):
        """Get a ConfigParser object for parsing a unit's config file."""
        file_contents = unit.file_contents(filename)

        # NOTE(beisner):  by default, ConfigParser does not handle options
        # with no value, such as the flags used in the mysql my.cnf file.
        # https://bugs.python.org/issue7005
        config = configparser.ConfigParser(allow_no_value=True)
        config.readfp(io.StringIO(file_contents))
        return config
utils.py 文件源码 项目:charm-neutron-openvswitch 作者: openstack 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def _get_config(self, unit, filename):
        """Get a ConfigParser object for parsing a unit's config file."""
        file_contents = unit.file_contents(filename)

        # NOTE(beisner):  by default, ConfigParser does not handle options
        # with no value, such as the flags used in the mysql my.cnf file.
        # https://bugs.python.org/issue7005
        config = configparser.ConfigParser(allow_no_value=True)
        config.readfp(io.StringIO(file_contents))
        return config
utils.py 文件源码 项目:charm-cinder-backup 作者: openstack 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _get_config(self, unit, filename):
        """Get a ConfigParser object for parsing a unit's config file."""
        file_contents = unit.file_contents(filename)

        # NOTE(beisner):  by default, ConfigParser does not handle options
        # with no value, such as the flags used in the mysql my.cnf file.
        # https://bugs.python.org/issue7005
        config = configparser.ConfigParser(allow_no_value=True)
        config.readfp(io.StringIO(file_contents))
        return config
configuration.py 文件源码 项目:incubator-airflow-old 作者: apache 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, *args, **kwargs):
        ConfigParser.__init__(self, *args, **kwargs)
        self.read_string(parameterized_config(DEFAULT_CONFIG))
        self.is_validated = False


问题


面经


文章

微信
公众号

扫码关注公众号