Bug 1127529 - [RFE][oslo]: JsonOpt Support for oslo.config
Summary: [RFE][oslo]: JsonOpt Support for oslo.config
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Red Hat OpenStack
Classification: Red Hat
Component: RFEs
Version: unspecified
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
: ---
Assignee: RHOS Maint
QA Contact:
URL: https://blueprints.launchpad.net/oslo...
Whiteboard: upstream_milestone_none upstream_defi...
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-08-07 04:05 UTC by RHOS Integration
Modified: 2015-03-19 17:29 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Enhancement
Doc Text:
Clone Of:
Environment:
Last Closed:


Attachments (Terms of Use)

Description RHOS Integration 2014-08-07 04:05:07 UTC
Cloned from launchpad blueprint https://blueprints.launchpad.net/oslo/+spec/jsonopt-oslo-config.

Description:

In oslo.config.cfg, it will be useful to have an Option for specifying Json, in addition to the existing types such as StrOpt, DictOpt, etc. For example, this will allows specifying a valid Json string as value to a config parameter as shown below:

[custom_security_group]
default=[{"direction":"egress","ethertype":"IPv4"},{"direction":"ingress","protocol":"tcp","port_range_min":80,"port_range_max":80}]

Although this can be done in an indirect way by treating this as a StrOpt and then loading it into json after reading it from config file, it will be useful to have a native JsonOpt that performs this functionality.

The implementation of this is straight-forward with something like the following. Note that the below code needs to be enhanced with error checking, etc.

class Json(object):
 def __init__(self):
        super(Json, self).__init__()

    def __call__(self, value):
        import json
        return json.loads(str(value))
  
    def __repr__(self):
        return 'Json'
   ....

class JsonOpt(Opt):
    def __init__(self, name, **kwargs):
        super(JsonOpt, self).__init__(name,
                                      type=Json(),
                                      **kwargs)

Specification URL (additional information):

None


Note You need to log in before you can comment on or make changes to this bug.