Fix iosxr netconf plugin get device info (#65489)
* Fix iosxr netconf plugin get device info Fixes https://github.com/ansible/ansible/issues/64634 * Catch execption if the xml payload to get device info is not valid for iosxr version running on remote host. * Fix CI issue
This commit is contained in:
parent
9a81f5c3b7
commit
3919a891c2
1 changed files with 17 additions and 15 deletions
|
@ -55,22 +55,24 @@ class Netconf(NetconfBase):
|
||||||
])
|
])
|
||||||
|
|
||||||
install_filter = build_xml('install', install_meta, opcode='filter')
|
install_filter = build_xml('install', install_meta, opcode='filter')
|
||||||
|
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]
|
||||||
|
|
||||||
reply = self.get(install_filter)
|
hostname_filter = build_xml('host-names', opcode='filter')
|
||||||
ele_boot_variable = etree_find(reply, 'boot-variable/boot-variable')
|
reply = self.get(hostname_filter)
|
||||||
if ele_boot_variable is not None:
|
resp = remove_namespaces(re.sub(r'<\?xml version="1.0" encoding="UTF-8"\?>', '', reply))
|
||||||
device_info['network_os_image'] = re.split('[:|,]', ele_boot_variable.text)[1]
|
hostname_ele = etree_find(resp.strip(), 'host-name')
|
||||||
ele_package_name = etree_find(reply, 'package-name')
|
device_info['network_os_hostname'] = hostname_ele.text if hostname_ele is not None else None
|
||||||
if ele_package_name is not None:
|
except Exception as exc:
|
||||||
device_info['network_os_package'] = ele_package_name.text
|
self._connection.queue_message('vvvv', 'Fail to retrieve device info %s' % exc)
|
||||||
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
|
|
||||||
|
|
||||||
return device_info
|
return device_info
|
||||||
|
|
||||||
def get_capabilities(self):
|
def get_capabilities(self):
|
||||||
|
|
Loading…
Reference in a new issue