HiRoLabブログ

HiRoのゆるふわIT備忘録

pyATS/Genieを導入して遊んでみる

やること

pyATS/GenieをインストールからCisco(IOS)-892サービス統合型ルータのバージョンを参照してみる。

環境構築

今回はVMware ESXiの仮想マシン(ubuntu)にpyATS/Genieを導入。 仮想マシンは下図を参照。

VMware ESXiに仮想マシン登録の記事はかけてない為、余力があれば記事を作成し本記事の更新を行う。

f:id:HiRo1325:20210211165724p:plain

まず最初に仮想環境を作る。

その為にpython3-venvのインストールを行う。

$ apt install python3-venv

pyatsディレクトリにて仮想環境を作成

$ python3 -m venv .

次にActivate

$ source bin/activate

ここまで出来たら、pyATS/Genieをインストールする。

インストールは下記コマンドで行う。

$ pip install pyats[full]

$ pip install genie[library]

$ pip install  xlrd xlwt xlsxwriter

Cisco(IOS)-892サービス統合型ルータのバージョン参照

Cisco(IOS)-892統合型ルータのホスト名、ユーザ名、IPアドレスを事前に設定しておく

ホスト名:R3 ユーザ名:cisco IPアドレス:192.168.100.23

次にgenie createコマンドにて対象機器のyamlファイルを作成する。 下記コマンド実行時に対話的に機器の情報を入力する必要がある。 詳細は下記を参照ください。

$ genie  create testbed --output yaml/testbed.yaml --encode-password

Start creating Testbed yaml file ...
Do all of the devices have the same username? [y/n] n
Do all of the devices have the same default password? [y/n] n
Do all of the devices have the same enable password? [y/n] n

Device hostname: R3
   IP (ip, or ip:port): 192.168.100.23
   Username: cisco
   Default Password (leave blank if you want to enter on demand): 
   Enable Password (leave blank if you want to enter on demand): 
   Protocol (ssh, telnet, ...): telnet
   OS (iosxr, iosxe, ios, nxos, linux, ...): ios
More devices to add ? [y/n] n
Testbed file generated: 
yaml/testbed.yaml 

ここまできたらようやくgenie parseにてshowコマンドを使用することができる。 genie parseコマンドの引数にshowコマンド、genie createで作成したyamlファイル、デバイスのホスト名を指定する。 今回はshow versionを行う。

$ genie parse "show version" --testbed-file yaml/testbed.yaml --devices R3

  0%|                                                                                               | 0/1 [00:00<?, ?it/s]{
  "version": {
    "chassis": "892",
    "chassis_sn": "FHK1451705J",
    "compiled_by": "prod_rel_team",
    "compiled_date": "Sun 02-Dec-18 13:05",
    "curr_config_register": "0x2102",
    "hostname": "R3",
    "image_id": "C890-UNIVERSALK9-M",
    "image_type": "production image",
    "last_reload_reason": "power-on",
    "last_reload_type": "Normal Reload",
    "license_level": "advipservices",
    "license_type": "Permanent",
    "license_udi": {},
    "main_mem": "498688",
    "mem_size": {
      "non-volatile configuration": "256"
    },
    "next_reload_license_level": "advipservices",
    "number_of_intfs": {
      "FastEthernet": "9",
      "Gigabit Ethernet": "1",
      "ISDN Basic Rate": "1"
    },
    "os": "IOS",
    "platform": "C890",
    "processor_board_flash": "250880K",
    "processor_type": "MPC8300",
    "returned_to_rom_by": "power-on",
    "rom": "System Bootstrap, Version 12.4(22r)YB3, RELEASE SOFTWARE (fc1)",
    "rtr_type": "892",
    "system_image": "flash:c890-universalk9-mz.150-1.M3.bin",
    "uptime": "4 weeks, 2 days, 19 hours, 1 minute",
    "version": "15.8(3)M1",
    "version_short": "15.8"
  }
}
100%|███████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  2.06it/s]

今回genie parseコマンドで指定するオプションなどはここまでとする。 別記事にて他のオプションを使用した記事を作成していく。 例えばoutputオプションなど。

参考ページ

参考にしたサイトは下記です。 genie parseで使用できるshowコマンドの記載がある。

developer.cisco.com