As the issue https://github.com/openwisp/netjsonconfig/issues/112 goes,
It'd be ideal to be able to easily extend the backends. Since the use-case
of adding support for an OpenWRT package is very common, this
implementation primarily focuses on that.
Adding a method to BaseBackend to allow insertions of converters and
schemas is an approach
class BaseBackend(object):
.......
.......
def add_plugin(self, key, schema, converter):
schema.pop('$schema', None)
# add to backend's schema, this could have an option to raise an
error if the value is being overridden
self.schema['properties'][key] = schema
if getattr(self, 'converters'):
self.converters.append(converter)
else:
self.converters = [converter]
Tracking the 'plugins' can become simpler too, by adding a an attribute to
the converter, if needed.
Let's say I was to create a plugin for Coova-Chilli:
coova_schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties" : {
"disabled" : {"type" : "integer"},
},
}
class CoovaConverter(OpenWrtConverter):
def to_intermediate_loop(self, block, result, index=None):
if block:
block.update({
'.type': 'chilli',
'.name': 'chilli'
})
result['chilli'] = [self.sorted_dict(block)]
return result
........
........
o = OpenWrt({
'chilli': {
"disabled": 1,
}
})
o.add_plugin(key='chilli', schema=coova_schema, converter=CoovaConverter)
o.render()
'''
package chilli
config chilli 'chilli'
option disabled '1'
'''
This is incomplete code, obviously, but gives an idea of how the
implementation goes.
Thoughts?
--
You received this message because you are subscribed to the Google Groups
"OpenWISP" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.