An OpenStack library for parsing configuration options from the command
line and configuration files
1)
How to print configuration using oslo.config
from pprint import pprint
from oslo.config import cfg
res = [{k:v} for k, v in cfg.CONF.iteritems()]
pprint(res)
2)
How to Register, Unregister and Override an option in the configuration using oslo.config
from pprint import pprint
from oslo.config import cfg
##Register
opts = [cfg.StrOpt('api_server_ip', default='127.0.0.1', help=""),]
cfg.CONF.register_opts(opts)
OR
cfg.CONF.register_opt(cfg.StrOpt('api_server_ip', default='127.0.0.1', help=""))
##Unregister
opts = [cfg.StrOpt('api_server_ip', default='127.0.0.1', help=""),]
cfg.CONF.unregister_opts(opts)
OR
cfg.CONF.unregister_opt(cfg.StrOpt('api_server_ip', default='127.0.0.1', help=""))
##Override
cfg.CONF.set_override('transport_url', None)
##Print all config options
res = [{k:v} for k, v in cfg.CONF.iteritems()]
pprint(res)
1)
How to print configuration using oslo.config
from pprint import pprint
from oslo.config import cfg
res = [{k:v} for k, v in cfg.CONF.iteritems()]
pprint(res)
2)
How to Register, Unregister and Override an option in the configuration using oslo.config
from pprint import pprint
from oslo.config import cfg
##Register
opts = [cfg.StrOpt('api_server_ip', default='127.0.0.1', help=""),]
cfg.CONF.register_opts(opts)
OR
cfg.CONF.register_opt(cfg.StrOpt('api_server_ip', default='127.0.0.1', help=""))
##Unregister
opts = [cfg.StrOpt('api_server_ip', default='127.0.0.1', help=""),]
cfg.CONF.unregister_opts(opts)
OR
cfg.CONF.unregister_opt(cfg.StrOpt('api_server_ip', default='127.0.0.1', help=""))
##Override
cfg.CONF.set_override('transport_url', None)
##Print all config options
res = [{k:v} for k, v in cfg.CONF.iteritems()]
pprint(res)
Very instructive thank you for your sharing
ReplyDeleteI m wondering how can we collect the communication that goes between the componants of Openstack for exemple the RPC calls
Very appreciated for your help
nice explanation.
ReplyDeletewhat if I want to use multi "dimensional key","value" pair.
like, I want to have something like this
mydict={('a','b','c','d','e'):'syed'}
but oslo.config doesnt parse multidimensional keys.
your help will be greatly appreciated.
mydict = {('a','b','c','d','e'):'syed'}
Deletemynewconfig = [cfg.DictOpt('my_config', default=mydict, help='this is my help'),]
cfg.CONF.register_opts(mynewconfig)
mydict = {('a','b','c','d','e'):'syed'}
ReplyDeletemynewconfig = [cfg.DictOpt('my_config', default=mydict, help='this is my help'),]
cfg.CONF.register_opts(mynewconfig)