Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix iosxr netconf plugin get device info (#65489) #65588

Merged
merged 1 commit into from Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/iosxr_netconf_plugix_fix.yml
@@ -0,0 +1,2 @@
bugfixes:
- Netconf modules are sending a bad rpc call for IOS-XR (https://github.com/ansible/ansible/issues/64634)
34 changes: 18 additions & 16 deletions lib/ansible/plugins/netconf/iosxr.py
Expand Up @@ -55,22 +55,24 @@ def get_device_info(self):
])

install_filter = build_xml('install', install_meta, opcode='filter')

reply = self.get(install_filter)
ele_boot_variable = etree_find(reply, 'boot-variable/boot-variable')
if ele_boot_variable is not None:
device_info['network_os_image'] = re.split('[:|,]', ele_boot_variable.text)[1]
ele_package_name = etree_find(reply, 'package-name')
if ele_package_name is not None:
device_info['network_os_package'] = ele_package_name.text
device_info['network_os_version'] = re.split('-', ele_package_name.text)[-1]

hostname_filter = build_xml('host-names', opcode='filter')

reply = self.get(hostname_filter)
hostname_ele = etree_find(reply, 'host-name')
device_info['network_os_hostname'] = hostname_ele.text if hostname_ele is not None else None

try:
reply = self.get(install_filter)
resp = remove_namespaces(re.sub(r'<\?xml version="1.0" encoding="UTF-8"\?>', '', reply))
ele_boot_variable = etree_find(resp, 'boot-variable/boot-variable')
if ele_boot_variable is not None:
device_info['network_os_image'] = re.split('[:|,]', ele_boot_variable.text)[1]
ele_package_name = etree_find(reply, 'package-name')
if ele_package_name is not None:
device_info['network_os_package'] = ele_package_name.text
device_info['network_os_version'] = re.split('-', ele_package_name.text)[-1]

hostname_filter = build_xml('host-names', opcode='filter')
reply = self.get(hostname_filter)
resp = remove_namespaces(re.sub(r'<\?xml version="1.0" encoding="UTF-8"\?>', '', reply))
hostname_ele = etree_find(resp.strip(), 'host-name')
device_info['network_os_hostname'] = hostname_ele.text if hostname_ele is not None else None
except Exception as exc:
self._connection.queue_message('vvvv', 'Fail to retrieve device info %s' % exc)
return device_info

def get_capabilities(self):
Expand Down