Skip to content

Commit d0f875d

Browse files
authored
Adds implemented feature to support fastcli=False (#202)
1 parent 782e60e commit d0f875d

File tree

4 files changed

+309
-13
lines changed

4 files changed

+309
-13
lines changed

pyntc/devices/ios_device.py

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class IOSDevice(BaseDevice):
4646
vendor = "cisco"
4747
active_redundancy_states = {None, "active"}
4848

49-
def __init__(self, host, username, password, secret="", port=22, confirm_active=True, **kwargs):
49+
def __init__(self, host, username, password, secret="", port=22, confirm_active=True, fast_cli=True, **kwargs):
5050
"""
5151
PyNTC Device implementation for Cisco IOS.
5252
@@ -57,6 +57,7 @@ def __init__(self, host, username, password, secret="", port=22, confirm_active=
5757
secret (str): The password to escalate privilege on the device.
5858
port (int): The port to use to establish the connection.
5959
confirm_active (bool): Determines if device's high availability state should be validated before leaving connection open.
60+
fast_cli (bool): Fast CLI mode for Netmiko, it is recommended to use False when opening the client on code upgrades
6061
"""
6162
super().__init__(host, username, password, device_type="cisco_ios_ssh")
6263

@@ -65,6 +66,7 @@ def __init__(self, host, username, password, secret="", port=22, confirm_active=
6566
self.port = int(port)
6667
self.global_delay_factor = kwargs.get("global_delay_factor", 1)
6768
self.delay_factor = kwargs.get("delay_factor", 1)
69+
self._fast_cli = fast_cli
6870
self._connected = False
6971
self.open(confirm_active=confirm_active)
7072

@@ -133,11 +135,21 @@ def _get_file_system(self):
133135
raise FileSystemNotFoundError(hostname=self.hostname, command="dir")
134136

135137
# Get the version of the image that is booted into on the device
136-
def _image_booted(self, image_name, **vendor_specifics):
138+
def _image_booted(self, image_name, image_pattern=r".*\.(\d+\.\d+\.\w+)\.SPA.+", **vendor_specifics):
137139
version_data = self.show("show version")
138140
if re.search(image_name, version_data):
139141
return True
140142

143+
# Test for version number in the text, used on install mode devices that use packages.conf
144+
try:
145+
version_number = re.search(image_pattern, image_name).group(1)
146+
if version_number and version_number in version_data:
147+
return True
148+
# Continue on if regex is unable to find the result, which raises an attribute error
149+
except AttributeError:
150+
pass
151+
152+
# Unable to find the version number in output, the image is not booted.
141153
return False
142154

143155
def _interfaces_detailed_list(self):
@@ -277,8 +289,8 @@ def config(self, command, **netmiko_args):
277289
**netmiko_args: Any argument supported by ``netmiko.ConnectHandler.send_config_set``.
278290
279291
Returns:
280-
str: When ``command`` is a str, the config session input and ouput from sending ``command``.
281-
list: When ``command`` is a list, the config session input and ouput from sending ``command``.
292+
str: When ``command`` is a str, the config session input and output from sending ``command``.
293+
list: When ``command`` is a list, the config session input and output from sending ``command``.
282294
283295
Raises:
284296
TypeError: When sending an argument in ``**netmiko_args`` that is not supported.
@@ -350,7 +362,7 @@ def config_list(self, commands, **netmiko_args):
350362
**netmiko_args: Any argument supported by ``netmiko.ConnectHandler.send_config_set``.
351363
352364
Returns:
353-
list: Each command's input and ouput from sending the command in ``commands``.
365+
list: Each command's input and output from sending the command in ``commands``.
354366
355367
Raises:
356368
TypeError: When sending an argument in ``**netmiko_args`` that is not supported.
@@ -509,6 +521,15 @@ def config_register(self):
509521

510522
return self._config_register
511523

524+
@property
525+
def fast_cli(self):
526+
return self._fast_cli
527+
528+
@fast_cli.setter
529+
def fast_cli(self, value):
530+
self._fast_cli = value
531+
self.native.fast_cli = value
532+
512533
def file_copy(self, src, dest=None, file_system=None):
513534
self.enable()
514535
if file_system is None:
@@ -551,7 +572,7 @@ def file_copy_remote_exists(self, src, dest=None, file_system=None):
551572
return True
552573
return False
553574

554-
def install_os(self, image_name, install_mode=False, install_mode_delay_factor=10, **vendor_specifics):
575+
def install_os(self, image_name, install_mode=False, install_mode_delay_factor=20, **vendor_specifics):
555576
"""Installs the prescribed Network OS, which must be present before issuing this command.
556577
557578
Args:
@@ -570,6 +591,12 @@ def install_os(self, image_name, install_mode=False, install_mode_delay_factor=1
570591
# Change boot statement to be boot system <flash>:packages.conf
571592
self.set_boot_options(INSTALL_MODE_FILE_NAME, **vendor_specifics)
572593

594+
# Get the current fast_cli to set it back later to whatever it is
595+
current_fast_cli = self.fast_cli
596+
597+
# Set fast_cli to False to handle install mode, 10+ minute installation
598+
self.fast_cli = False
599+
573600
# Check for OS Version specific upgrade path
574601
# https://www.cisco.com/c/en/us/td/docs/switches/lan/catalyst9300/software/release/17-2/release_notes/ol-17-2-9300.html
575602
os_version = self.os_version
@@ -589,13 +616,18 @@ def install_os(self, image_name, install_mode=False, install_mode_delay_factor=1
589616
self.show(command, delay_factor=install_mode_delay_factor)
590617
except IOError:
591618
pass
619+
592620
else:
593621
self.set_boot_options(image_name, **vendor_specifics)
594622
self.reboot()
595623

596624
# Wait for the reboot to finish
597625
self._wait_for_device_reboot(timeout=timeout)
598626

627+
# Set FastCLI back to originally set when using install mode
628+
if install_mode:
629+
self.fast_cli = current_fast_cli
630+
599631
# Verify the OS level
600632
if not self._image_booted(image_name):
601633
raise OSInstallError(hostname=self.hostname, desired_boot=image_name)
@@ -624,13 +656,13 @@ def open(self, confirm_active=True):
624656
Open a connection to the network device.
625657
626658
This method will close the connection if ``confirm_active`` is True and the device is not active.
627-
Devices that do not have high availibility are considred active.
659+
Devices that do not have high availability are considered active.
628660
629661
Args:
630662
confirm_active (bool): Determines if device's high availability state should be validated before leaving connection open.
631663
632664
Raises:
633-
DeviceNotActiveError: When ``confirm_active`` is True, and the device high availabilit state is not active.
665+
DeviceNotActiveError: When ``confirm_active`` is True, and the device high availability state is not active.
634666
635667
Example:
636668
>>> device = IOSDevice(**connection_args)
@@ -662,6 +694,7 @@ def open(self, confirm_active=True):
662694
global_delay_factor=self.global_delay_factor,
663695
secret=self.secret,
664696
verbose=False,
697+
fast_cli=self.fast_cli,
665698
)
666699
self._connected = True
667700

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
Cisco IOS Software, C3750 Software (C3750-IPSERVICESK9-M), Version 15.0(2)SE11, RELEASE SOFTWARE (fc3)
2+
Technical Support: http://www.cisco.com/techsupport
3+
Copyright (c) 1986-2017 by Cisco Systems, Inc.
4+
Compiled Sat 19-Aug-17 09:28 by prod_rel_team
5+
6+
ROM: Bootstrap program is C3750 boot loader
7+
BOOTLDR: C3750 Boot Loader (C3750-HBOOT-M) Version 12.2(25r)SE1, RELEASE SOFTWARE (fc)
8+
9+
joshv-sw01 uptime is 30 weeks, 2 days, 6 hours, 5 minutes
10+
System returned to ROM by power-on
11+
System restarted at 16:23:49 CDT Sun Jul 19 2020
12+
System image file is "flash:/c3750-ipservicesk9-mz.150-2.SE11.bin"
13+
14+
15+
This product contains cryptographic features and is subject to United
16+
States and local country laws governing import, export, transfer and
17+
use. Delivery of Cisco cryptographic products does not imply
18+
third-party authority to import, export, distribute or use encryption.
19+
Importers, exporters, distributors and users are responsible for
20+
compliance with U.S. and local country laws. By using this product you
21+
agree to comply with applicable laws and regulations. If you are unable
22+
to comply with U.S. and local laws, return this product immediately.
23+
24+
A summary of U.S. laws governing Cisco cryptographic products may be found at:
25+
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html
26+
27+
If you require further assistance please contact us by sending email to
28+
29+
30+
cisco WS-C3750G-48PS (PowerPC405) processor (revision C0) with 131072K bytes of memory.
31+
Processor board ID FOC0948Y2RB
32+
Last reset from power-on
33+
4 Virtual Ethernet interfaces
34+
52 Gigabit Ethernet interfaces
35+
The password-recovery mechanism is enabled.
36+
37+
512K bytes of flash-simulated non-volatile configuration memory.
38+
Base ethernet MAC Address : 00:16:47:10:AF:00
39+
Motherboard assembly number : 73-9365-08
40+
Power supply part number : 341-0108-02
41+
Motherboard serial number : FOC09480D0A
42+
Power supply serial number : DCA09431730
43+
Model revision number : C0
44+
Motherboard revision number : A0
45+
Model number : WS-C3750G-48PS-E
46+
System serial number : FOC0948Y2RB
47+
SFP Module assembly part number : 73-7757-03
48+
SFP Module revision Number : A0
49+
SFP Module serial number : CAT094403WR
50+
Top Assembly Part Number : 800-26344-02
51+
Top Assembly Revision Number : B0
52+
Version ID : V02
53+
CLEI Code Number : CNMWM00ARB
54+
Hardware Board Revision Number : 0x05
55+
56+
57+
Switch Ports Model SW Version SW Image
58+
------ ----- ----- ---------- ----------
59+
* 1 52 WS-C3750G-48PS 15.0(2)SE11 C3750-IPSERVICESK9-M
60+
61+
62+
Configuration register is 0xF
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
Cisco IOS XE Software, Version 16.09.03
2+
Cisco IOS Software [Fuji], Catalyst L3 Switch Software (CAT9K_IOSXE), Version 16.9.3, RELEASE SOFTWARE (fc2)
3+
Technical Support: http://www.cisco.com/techsupport
4+
Copyright (c) 1986-2019 by Cisco Systems, Inc.
5+
Compiled Wed 20-Mar-19 08:02 by mcpre
6+
7+
8+
Cisco IOS-XE software, Copyright (c) 2005-2019 by cisco Systems, Inc.
9+
All rights reserved. Certain components of Cisco IOS-XE software are
10+
licensed under the GNU General Public License ("GPL") Version 2.0. The
11+
software code licensed under GPL Version 2.0 is free software that comes
12+
with ABSOLUTELY NO WARRANTY. You can redistribute and/or modify such
13+
GPL code under the terms of GPL Version 2.0. For more details, see the
14+
documentation or "License Notice" file accompanying the IOS-XE software,
15+
or the applicable URL provided on the flyer accompanying the IOS-XE
16+
software.
17+
18+
19+
ROM: IOS-XE ROMMON
20+
BOOTLDR: System Bootstrap, Version 16.9.1r [FC2], RELEASE SOFTWARE (P)
21+
22+
AKBTESTW01 uptime is 1 year, 22 weeks, 6 days, 9 hours, 38 minutes
23+
Uptime for this control processor is 1 year, 22 weeks, 6 days, 9 hours, 44 minutes
24+
System returned to ROM by Reload Command at 22:09:11 NZST Wed May 1 2019
25+
System restarted at 22:16:13 NZST Wed May 1 2019
26+
System image file is "flash:packages.conf"
27+
Last reload reason: Reload Command
28+
29+
30+
31+
This product contains cryptographic features and is subject to United
32+
States and local country laws governing import, export, transfer and
33+
use. Delivery of Cisco cryptographic products does not imply
34+
third-party authority to import, export, distribute or use encryption.
35+
Importers, exporters, distributors and users are responsible for
36+
compliance with U.S. and local country laws. By using this product you
37+
agree to comply with applicable laws and regulations. If you are unable
38+
to comply with U.S. and local laws, return this product immediately.
39+
40+
A summary of U.S. laws governing Cisco cryptographic products may be found at:
41+
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html
42+
43+
If you require further assistance please contact us by sending email to
44+
45+
46+
47+
Technology Package License Information:
48+
49+
------------------------------------------------------------------------------
50+
Technology-package Technology-package
51+
Current Type Next reboot
52+
------------------------------------------------------------------------------
53+
network-advantage Smart License network-advantage
54+
dna-advantage Subscription Smart License dna-advantage
55+
56+
57+
Smart Licensing Status: UNREGISTERED/EVAL EXPIRED
58+
59+
cisco C9500-40X (X86) processor with 1419496K/6147K bytes of memory.
60+
Processor board ID FCW2233FFG3
61+
16 Virtual Ethernet interfaces
62+
96 Ten Gigabit Ethernet interfaces
63+
4 Forty Gigabit Ethernet interfaces
64+
2048K bytes of non-volatile configuration memory.
65+
16777216K bytes of physical memory.
66+
1638400K bytes of Crash Files at crashinfo:.
67+
1638400K bytes of Crash Files at crashinfo-2:.
68+
11264000K bytes of Flash at flash:.
69+
11264000K bytes of Flash at flash-2:.
70+
0K bytes of WebUI ODM Files at webui:.
71+
72+
Base Ethernet MAC Address : 0c:d0:f8:cd:b5:80
73+
Motherboard Assembly Number : 73-18140-03
74+
Motherboard Serial Number : FOC223855F9
75+
Model Revision Number : D0
76+
Motherboard Revision Number : B0
77+
Model Number : C9500-40X
78+
System Serial Number : FCW2233FFG3
79+
80+
81+
Switch Ports Model SW Version SW Image Mode
82+
------ ----- ----- ---------- ---------- ----
83+
* 1 50 C9500-40X 16.9.3 CAT9K_IOSXE INSTALL
84+
2 50 C9500-40X 16.9.3 CAT9K_IOSXE INSTALL
85+
86+
87+
Switch 02
88+
---------
89+
Switch uptime : 1 year, 22 weeks, 6 days, 9 hours, 47 minutes
90+
91+
Base Ethernet MAC Address : 70:35:09:dd:20:00
92+
Motherboard Assembly Number : 73-11122-03
93+
Motherboard Serial Number : FOC234567Y9
94+
Model Revision Number : D0
95+
Motherboard Revision Number : B0
96+
Model Number : C9500-40X
97+
System Serial Number : FCW1234F88V
98+
99+
Configuration register is 0x102

0 commit comments

Comments
 (0)