summaryrefslogtreecommitdiff
path: root/lib/ansible/module_utils
diff options
context:
space:
mode:
authorNathaniel Case <this.is@nathanielca.se>2017-04-04 15:00:00 -0400
committerNathaniel Case <ncase@redhat.com>2017-04-04 15:01:36 -0400
commitbf805d145324dc5692ff26aecd931474bfbb4e65 (patch)
tree7afc4b424f41c01ccdcd7cfb992ad2c3d66472b1 /lib/ansible/module_utils
parentec0cbfac4be6a3865a3ff66431ea68f37e72b9f3 (diff)
downloadansible-bf805d145324dc5692ff26aecd931474bfbb4e65.tar.gz
junos_config: Remove reliance on ability to output configuration in `set` format (#23225)
* Remove reliance on ability to output configuration in `set` format * Support multiple warnings per rpc-reply
Diffstat (limited to 'lib/ansible/module_utils')
-rw-r--r--lib/ansible/module_utils/junos.py5
-rw-r--r--lib/ansible/module_utils/netconf.py24
2 files changed, 24 insertions, 5 deletions
diff --git a/lib/ansible/module_utils/junos.py b/lib/ansible/module_utils/junos.py
index dfe3148157..211e099eb6 100644
--- a/lib/ansible/module_utils/junos.py
+++ b/lib/ansible/module_utils/junos.py
@@ -147,7 +147,7 @@ def get_diff(module):
if output is not None:
return output.text
-def load_config(module, candidate, action='merge', commit=False, format='xml',
+def load_config(module, candidate, warnings, action='merge', commit=False, format='xml',
comment=None, confirm=False, confirm_timeout=None):
with locked_config(module):
@@ -155,6 +155,8 @@ def load_config(module, candidate, action='merge', commit=False, format='xml',
candidate = '\n'.join(candidate)
reply = load_configuration(module, candidate, action=action, format=format)
+ if isinstance(reply, list):
+ warnings.extend(reply)
validate(module)
diff = get_diff(module)
@@ -168,4 +170,3 @@ def load_config(module, candidate, action='merge', commit=False, format='xml',
discard_changes(module)
return diff
-
diff --git a/lib/ansible/module_utils/netconf.py b/lib/ansible/module_utils/netconf.py
index f2b0e03747..580de33c2b 100644
--- a/lib/ansible/module_utils/netconf.py
+++ b/lib/ansible/module_utils/netconf.py
@@ -31,13 +31,31 @@ from xml.etree.ElementTree import tostring, fromstring
from ansible.module_utils.connection import exec_command
+
+NS_MAP = {'nc': "urn:ietf:params:xml:ns:netconf:base:1.0"}
+
def send_request(module, obj, check_rc=True):
request = tostring(obj)
rc, out, err = exec_command(module, request)
- if rc != 0:
- if check_rc:
+ if rc != 0 and check_rc:
+ error_root = fromstring(err)
+ fake_parent = Element('root')
+ fake_parent.append(error_root)
+
+ error_list = fake_parent.findall('.//nc:rpc-error', NS_MAP)
+ if not error_list:
module.fail_json(msg=str(err))
- return fromstring(out)
+
+ warnings = []
+ for rpc_error in error_list:
+ message = rpc_error.find('./nc:error-message', NS_MAP).text
+ severity = rpc_error.find('./nc:error-severity', NS_MAP).text
+
+ if severity == 'warning':
+ warnings.append(message)
+ else:
+ module.fail_json(msg=str(err))
+ return warnings
return fromstring(out)
def children(root, iterable):