napalm-automation / napalm-ios

Apache License 2.0
31 stars 40 forks source link

get_facts traceback on IOS-XE device #51

Closed clay584 closed 7 years ago

clay584 commented 7 years ago

When trying to do a get_facts on an IOS-XE device, I am getting a traceback.

>>> import napalm
>>> driver = napalm.get_network_driver('ios')
>>> device = driver(hostname='router1', username='ccurtis', password='Password1')
>>> device.open()
>>> device.get_facts()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/napalm_ios/ios.py", line 513, in get_facts
    _, os_version = line.split("Cisco IOS Software, ")
ValueError: need more than 1 value to unpack
>>> 

It is due to the fact that I am running Denali code (16.3.1a) on this device for MPLS support. This is what I did to fix it, but you can probably patch it in a more graceful manner as opposed to ignoring an exception.

if re.search(r"Cisco IOS Software", line):
    try:
        _, os_version = line.split("Cisco IOS Software, ")
    except:
        pass
    try:
        _, os_version = line.split("Cisco IOS Software ")
    except:
        pass
    os_version = os_version.strip()

show version output:

Cisco IOS Software [Denali], Catalyst L3 Switch Software (CAT3K_CAA-UNIVERSALK9-M), Version 16.3.1a, RELEASE SOFTWARE (fc4)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2016 by Cisco Systems, Inc.
Compiled Thu 29-Sep-16 22:08 by mcpre    

Cisco IOS-XE software, Copyright (c) 2005-2016 by cisco Systems, Inc.
All rights reserved.  Certain components of Cisco IOS-XE software are
licensed under the GNU General Public License ("GPL") Version 2.0.  The
software code licensed under GPL Version 2.0 is free software that comes
with ABSOLUTELY NO WARRANTY.  You can redistribute and/or modify such
GPL code under the terms of GPL Version 2.0.  For more details, see the
documentation or "License Notice" file accompanying the IOS-XE software,
or the applicable URL provided on the flyer accompanying the IOS-XE
software.    

ROM: IOS-XE ROMMON
BOOTLDR: CAT3K_CAA Boot Loader (CAT3K_CAA-HBOOT-M) Version 3.78, RELEASE SOFTWARE (P)    

fauhousing3850-01 uptime is 5 days, 4 hours, 13 minutes
Uptime for this control processor is 5 days, 4 hours, 15 minutes
System returned to ROM by reload at 14:27:42 UTC Wed Oct 12 2016
System image file is "flash:cat3k_caa-universalk9.16.03.01a.SPA.bin"
Last reload reason: Reload Command    

This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.    

A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html    

If you require further assistance please contact us by sending email to
export@cisco.com.    

Technology Package License Information:     

-----------------------------------------------------------------
Technology-package                   Technology-package
Current             Type             Next reboot  
------------------------------------------------------------------
ipservicesk9        Permanent        ipservicesk9    

cisco WS-C3850-12XS (MIPS) processor (revision K0) with 866081K/6147K bytes of memory.
Processor board ID FOC2028U0P2
1 Virtual Ethernet interface
16 Ten Gigabit Ethernet interfaces
2048K bytes of non-volatile configuration memory.
4194304K bytes of physical memory.
253984K bytes of Crash Files at crashinfo:.
3431232K bytes of Flash at flash:.
0K bytes of  at webui:.    

Base Ethernet MAC Address          : 00:a2:89:56:f1:80
Motherboard Assembly Number        : 73-16295-06
Motherboard Serial Number          : FOC20276N1P
Model Revision Number              : K0
Motherboard Revision Number        : A0
Model Number                       : WS-C3850-12XS
System Serial Number               : FOC2029U0K2    

Switch Ports Model              SW Version        SW Image              Mode   
------ ----- -----              ----------        ----------            ----   
*    1 16    WS-C3850-12XS      16.3.1            CAT3K_CAA-UNIVERSALK9 BUNDLE     

Configuration register is 0x102

After the fix:

>>> import napalm
>>> driver = napalm.get_network_driver('ios')
>>> device = driver(hostname='router1', username='ccurtis', password='Password1')
>>> 
>>> device.open()
>>> device.get_facts()
{'os_version': u'[Denali], Catalyst L3 Switch Software (CAT3K_CAA-UNIVERSALK9-M), Version 16.3.1a, RELEASE SOFTWARE (fc4)', 'uptime': 447060, 'interface_list': [u'Vlan1', u'GigabitEthernet0/0', u'Te1/0/1', u'Te1/0/2', u'Te1/0/3', u'Te1/0/4', u'Te1/0/5', u'Te1/0/6', u'Te1/0/7', u'Te1/0/8', u'Te1/0/9', u'Te1/0/10', u'Te1/0/11', u'Te1/0/12', u'Te1/1/1', u'Te1/1/2', u'Te1/1/3', u'Te1/1/4', u'Loopback0', u'Loopback112', u'Loopback122', u'Loopback132', u'Loopback142', u'Loopback152', u'Loopback162', u'Loopback182', u'Loopback192'], 'vendor': u'Cisco', 'serial_number': u'FOC2029U0K2', 'model': u'WS-C3850-12XS', 'hostname': u'router1', 'fqdn': u'router1.xxx.edu'}
>>> quit()
ktbyers commented 7 years ago

Okay will try to look at it. Should be easy to fix.

ktbyers commented 7 years ago

@clay584 Please test the fix referenced above.

clay584 commented 7 years ago

It fixed it. Thanks Kirk! BTW, your python class is paying off. It was a very good primer for me. I am using napalm, ntc-ansible, and other bits to automate the deployment and operation of an MPLS network for a large university. Pretty cool stuff.

ktbyers commented 7 years ago

Nice...