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

oslo_config学习小结 配置文件指的是文件以.conf,.ini结尾等内容为配置项的文件,配置文件内容格式一般为[DEFAULT][sectiona][sectionb] 阅读详情

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:String、Boolean、Integer、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)
OpenStack Ocata 官方文档下载 OpenStack Ocata官方英文安装文档,Centos 7/RHEL 7 64位 立即下载

相关推荐

OpenstackOcata本地源

用于Centos7的OpenstackOcata版的包,全部下载到本地了,传进去设置好yum源就能用。

openstack从入门到精通—基于Ocata版本

本课程详细地介绍了openstack的原理,部署过程,全部为现场搭环境一步步实战操作,真正带你走进openstack的世界

AIAgent知识表示与推理:基于本体论与规则引擎的实现

AIAgent知识表示与推理:基于本体论与规则引擎的实现 1. 背景介绍 人工智能(AI)系统的核心是知识表示和推理,这是实现智能行为的基础。在过去的几十年里,人工智能领域一直致力于研究如何有效地表示和推理知识,以支持智能系统的决策和行为。其中,基于本体论的知识表示和

AI天才研究院 1494

Ubuntu 20.04集群手动安装OpenStack Yoga

文章目录基础基础中的基础基础OpenStack 基础 基础中的基础 我这里用的是Ubuntu 20.04,开局白板啥都没有。 好像已经使用netplan和NetworkManager管理网络,但是因为centos不用NM,而且为了方便,我这里使用network管理网络。 首先需要安装几个软件,分别是networking服务、网桥工具以及网络工具(比如ifconfig)。 只有有了网桥工具才能正常创建网桥,不然会报错 apt install ifupdown bridge-utils net-tools --

RBK的博客 4565

TLV320AIC3204音频CODEC硬件设计与调试实战

本文深入解析了TLV320AIC3204音频CODEC的硬件设计与调试实战。文章从芯片功能定位入手,详细阐述了电源时钟设计、模拟输入电路等关键硬件设计要点,并提供了软件驱动配置与分层调试方法,帮助工程师有效规避常见陷阱,解决底噪、失真等典型音频调试问题。

zero1的博客 1125

zabbix6.0.4拓扑图链路显示流量

1. 背景介绍 网络流量监控是网络管理员必备功课,以前研究cacti的weathermap插件,网络流量大小和拥塞情况一清二楚,随着cacti的没落,weathermap插件也不能再继续使用,此时就需要学习了解新的替代方案。 经过研究和实际测试,发现zabbix的拓扑图有这个功能。 以下验证了zabbix的拓扑图显示线路流量的功能。 2. Zabbix 6显示拓扑图流量过程 选择监测-拓扑图 点进Local ne...

u013930899的博客 8483

python openstack oslo_config使用_OpenStack 实现技术分解 (7) 通用库 — oslo_config

目录前文列表扩展阅读oslo.config(摘自官方文档) An OpenStack library for parsing configuration options from the command line and configuration files.oslo.config 是一个 OpenStack 通用库, 用于解析并加载来自于 CLI 或配置文件中所提供的参数项或配置项.oslo....

weixin_39942492的博客 598

基于ESP32-WROOM的智能蓝牙电压电流监测与远程控制系统设计

本文介绍了基于ESP32-WROOM的智能蓝牙电压电流监测与远程控制系统设计。该系统集成了INA219传感器和OLED显示屏,通过蓝牙实现无线数据传输和远程控制,适用于智能家居能耗监控和工业设备管理,具有成本低、精度高、功耗优化等优点。

qsc901234的博客 203

open stack-Zed安装笔记(All In One)(一台物理机既做控制节点也做计算节点)

进入文件后第一行127.0.0.1这行不管,是回环网络的解析,其他行全屏蔽掉,然后输入自己的,有多少个节点就输入多少行,格式参照第一行,先是IP地址,然后是主机名。打开文件后应该看见里面第一行写着Ubuntu(你自己之前设置的主机名),把这行删了,写上controller。身份验证服务使用域的组合, 项目、用户和角色。安装好Ubuntu系统后进入终端,可以su进入超级用户,也可以不用,用apt下载一些需要的组件,新版本的Ubuntu可能打开该文件是一个新文件,没有关系,进去写就对了。

LCX190937的博客 1226

RDM协议控制端实战:从数据包构造到高效设备发现算法

本文深入探讨了RDM协议控制端的核心开发流程,涵盖从数据包构造、发送到响应解析的全过程。重点解析了如何利用二分搜寻算法高效实现网络设备发现,并分享了组包、解包中的关键代码实现与常见调试技巧,为舞台灯光与智能硬件领域的嵌入式开发提供实战指导。

week9的博客 457

【ArcGIS遇上Python】使用add-in向导开发ArcGIS插件(1):add-in工具介绍及安装

文章目录addin介绍addin下载addin安装 addin介绍 ArcGIS从10.0开始支持addin(ArcGIS软件中又叫作加载项)的方式进行插件制作。相对于以往9.x系列,addin的无论是从使用或者编写都更加方便快捷。通过开发语言,可以制作ArcGIS Desktop各个软件模块的插件。 Esri提供了Python加载项向导工具来实现Addin界面的搭建,可以到Esri官网去下载该工具Python加载项向导 。从介绍来看,该设计器要求的最低ArcGIS版本为10.1 ,如下图所示: add

智慧空间实验室 7201

云计算实训(实验3、实验4)

OpenStack实验3、4

m0_74268254的博客 2425

Python爬虫实战:使用最新技术抓取采购网招标公告信息

本文将详细介绍如何使用Python最新爬虫技术构建一个高效的采购网招标公告信息抓取系统。我们将从爬虫基础概念讲起,逐步深入到高级技巧,包括异步处理、反爬虫对策、数据解析与存储等,并提供完整的代码实现。本文旨在为读者提供一套完整的网络数据采集解决方案,适用于各类政府采购平台和商业招标网站。网络爬虫(Web Crawler)是一种自动抓取互联网信息的程序或脚本,它们按照一定的规则,自动地浏览万维网并提取所需数据。在现代商业环境中,爬虫技术广泛应用于价格监控、竞争情报收集、市场研究等领域。

2201_76125261的博客 1622

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

oslo 是OpenStack的公共库。 oslo.config oslo.messaging oslo.log

基于OpenStack Ocata版本源码分析 259

【数据集】1970-2023年全球温室气体排放 GHG 数据集 EDGAR

1970-2023年全球温室气体排放 GHG 数据集 EDGAR

WW、forever的博客 1173

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

OpenStack公共组件oslo之一——oslo.config

本文首先基于Nova介绍了oslo.config组件的用法,然后结合其使用,详细分析了oslo.config组件的实现原理。

上善若水的木偶戏 2845

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

python配置模块oslo.config

安装oslo.config模块 pip install oslo.config python oslo.config读取配置文件 创建代码目录 mkdir /python/cinder/ 复制一个cinder的配置文件 cp /etc/cinder/cinder.conf /python/cinder/ cat /python/cinder/cinder.conf [keystone_authtoken] memcached_servers = localhost:11211 signing_dir

weixin_40548182的博客 2539

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

oslo.config

 OpenStack的oslo项目旨在独立出系统中可重用的基础功能,oslo.config就是其中一个被广泛使用的库,该项工作的主要目的就是解析OpenStack中命令行(CLI)或配置文件(.conf)中的配置信息。 配置文件:   用来配置OpenStack各个服务的ini风格的配置文件,通常以.conf结尾; 配置项(options):    配置文件或命令行中给出的配置信息的

u012977347的博客 652

openstack oslo_config 和 oslo_log库

一、oslo.config库的作用和概念理解 openstack中的 oslo.config库用于解析命令行和配置文件中的配置选项,把配置项直接融入代码内。在本文的语境下,有这么几个概念: 配置文件:用来配置OpenStack各个服务的ini风格的配置文件,通常以.conf结尾; 配置项(options):     配置文件或命令行中给出的配置信息的左值,如:enabled_apis =

每天进步一点点。。。的博客 3702

一文帮你快速掌握 OpenStack 的 oslo.config

本文将深入探讨 oslo.config 的核心功能、设计理念以及在 OpenStack 生态系统中的重要角色,帮助读者快速掌握如何使用 oslo.config 来管理复杂的云服务配置。无论你是对 OpenStack 充满好奇的初学者,还是希望优化现有系统的资深开发者,这篇文章都将为你提供有价值的见解和实用的指导。

qq_32799165的博客 1283

python openstack oslo_config使用_【转】Openstack中oslo_config模块学习

OpenStack的项目貌似越来越多了,在Grizzly版之前,每个项目都得实现一套处理配置文件的代码。在每个项目的源码中基本上都可以找到openstack/common/cfg.py,iniparser.py文件,当然,这些不同项目之间的cfg.py等文件很大可能是copy-and-paste分分钟来搞定。这种情况肯定无法被大神忍受,最终,社区决定改变这一切,提出了Oslo项目。Oslo项目的宗...

weixin_39614546的博客 432

OpenStack配置解析库oslo.config

oslo.config模块在OpenStack中最大的作用就是配置文件以及命令行参数的解析要了解oslo.config的工作流程,需要了解一下关于Python基础模块中的argparse模块,该模块的信息可以参考:https://docs.python.org/2/library/argparse.html命令行参数的解析使用的是argparse基础模块中的ArgumentParser类,该类可以...

ikukaku的博客 1187

OpenStack Oslo.Config 项目启动与配置教程

OpenStack Oslo.Config 项目启动与配置教程 1. 项目的目录结构及介绍 OpenStack Oslo.Config 是一个用于解析命令行参数和 .ini 风格配置文件的开源库。以下是项目的目录结构及各部分的作用介绍: doc/: 包含项目的文档。 oslo_config/: 核心代码目录,包含了所有的配置解析功能。 releasenotes/: 包含版本的发布说明。 .cov...

gitblog_00490的博客 293

oslo config

前段时间开始认真看了一下Ryu的源码,发现oslo是一个非常方便的命令行解析库,可以用于CLI和CONF的解析。oslo是 OpenStack发起的项目,全称为OpenStack Common Libraries,是OpenStack Projects共享的基础库。 oslo 在RYU的目录下可以找到cfg.py文件,这个文件中import了oslo的相关模块,以便调用时减少引用数目。从文件中可

公众号 1078

OpenStack开发基础-oslo.config

The cfg Module cfg Module来自于OpenStack中的重要的基础组件oslo.config,通过cfg Module能够用来通过命令行或者是配置文件来配置一些options,对于每个选项使用Opt类或者其子类来定义。首先我们来看一个定义option的样例: example1: #!/usr/bin/env python # encoding: u...

weixin_33753003的博客 208
下一篇: 基于OpenStack Ocata版本源码分析-oslo
analy100
博客等级 码龄9年 0粉丝 2原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值