Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def parse_output(element):
self.outputs.append(_outputter_class(element, template_obj=self))
[{'interface': 'Lo0', 'ip': '192.168.0.1', 'mask': '32'},
{'interface': 'Lo1', 'ip': '1.1.1.1', 'mask': '32'},
{'interface': 'Lo2', 'ip': '2.2.2.2', 'mask': '32'},
{'interface': 'Lo3', 'ip': '3.3.3.3', 'mask': '32'}]
"""
# filter templates to run outputs for:
templates = [templates] if isinstance(templates, str) else templates
templates_obj = self._templates
if templates:
templates_obj = [
template for template in self._templates if template.name in templates
]
# checkif kwargs privided, create outputter if so
if kwargs:
kwargs.setdefault("returner", "self")
outputter = _outputter_class(**kwargs)
# form results structure
if structure.lower() == "list":
if kwargs:
return [
outputter.run(template.results, macro=template.macro)
for template in templates_obj
]
else:
return [template.results for template in templates_obj]
elif structure.lower() == "dictionary":
if kwargs:
return {
template.name: outputter.run(template.results, macro=template.macro)
for template in templates_obj
if template.name
}