@@ -324,3 +324,51 @@ def __restore_intermediate_data(self):
324324 del self .intermediate_data
325325 self .intermediate_data = self ._intermediate_copy
326326 del self ._intermediate_copy
327+
328+ def distinct_native (self , templates = None ):
329+ """
330+ :param templates: ``list`` containing **NetJSON** configuration dictionaries
331+
332+ returns a dict of configuration which contains configurations
333+ that do not exist in given templates.
334+
335+ :returns: dict
336+ """
337+
338+ templates = self ._merge_config ({}, templates )
339+ config_to_send = deepcopy (self .config )
340+
341+ for section in self .config :
342+ template_section = templates .get (section , None )
343+
344+ if isinstance (template_section , dict ):
345+ for element in template_section :
346+ self ._distinct_native_dict (
347+ template_section , element , section , config_to_send
348+ )
349+ # if empty, delete section dict
350+ if not config_to_send [section ]:
351+ del config_to_send [section ]
352+
353+ elif isinstance (template_section , list ):
354+ for element in template_section :
355+ if element in self .config [section ]:
356+ config_to_send [section ].remove (element )
357+ # if empty, delete section list
358+ if not config_to_send [section ]:
359+ del config_to_send [section ]
360+
361+ return config_to_send
362+
363+ def _distinct_native_dict (self , template_section , element , section , config_to_send ):
364+ if element in self .config [section ].keys ():
365+ t_element = template_section [element ]
366+ if isinstance (t_element , list ):
367+ for item in t_element :
368+ if item in self .config [section ][element ]:
369+ config_to_send [section ][element ].remove (item )
370+ # if empty, delete section list
371+ if not config_to_send [section ][element ]:
372+ del config_to_send [section ][element ]
373+ elif t_element == self .config [section ][element ]:
374+ del config_to_send [section ][element ]
0 commit comments