Bug 1127529

Summary: [RFE][oslo]: JsonOpt Support for oslo.config
Product: Red Hat OpenStack Reporter: RHOS Integration <rhos-integ>
Component: RFEsAssignee: RHOS Maint <rhos-maint>
Status: CLOSED UPSTREAM QA Contact:
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: unspecifiedCC: markmc, yeylon
Target Milestone: ---Keywords: FutureFeature
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
URL: https://blueprints.launchpad.net/oslo/+spec/jsonopt-oslo-config
Whiteboard: upstream_milestone_none upstream_definition_new upstream_status_good-progress
Fixed In Version: Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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