Skip to content

Commit

Permalink
[backward-conversion] Recognize templates openwisp#100
Browse files Browse the repository at this point in the history
  • Loading branch information
atb00ker committed Apr 20, 2020
1 parent 5182887 commit 0ccc26c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ target/

# editors
*.komodoproject
.vscode

# other
*.DS_Store*
.__*
__DEV

# TODO: Remove
test.py
30 changes: 30 additions & 0 deletions netjsonconfig/backends/base/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,36 @@ def json(self, validate=True, *args, **kwargs):
config.update({'type': 'DeviceConfiguration'})
return json.dumps(config, *args, **kwargs)

def distinct_native(self, templates=None):
"""
:param templates: ``list`` containing **NetJSON** configuration dictionaries
returns a dict of configuration which contains configurations
that do not exist in given templates.
:returns: dict
"""
config_to_send = {}
controller_config = self._merge_config({}, templates)
for section in controller_config:
device_section = self.config.get(section, None)

if device_section and isinstance(device_section, list):
for element in device_section:
element_dict = dict(element)
if element_dict not in controller_config[section]:
config_to_send[section] = element_dict

if device_section and isinstance(device_section, dict):
for config in controller_config[section]:
device_config = device_section.get(config, None)
if device_config and device_config != controller_config[section][config]:
if not config_to_send.get(section, None):
config_to_send[section] = {}
config_to_send[section][config] = device_config

return config_to_send

def generate(self):
"""
Returns a ``BytesIO`` instance representing an in-memory tar.gz archive
Expand Down

0 comments on commit 0ccc26c

Please sign in to comment.