[openstack-dev] [oslo] Option registration convention?

Mark McLoughlin markmc at redhat.com
Thu Jun 13 08:23:13 UTC 2013


On Thu, 2013-06-13 at 15:01 +0800, Zhongyue Luo wrote:
> 
> 
> 
> On Thu, Jun 13, 2013 at 2:09 PM, Mark McLoughlin <markmc at redhat.com> wrote:
>         On Thu, 2013-06-13 at 13:35 +0800, Zhongyue Luo wrote:

>         
>         > The downside of this solution is that we have to call a private
>         > function in ConfigOpts called _all_opt_infos() to look at all options
>         > registered.
>         > https://github.com/openstack/oslo.config/blob/master/oslo/config/cfg.py#L1822
>         >
>         > We would have to create a public api version of it.
>         
>         
>         I think it would be useful to have an API which would return the Opt
>         object associated with a given config option name:
>         
>           def lookup(self, name, group=None):
>               return self._get_opt_info(opt_name, group)['opt']
>         
>         
>         and then we can just do:
>         
>           def print_help(conf, group=None):
>               d = conf if group is None else conf[group]
>               for key in d.keys():
>                   if isinstance(conf.GroupAttr, d[key]):
>                       print_help(conf, group=key)
>                   else:
>                       print key, conf.lookup(key, group).help
> 
> 
> But don't we already have the Opt object retrieved from the module object?
> I'm not sure I understand this part.

You asked about an API for introspecting a ConfigOpts object and this is
my suggestion for that API.

But, yes - if we just probe module-level option declarations, rather
than introspect cfg.CONF then we don't need this API.

>         >  Or just have generate.py handle things on its own.
>         > 3) Any objections of adding a public version of _all_opt_infos()?
>         
>         
>         No objection to something like the lookup() above, but we already have a
>         way of iterating over registered options and groups.
> 
> 
> cfg.CONF.items() is what you're referring to, right?

Well, more like conf.keys() ... but yes, that's what I mean.

Cheers,
Mark.





More information about the OpenStack-dev mailing list