Skip to content

Commit

Permalink
[backward-conversion] Recognize templates #100
Browse files Browse the repository at this point in the history
Closes #100
  • Loading branch information
atb00ker committed Apr 20, 2020
1 parent 5182887 commit 86cbaeb
Show file tree
Hide file tree
Showing 2 changed files with 46 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
42 changes: 42 additions & 0 deletions netjsonconfig/backends/base/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,48 @@ def json(self, validate=True, *args, **kwargs):
config.update({'type': 'DeviceConfiguration'})
return json.dumps(config, *args, **kwargs)

def merge_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:
"""
TODO: Discuss case where dns_servers set but
someone removed it from device, will cause
information loss.
TODO: Question: in an array like interfaces,
if say, mtu is changed, do I copy the entire interface
or just the mtu value with interface name?
Currently copying the entire thing because I feel it
Should be stored together.
Same for "radios"
"""
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 86cbaeb

Please sign in to comment.