Skip to content

Commit 0ccc26c

Browse files
committed
[backward-conversion] Recognize templates #100
Closes #100
1 parent 5182887 commit 0ccc26c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ target/
5454

5555
# editors
5656
*.komodoproject
57+
.vscode
5758

5859
# other
5960
*.DS_Store*
6061
.__*
6162
__DEV
63+
64+
# TODO: Remove
65+
test.py

netjsonconfig/backends/base/backend.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,36 @@ def json(self, validate=True, *args, **kwargs):
161161
config.update({'type': 'DeviceConfiguration'})
162162
return json.dumps(config, *args, **kwargs)
163163

164+
def distinct_native(self, templates=None):
165+
"""
166+
:param templates: ``list`` containing **NetJSON** configuration dictionaries
167+
168+
returns a dict of configuration which contains configurations
169+
that do not exist in given templates.
170+
171+
:returns: dict
172+
"""
173+
config_to_send = {}
174+
controller_config = self._merge_config({}, templates)
175+
for section in controller_config:
176+
device_section = self.config.get(section, None)
177+
178+
if device_section and isinstance(device_section, list):
179+
for element in device_section:
180+
element_dict = dict(element)
181+
if element_dict not in controller_config[section]:
182+
config_to_send[section] = element_dict
183+
184+
if device_section and isinstance(device_section, dict):
185+
for config in controller_config[section]:
186+
device_config = device_section.get(config, None)
187+
if device_config and device_config != controller_config[section][config]:
188+
if not config_to_send.get(section, None):
189+
config_to_send[section] = {}
190+
config_to_send[section][config] = device_config
191+
192+
return config_to_send
193+
164194
def generate(self):
165195
"""
166196
Returns a ``BytesIO`` instance representing an in-memory tar.gz archive

0 commit comments

Comments
 (0)