基于OpenStack Ocata版本源码分析--oslo.config

本文介绍了OpenStack项目中的oslo.config库,主要用于解析命令行CLI和配置文件(.conf)的配置信息。文章详细讲解了oslo.config的安装、使用方法,并通过keystone.conf配置文件的例子展示其解析过程,同时还提到了配置选项的注册和CLI的注册。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

oslo.config

oslo.config 是用OpenStack 项目中使用频繁比较高的一个类库,主要作用是用解析OpenStack 中命令行(CLI)、配置文件(.conf)的配置信息。

例如;

keystone.conf (/etc/keystone/keystone.conf) 配置文件中的catalog 配置信息:

[catalog]

#
# From keystone
#

# Absolute path to the file used for the templated catalog backend. This option
# is only used if the `[catalog] driver` is set to `templated`. (string value)
#template_file = default_catalog.templates

# Entry point for the catalog driver in the `keystone.catalog` namespace.
# Keystone provides a `sql` option (which supports basic CRUD operations
# through SQL), a `templated` option (which loads the catalog from a templated
# catalog file on disk), and a `endpoint_filter.sql` option (which supports
# arbitrary service catalogs per project). (string value)
#driver = sql

# Toggle for catalog caching. This has no effect unless global caching is
# enabled. In a typical deployment, there is no reason to disable this.
# (boolean value)
#caching = true

# Time to cache catalog data (in seconds). This has no effect unless global and
# catalog caching are both enabled. Catalog data (services, endpoints, etc.)
# typically does not change frequently, and so a longer duration than the
# global default may be desirable. (integer value)
#cache_time = <None>

# Maximum number of entities that will be returned in a catalog collection.
# There is typically no reason to set this, as it would be unusual for a
# deployment to have enough services or endpoints to exceed a reasonable limit.
# (integer value)
#list_limit = <None>

使用oslo.config进行解析:

文件位置: keystone/keystone/conf/catalog.py

from oslo_config import cfg

from keystone.conf import utils

# 对应 keystone.conf 配置文件中[catalog]中的template_file
template_file = cfg.StrOpt(
    'template_file',
    default='default_catalog.templates',
    help=utils.fmt("""
Absolute path to the file used for the templated catalog backend. This option
is only used if the `[catalog] driver` is set to `templated`.
"""))

# 对应 keystone.conf 配置文件中[catalog]中的driver
driver = cfg.StrOpt(
    'driver',
    default='sql',
    help=utils.fmt("""
Entry point for the catalog driver in the `keystone.catalog` namespace.
Keystone provides a `sql` option (which supports basic CRUD operations through
SQL), a `templated` option (which loads the catalog from a templated catalog
file on disk), and a `endpoint_filter.sql` option (which supports arbitrary
service catalogs per project).
"""))

# 对应 keystone.conf 配置文件中[catalog]中的caching
aching = cfg.BoolOpt(
    'caching',
    default=True,
    help=utils.fmt("""
Toggle for catalog caching. This has no effect unless global caching is
enabled. In a typical deployment, there is no reason to disable this.
"""))

# 对应 keystone.conf 配置文件中[catalog]中的cache_time
cache_time = cfg.IntOpt(
    'cache_time',
    help=utils.fmt("""
Time to cache catalog data (in seconds). This has no effect unless global and
catalog caching are both enabled. Catalog data (services, endpoints, etc.)
typically does not change frequently, and so a longer duration than the global
default may be desirable.
"""))

# 对应 keystone.conf 配置文件中[catalog]中的list_limit
list_limit = cfg.IntOpt(
    'list_limit',
    help=utils.fmt("""
Maximum number of entities that will be returned in a catalog collection. There
is typically no reason to set this, as it would be unusual for a deployment to
have enough services or endpoints to exceed a reasonable limit.
"""))


GROUP_NAME = __name__.split('.')[-1]
ALL_OPTS = [
    template_file,
    driver,
    aching,
    cache_time,
    list_limit,
]


def register_opts(conf):
    conf.register_opts(ALL_OPTS, group=GROUP_NAME)


def list_opts():
    return {GROUP_NAME: ALL_OPTS}

oslo.config 安装

pip install oslo.config

oslo.config 使用

简单使用:

#
# cfg 是 oslo_config 核心模块
# types:StringBooleanInteger、Float、Port、List、Dict、IPAddress、Hostname、HostAddress、URI。     
#  
from  oslo_config import cfg
from  oslo_config import types

PortType = types.Integer(1, 65535)

common_opts = [
    cfg.StrOpt('bind_host', default='0.0.0.0', help='IP address to listen on.'),
    cfg.Opt('bind_port', type=PortType, default=9292, help='Port number to listen on.')
]

与之对应的 .conf:

$ cat 01.conf

# IP address to listen on.
bind_host = '0.0.0.0'

# Port number to listen on.
bind_port = 9292
  • cfg.StrOpt
driver = cfg.StrOpt(
    'driver',
    default='sql',
    help=utils.fmt("""
Entry point for the assignment backend driver (where role assignments are
stored) in the `keystone.assignment` namespace. Only a SQL driver is supplied
by keystone itself. Unless you are writing proprietary drivers for keystone,
you do not need to set this option.
"""))
  • cfg.ListOpt
prohibited_implied_role = cfg.ListOpt(
    'prohibited_implied_role',
    default=['admin'],
    help=utils.fmt("""
A list of role names which are prohibited from being an implied role.
"""))
  • cfg.URIOpt
public_endpoint = cfg.URIOpt(
    'public_endpoint',
    help=utils.fmt("""
The base public endpoint URL for Keystone that is advertised to clients (NOTE:
this does NOT affect how Keystone listens for connections). Defaults to the
base host URL of the request. For example, if keystone receives a request to
`http://server:5000/v3/users`, then this will option will be automatically
treated as `http://server:5000`. You should only need to set option if either
the value of the base URL contains a path that keystone does not automatically
infer (`/prefix/v3`), or if the endpoint should be found on a different host.
"""))
  • cfg.IntOpt
max_project_tree_depth = cfg.IntOpt(
    'max_project_tree_depth',
    default=5,
    help=utils.fmt("""
Maximum depth of the project hierarchy, excluding the project acting as a
domain at the top of the hierarchy. WARNING: Setting it to a large value may
adversely impact performance.
"""))
  • cfg.BoolOpt
strict_password_check = cfg.BoolOpt(
    'strict_password_check',
    default=False,
    help=utils.fmt("""
If set to true, strict password length checking is performed for password
manipulation. If a password exceeds the maximum length, the operation will fail
with an HTTP 403 Forbidden error. If set to false, passwords are automatically
truncated to the maximum length.
"""))

注册

from  oslo_config import cfg
from  oslo_config import types

conf = cfg.CONF

PortType = types.Integer(1, 65535)

common_opts = [
    cfg.StrOpt('bind_host', default='0.0.0.0', help='IP address to listen on.'),
    cfg.Opt('bind_port', type=PortType, default=9292, help='Port number to listen on.')
]
# 使用 register_opts 
conf.register_opts(common_opts, group='default')

注册CLI

cli_opts = [
    cfg.BoolOpt('verbose',
                short='v',
                default=False,
                help='Print more verbose output.'),
    cfg.BoolOpt('debug',
                short='d',
                default=False,
                help='Print debugging output.'),
]

def add_common_opts(conf):
    conf.register_cli_opts(cli_opts)
<think>好的,我需要帮助用户确定CentOS上OpenStack Train的版本号。首先,用户提到了在CentOS7下安装OpenStack Train版本的Dashboard时遇到的问题,引用了相关的安装步骤,比如克隆Horizon仓库的稳定分支stable/train,以及初始化命令的路径。这说明用户可能已经通过kolla-ansible进行部署,而kolla-ansible通常与特定版本OpenStack相关联。 首先,OpenStack版本命名是按字母顺序的,比如Train是第20个版本,对应2019.10发布的。通常每个版本会有详细的版本号,比如Train的版本号是20.0.0。不过需要确认CentOS中OpenStack的包版本是否与上游一致,因为RDO或其他仓库可能会有些差异。 用户提供的引用中提到使用stable/train分支,而OpenStack的每个稳定分支对应一个主要版本。例如,Train的版本号是20.x.x。CentOS可能通过RDO仓库提供OpenStack Train,需要确认RDO中对应的版本号。 另外,用户执行了初始化脚本/usr/share/kolla-ansible/init-runonce,这说明他们使用的是kolla-ansible进行部署,而kolla-ansible的版本也会对应特定的OpenStack版本。例如,kolla-ansible的Train版本应该对应OpenStack Train。 可能需要检查安装的软件包版本,比如通过yum list installed | grep openstack,或者查看horizon的版本号,因为用户克隆了Horizon的stable/train分支,Horizon属于OpenStack的Dashboard组件,其版本号应与Train一致,即20.x.x。 总结来说,CentOS上通过kolla-ansible部署的OpenStack Train版本对应的版本号应为20.x.x,具体的小版本号可能需要查看具体的软件包或使用命令如openstack --version来确认。</think>在CentOS系统中,OpenStack Train版本对应的版本号为**20.x.x系列**。具体说明如下: 1. **版本命名规则** OpenStack采用按字母顺序的代号命名,Train是第20个版本,于2019年10月发布。其基础组件的版本号统一为$20.0.0$,例如: - Nova组件:$20.0.0$ - Neutron组件:$20.0.0$ - Horizon组件:$20.0.0$(对应git仓库的`stable/train`分支)[^1] 2. **CentOS中的部署验证** 通过Kolla-Ansible部署时,可使用以下命令验证: ```bash # 查看kolla-ansible版本OpenStack的映射关系 yum info kolla-ansible | grep Version # 查看已安装的OpenStack组件版本 openstack --version ``` 若使用RDO仓库安装,Train版本在CentOS中通常标记为`centos-openstack-train`,软件包版本号为$20.*`。 3. **初始化脚本关联性** 用户引用的初始化脚本路径`/usr/share/kolla-ansible/init-runonce`是Kolla-Ansible为Train版本提供的标准初始化工具,其设计兼容OpenStack 20.x.x的API特性[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值