I already voiced my concern regarding this on the issue but I can tell you 
more.

You want to extend the schema of a backend and tha's a very interesting 
feature. Right now it does
not work as expected as I found during GSOC 2017 [0]. The problem is that 
you may redefine
some part of a schema which is already there and using `merge_config` as in 
[1] does not update
the previous part and only add one. This may result in errors validating 
the configuration against
the schema or worse invalid configuration passing the validation pass.

Another problem you have to think of is that you are now modifying the 
backend using `add_plugin`
. When will this happen? OpenWisp will load it? How it this going to 
happen? Is this kind of configuration
part of the server or just the library?

I'm not rejecting the `add_plugin` approach but I fear it can make the use 
of the plugins extremely simple
and undebuggable. I would like the community to spin up more code for 
supporting the configuration of
packages and such and I'm in favor of extensibility. I think my previous 
work on netjsonconfig shows
this [2] and we can reuse the same approach for Converters leaving the 
patch approach for experimentation.

https://github.com/openwisp/netjsonconfig/issues/93
[1]: 
https://github.com/openwisp/netjsonconfig/blob/e796427531298b751218c9a011ff3466dc27c906/netjsonconfig/backends/airos/schema.py#L257
[2]: 
http://netjsonconfig.openwisp.org/en/stable/backends/create_your_backend.html
Il giorno lunedì 5 novembre 2018 17:55:47 UTC+1, Aarnav Bos ha scritto:
>
> 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# 
> <http://www.google.com/url?q=http%3A%2F%2Fjson-schema.org%2Fdraft-04%2Fschema%23&sa=D&sntz=1&usg=AFQjCNErMcaHf-UwnUAcatsDo1BKETJd2A>
> ",
>     "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.

Reply via email to