Skip to content

Commit

Permalink
prepare for backends module splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
edoput committed May 18, 2018
1 parent 11cfed1 commit 5566d6b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
10 changes: 3 additions & 7 deletions bin/netjsonconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import six
import argparse
import netjsonconfig


description = """
Converts a NetJSON DeviceConfiguration object to native router configurations.
Expand Down Expand Up @@ -56,7 +57,7 @@ output = parser.add_argument_group('output')

output.add_argument('--backend', '-b',
required=True,
choices=['openwrt', 'openwisp', 'openvpn'],
choices=netjsonconfig.get_backends().keys(),
action='store',
type=str,
help='Configuration backend')
Expand Down Expand Up @@ -166,13 +167,8 @@ context = dict(os.environ)
method = args.method
method_arguments = parse_method_arguments(args.args)

backends = {
'openwrt': netjsonconfig.OpenWrt,
'openwisp': netjsonconfig.OpenWisp,
'openvpn': netjsonconfig.OpenVpn
}

backend_class = backends[args.backend]
backend_class = netjsonconfig.get_backends()[args.backend]
try:
options = dict(templates=templates, context=context)
if args.config:
Expand Down
14 changes: 14 additions & 0 deletions netjsonconfig/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
from pkg_resources import iter_entry_points

from .version import VERSION, __version__, get_version # noqa

from .backends.openwrt.openwrt import OpenWrt # noqa
from .backends.openwisp.openwisp import OpenWisp # noqa
from .backends.openvpn.openvpn import OpenVpn # noqa


def get_backends():
default = {
'openwrt': OpenWrt,
'openwisp': OpenWisp,
'openvpn': OpenVpn,
}

for entry_point in iter_entry_points('netjsonconfig.backends'):
default.update({entry_point.name.lower(): entry_point.load()})
return default

0 comments on commit 5566d6b

Please sign in to comment.