Code review comment for lp:~saviq/charm-helpers/confg-patterns

Revision history for this message
MichaƂ Sawicz (saviq) wrote :

> I know the initial target is for the horizon subordinate plugin charms
> to use this, but would you mind giving an example of how horizon would use it?

Sure. The charm would register a pattern config:

> register_config('/path/to/dashboard/enabled/_{}_juju_{}.py')

Then,

> class RouterSettingContext(OSPatternContextGenerator):
> def __call__(self):
> ctxt = {
> (40, 'router'): {'DISABLED': False if config('profile') in ['cisco'] else True}
> }
> return ctxt

and, for example
> class PluginContext(OSPatternContextGenerator):
> def __call__(self):
> # ...
> ctxt = {}
> for rid in relation_ids('plugin'):
> # ...
> rdata = relation_get(rid=rid, unit=unit)
> ctxt[(rdata['priority'], unit): {'DASHBOARD': rdata['DASHBOARD'],
> 'DISABLED': rdata['DISABLED'],
> # ...
> return ctxt

This would result in generating files, say:

> /path/to/config/enabled/_40_juju_router.py
> /path/to/config/enabled/_99_juju_horizon-contrail.py

In PluginContext I can then warn about conflicts etc. Multiple subordinates could even override one another.

HTH, let me know if I should explain more of this in the docstring.

« Back to merge proposal