Custom Search

Sunday, February 1, 2015

How to use OpenStack oslo.config

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)


6 comments:

  1. Very instructive thank you for your sharing
    I 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

    ReplyDelete
  2. nice explanation.
    what 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.

    ReplyDelete
    Replies
    1. mydict = {('a','b','c','d','e'):'syed'}
      mynewconfig = [cfg.DictOpt('my_config', default=mydict, help='this is my help'),]
      cfg.CONF.register_opts(mynewconfig)

      Delete
  3. mydict = {('a','b','c','d','e'):'syed'}
    mynewconfig = [cfg.DictOpt('my_config', default=mydict, help='this is my help'),]
    cfg.CONF.register_opts(mynewconfig)

    ReplyDelete
  4. BlueHost is ultimately one of the best web-hosting provider for any hosting services you might need.

    ReplyDelete