ネットワーク自動化のツール、pyATS で書くtestbed.yaml (ネットワーク構成情報ファイル)のFAQ を作ってみ増田。ansible で言うところの inventory ファイルですね。
目次
Q: 最小限の testbed.yaml は?
下記は iosxe の例です。type は必須なので、何か入れましょう。type はデフォルトで何かに使われるというわけではないので、何でも構いません。
devices:
R1_xe:
os: iosxe
type: CSR1000v
connections:
cli:
ip: 10.1.1.1
protocol: ssh
credentials:
default:
password: Cisc0123
username: admin
enable:
password: Cisc0123
os は ios, iosxe, iosxr, nxos, junos などを指定します。pyATS connection library Unicon の ドキュメントから見つけることが可能です。
参考 : Supported Platforms
後は connections と credentials は接続情報として必要になります。
Q: connections に複数接続を書くことは可能?
testbed.yaml では各デバイスに対して複数のアクセス方法を記載することが可能です。例えば、console(telnet:コンソール経由), mgmt(telnet: 管理ネットワーク経由), ssh(ssh: 管理ネットワーク経由)など。
devices:
R1_xe:
(snip)
connections:
console:
ip: 10.1.1.1
protocol: telnet
port: 2001
mgmt:
ip: 192.168.1.1
protocol: telnet
ssh:
ip: 192.168.1.1
protocol: ssh
(snip)Q: connections にある via って何?
デバイスに対して複数コネクション方法がある場合に defaults として使うものを via 指定できます。
devices:
R1_xe:
(snip)
connections:
defaults:
via: ssh
console:
ip: 10.1.1.1
protocol: telnet
port: 2001
mgmt:
ip: 192.168.1.1
protocol: telnet
ssh:
ip: 192.168.1.1
protocol: ssh
(snip)複数のコネクションがある状態で via が無いと、どの接続を使うのか不明なため、下記のエラーが出ます。
>>> device.connect()
(snip)
ValueError: Unicon is not able to identify the connection to be used, Please use the "via" option to specify the connection block to useこの場合は、testbed.yaml の中に書かなくても、下記のように device.connect() へ via を指定することでもコネクションを指定しての接続が可能です。
>>> device.connect(via='cli')Q: 接続時のコマンド/設定を止めるのは?
コネクション配下に arguments に init_exec_commands / init_config_commands に空のリスト [] を設定することで何も設定できないようにできます。
devices:
R1_xe:
os: iosxe
platform: iosxe
type: CSR1000v
alias: R1_xe
connections:
cli:
ip: 192.168.1.1
port: 17066
protocol: telnet
arguments:
init_exec_commands: []
init_config_commands: []
credentials:
default:
password: cisco
username: admin
enable:
password: cisco