pyATS のコネクションライブラリ Unicon でネットワーク機器などに接続した場合、ネットワーク自動化に必要なコマンドの設定投入がデフォルトで行われます。
下記の例では show version や設定モードで no logging console や exec-timeout 0 などが投入されています。
>>> device = testbed.devices['R1_xe']
>>> device.connect(via='cli')
[2020-01-11 06:27:38,543] +++ R1_xe logfile /tmp/R1_xe-cli-20200111T062738539.log +++
[2020-01-11 06:27:38,543] +++ Unicon plugin iosxe +++
Trying 172.25.192.134...
[2020-01-11 06:27:38,660] +++ connection to spawn: telnet 172.25.192.134 17066, id: 4561073104 +++
[2020-01-11 06:27:38,661] connection to R1_xe
Won't send login name and/or authentication information.
Connected to asg-ucs4-virl.cisco.com.
Escape character is '^]'.
R1_xe#
[2020-01-11 06:27:39,496] +++ initializing handle +++
[2020-01-11 06:27:39,497] +++ R1_xe: executing command 'term length 0' +++
term length 0
R1_xe#
[2020-01-11 06:27:39,830] +++ R1_xe: executing command 'term width 0' +++
term width 0
R1_xe#
[2020-01-11 06:27:40,155] +++ R1_xe: executing command 'show version' +++
show version
Cisco IOS XE Software, Version 16.09.01
Cisco IOS Software [Fuji], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.9.1, RELEASE SOFTWARE (fc2)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2018 by Cisco Systems, Inc.
Compiled Tue 17-Jul-18 16:57 by mcpre
Cisco IOS-XE software, Copyright (c) 2005-2018 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
R1_xe uptime is 4 weeks, 20 hours, 17 minutes
Uptime for this control processor is 4 weeks, 20 hours, 19 minutes
System returned to ROM by reload
System image file is "bootflash:packages.conf"
Last reload reason: Reload Command
(snip)
If you require further assistance please contact us by sending email to
export@cisco.com.
License Level: ax
License Type: Default. No valid license found.
Next reload license Level: ax
cisco CSR1000V (VXE) processor (revision VXE) with 1217428K/3075K bytes of memory.
Processor board ID 96DAE4B1XJZ
7 Gigabit Ethernet interfaces
32768K bytes of non-volatile configuration memory.
3018864K bytes of physical memory.
7774207K bytes of virtual hard disk at bootflash:.
0K bytes of WebUI ODM Files at webui:.
Configuration register is 0x2102
R1_xe#
[2020-01-11 06:27:40,584] +++ R1_xe: config +++
config term
Enter configuration commands, one per line. End with CNTL/Z.
R1_xe(config)#no logging console
R1_xe(config)#line console 0
R1_xe(config-line)#exec-timeout 0
R1_xe(config-line)#end
R1_xe#
上記設定投入を行いたくない場合には、testbed.yaml に下記 argments を追加して init_exec_commands と init_config_commands に空のリスト'[]’ を指定することで何も送信しなくなります。
devices:
R1_xe:
os: iosxe
platform: iosxe
type: CSR1000v
alias: R1_xe
connections:
cli:
ip: 172.25.192.134
port: 17066
protocol: telnet
arguments:
init_exec_commands: []
init_config_commands: []
credentials:
default:
password: Cisc0123
username: admin
enable:
password: Cisc0123
変更後に再度 device.connect() をしてみると、何もコマンドが送信されていないのが確認できます。
(pyats)$ genie shell --testbed-file testbed.yaml
Welcome to Genie Interactive Shell
==================================
Python 3.7.6 (default, Jan 3 2020, 14:59:27)
[Clang 10.0.1 (clang-1001.0.46.4)]
>>> from genie.testbed import load
>>> testbed = load('tb.yaml')
-------------------------------------------------------------------------------
>>> device = testbed.devices['R1_xe']
>>> device.connect(via='cli')
[2020-01-11 07:49:42,829] +++ R1_xe logfile /tmp/R1_xe-cli-20200111T074942828.log +++
[2020-01-11 07:49:42,830] +++ Unicon plugin iosxe +++
Trying 172.25.192.134...
[2020-01-11 07:49:42,960] +++ connection to spawn: telnet 172.25.192.134 17066, id: 4508784528 +++
[2020-01-11 07:49:42,960] connection to R1_xe
Won't send login name and/or authentication information.
Connected to asg-ucs4-virl.cisco.com.
Escape character is '^]'.
C
welcome to pyATS/Genie!
User Access Verification
Username: admin
Password:
R1_xe>
[2020-01-11 07:49:44,904] +++ initializing handle +++
enable
Password:
R1_xe#>>>
terminal length 0 や exec-timeout 0 は自動化をする場合には設定しておく方がいいかと思いますし、あまり問題にならない設定なので気にしない人も多いかと思いますが、例えば運用監視などで設定権限が無い人が pyATS/Genie を使う場合や、設定変更が週末だけに限定されているなどの運用ポリシーやアカウント制限がある場合には init_exec_commands / init_config_commands の無効化が使えます。