From 61baf41edcf4c88f1442ecef3d476a49368847b9 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Sun, 24 Apr 2016 07:43:21 -0400 Subject: [PATCH 1/2] Merge pull request #5 from dgarros/pyez Add options to get_config to accept format (text, set or xml) --- lib/ansible/module_utils/junos.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/ansible/module_utils/junos.py b/lib/ansible/module_utils/junos.py index 72e323b721..66b8d742ac 100644 --- a/lib/ansible/module_utils/junos.py +++ b/lib/ansible/module_utils/junos.py @@ -249,9 +249,13 @@ class Netconf(object): self.device.facts_refresh() return self.device.facts - def get_config(self): - ele = self.rpc('get_configuration', format='text') - return str(ele.text).strip() + def get_config(self, config_format="text"): + ele = self.rpc('get_configuration', format=config_format) + + if config_format == "text" or config_format == "set": + return str(ele.text).strip() + elif config_format == "xml": + return ele def rpc(self, name, format='xml', **kwargs): meth = getattr(self.device.rpc, name) @@ -337,4 +341,3 @@ def get_module(**kwargs): module.connect() return module - From c87300f9e7cd0ca545f9d0e369bbdae961b39e66 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Sun, 24 Apr 2016 08:20:14 -0400 Subject: [PATCH 2/2] adds check on config_format kwarg in junos This adds a check to validate the arugment for config_format kwarg in get_config. If the specified format is not a valid option, the shared module will call fail_json --- lib/ansible/module_utils/junos.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/junos.py b/lib/ansible/module_utils/junos.py index 66b8d742ac..5e81b55c41 100644 --- a/lib/ansible/module_utils/junos.py +++ b/lib/ansible/module_utils/junos.py @@ -250,9 +250,12 @@ class Netconf(object): return self.device.facts def get_config(self, config_format="text"): - ele = self.rpc('get_configuration', format=config_format) + if config_format not in ['text', 'set', 'xml']: + msg = 'invalid config format... must be one of xml, text, set' + self._fail(msg=msg) - if config_format == "text" or config_format == "set": + ele = self.rpc('get_configuration', format=config_format) + if config_format in ['text', 'set']: return str(ele.text).strip() elif config_format == "xml": return ele