CML2 を cmlutils で CML から操作する
cmlutils を使うと Cisco CML2 に関連する操作を CML から行うことが出来ます。
cmlutil の準備¶
cmlutil は Python で書かれている為、予め Python3 がインストールされている必要があります。
Python3 のインストール¶
Python3 をインストールします。
cmlutils のインストール¶
pip で cmlutils をインストールします。
mkdir cml
cd cml
python -m venv .
source bin/activate
python -m pip install --upgrade pip setuptools
python -m pip install cmlutils
認証情報を用意する¶
CML2 へのログイン用 認証情報は以下の 3 種類で指定することが出来ます。
- 環境変数として定義する
- 現在のディレクトリに
.virlrcファイルを作成して定義する - ホームディレクトリに
.virlrcファイルを作成して定義する
ホームディレクトリに定義しておく場合、以下のようにファイルを用意します。 CML2 のデフォルト状態だと Web UI で自己証明書を使っており、接続時にエラーになってしまいます。 その為、CML_VERIFY_CERT=false を指定して証明書のエラーを回避します。
cat << 'EOF' > ~/.virlrc
VIRL_HOST=10.0.0.1
VIRL_USERNAME=admin
VIRL_PASSWORD=password
CML_VERIFY_CERT=false
EOF
cmlutils のコマンド¶
cmlutils でよく使うコマンドをピックアップしておきます。
| 目的 | 対象 | コマンド |
|---|---|---|
| ラボ一覧を表示する | - | cml ls |
| ラボを選択する | - | cml use --id [ID] |
| ラボを未選択状態にする | - | cml clear |
| 選択中のラボ ID を表示する | - | cml id |
| ラボを開始する | 選択中のラボ | cml up |
| ラボを開始する | ID 指定したラボ | cml up --id [ID] |
| ラボを停止する | 選択中のラボ | cml down |
| ラボを停止する | ID 指定したラボ | cml up --down [ID] |
| ラボをワイプする | 選択中のラボ | cml wipe lab |
| ラボをワイプする (確認無し) | 選択中のラボ | cml wipe lab --no-confirm |
| ラボを削除する | 選択中のラボ | cml rm |
| ラボを削除する | 選択中のラボ | cml rm --no-confirm |
| ノード一覧を表示する | 選択中のラボ | cml nodes |
| ノードを開始する | 選択中のラボ | cml start [LABEL] |
| ノードを停止する | 選択中のラボ | cml stop [LABEL] |
| ノードをワイプする | 選択中のラボ | cml wipe node [LABEL] |
| ノードをワイプする (確認無し) | 選択中のラボ | cml wipe node [LABEL] --no-confirm |
| ノードへコンソール接続する | 選択中のラボ | cml console [LABEL] |
| ノードへ TELNET する | 選択中のラボ | cml telnet [LABEL] |
コンソール接続時に no matching cipher found エラーになる場合¶
コンソール接続時、以下のように no matching cipher found エラーが表示される場合があります。
# cml console iosv-0
Unable to negotiate with 10.0.0.1 port 22: no matching cipher found. Their offer: aes128-gcm@openssh.com,chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr
このような場合は /etc/ssh/ssh_config.d/98_cml.conf もしくは ~/.ssh/config へ下記を追加します。
参考¶
cmlutils のヘルプ¶
# cml --help
Usage: cml [OPTIONS] COMMAND [ARGS]...
Options:
--debug / --no-debug Print any debugging output.
--help Show this message and exit.
Commands:
clear clear the current lab ID
cockpit opens the Cockpit UI
command send a command or config to a node (requires pyATS)
console console for node
definitions manage image and node definitions
down stop a lab
extract extract configurations from all nodes in a lab
generate generate inv file for various tools
id get the current lab title and ID
license work with product licensing
ls lists running labs and optionally those in the cache
nodes get node list for the current lab
pull pull topology.yaml from repo
rm remove a lab
save save lab to a local yaml file
search list topologies available via github
ssh ssh to a node
start start a node
stop stop a node
telnet telnet to a node
ui opens the Workbench for the current lab
up start a lab
use use lab launched elsewhere
version version information
wipe wipe a lab or nodes within a lab