LoginSignup
5
4

More than 5 years have passed since last update.

Cisco IOS-XEで試す、はじめてのYDK

Last updated at Posted at 2017-06-11

YDKって何?

The YANG Development Kit (YDK) is a Software Development Kit that provides API’s that are modeled in YANG. The main goal of YDK is to reduce the learning curve of YANG data models by expressing the model semantics in an API and abstracting protocol/encoding details. YDK is composed of a core package that defines services and providers, plus one or more module bundles that are based on YANG models.

  • YANGモデルに対してAPIを提供してくれるSDK
  • プロトコル(SSHやNetconf)やエンコーディング(XML)を抽象化
  • YANGモデルの操作に集中でき、学習時間を大幅短縮できる
  • Ciscoが作って公開 ydk.io ydk.cisco.com
  • YANG? -> YANG ExplorerでYANGモデルに慣れる

背景

  • YANGモデルを理解するために、YANG ExplorerやPyangは役立つが、コードを書く場合、NCClientやYDKを使うことになる
  • NCClientの利用参考:Pythonでget_configその1
  • YDKはこれまで、IOS-XRの利用者中心に広まっていたが、2017/6/6あたりにIOS-XEバンドルAPIがリリースされ、IOS-XEでも気軽に試せるようになった

とりあえずこれだけ

  • YDK プロバイダモジュール .. 今のところNetconfServiceProviderのみ
  • YDK サービスモジュール
    • CRUDService .. YDKモジュールで作ったEntityのCRUD(Create/Read/Update/Delete)操作
    • NetconfService .. Netconf Operationの操作
    • CodecService .. Entityのエンコード、ペイロードのデコード
    • ExecutorService .. RPCの実行
  • YDK API
    • openconfig bundle API
    • cisco_ios_xe bundle API
    • cisco_ios_xr bundle API
    • ietf bundle API

※YANGはデータモデルなので特にNetconfに依存しないが、今のところNetconfのデータモデルとして使われている

インストール

楽ちんなやつ。環境によってエラーが出たら、適当に整える。

今回のメイン。

pip install ydk-models-cisco-ios-xe

ついでに入れとくやつ。

pip install ydk-models-cisco-ios-xe
pip install ydk-models-openconfig
pip install ydk-models-ietf

サンプルコード

ydk_test.py
import sys
from ydk.services import CRUDService
from ydk.providers import NetconfServiceProvider
from ydk.models.cisco_ios_xe import Cisco_IOS_XE_native as xe_native

provider = NetconfServiceProvider(address="10.71.130.57",port=830,username="cisco",password="cisco",protocol="ssh")
crud = CRUDService()

native = xe_native.Native()
native.hostname = sys.argv[1]
native.banner.motd.message = sys.argv[2]

crud.create(provider, native)

provider.close()
exit()
  • Netconf Provider作成(装置のアクセス情報)
  • YDK-IOS-XE APIを使って、Entity作成(ホスト名とバナーの設定)
  • CRUDサービスオブジェクトのCreateメソッドに、ProviderとEntityを入力

※ホスト名とバナーは、CLIの引数から補完

実行

~ $python3 ydk_test.py CSR1KV-1 "Hello, YDK"
cisco
Router#sh run | i banner
banner motd ^CHi, good morning^C
Router#
Router#
Router#
CSR1KV-1#
CSR1KV-1#sh run | i banner
banner motd ^CHello, YDK^C
CSR1KV-1#
CSR1KV-1#

シンプルな動作確認でした。

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4