キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 
cancel
9499
閲覧回数
5
いいね!
0
コメント
Hiromasa Kakehashi
Cisco Employee
Cisco Employee

netconf-console は Python ベースの NETCONF のテストツールです。

この記事では、netconf-console の主な使い方を紹介します。

 

入手方法

NSO/NCS のインストーラに含まれています。
インストール後、NSO/NCS のインストールディレクトリの bin 配下に展開されます。

Github にも公開されています。
※ netconf-console は動作上、NSO/NCS の機能には依存していません。
     後述する Python の依存関係を満たしていれば動作します。

 

動作環境

netconf-console は以下の環境で動作します。

  • Python 2.3+
  • paramiko
  • xmllint

 

使い方

 

1. Help

-h オプションでコマンドのシンタックスやオプションを確認することができます。

$ netconf-console -h
Usage: netconf-console [-h | --help] [options] [cmdoptions | <filename> | -]

Where <filename> is a file containing a NETCONF XML command session.
If <filename> is not given, one of the Command Options must be given.
Filename '-' means standard input.


Options:
-h, --help show this help message and exit

( snip )

 

2. hello

--hello を使って、NETCONFサーバの Capability を確認することができます。

$ netconf-console --host 192.168.0.1 --port 2022 -u admin -p admin --hello
<?xml version="1.0" encoding="UTF-8"?>
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<capabilities>
<capability>urn:ietf:params:netconf:base:1.0</capability>
<capability>urn:ietf:params:netconf:base:1.1</capability>
<capability>urn:ietf:params:netconf:capability:writable-running:1.0</capability>
<capability>urn:ietf:params:netconf:capability:xpath:1.0</capability>
<capability>urn:ietf:params:netconf:capability:validate:1.0</capability>

( snip )

</capabilities>
<session-id>33</session-id>
</hello>

 

3. get-config

--get-config を使ってデバイスのコンフィグを取得することができます。
応答に含まれる情報は --xpath オプションによってフィルタリングすることができます。

この例では /devices/device 配下の CE01 のコンフィグを取得しています。

$ netconf-console --host 192.168.0.1 --port 2022 -u admin -p admin --get-config --xpath /devices/device[name=\"CE01\"]
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<data>
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>CE01</name>
<address>127.0.0.1</address>
<port>10023</port>

( snip )

</device>
</devices>
</data>
</rpc-reply>

 

4. get

--get を使ってデバイスの状態を取得することができます。
応答に含まれる情報は --xpath オプションによってフィルタリングすることができます。

この例では、/ncs-state を指定して NSO の状態を確認しています。

$ netconf-console --host 192.168.0.1 --port 2022 -u admin -p admin --get --xpath /ncs-state
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<data>
<ncs-state xmlns="http://tail-f.com/yang/ncs-monitoring">
<patches>
<patches-directory>/var/shared/ncs/nso-4.2.1/lib/ncs/patches</patches-directory>
</patches>
<version>4.2.1</version>
<epoll>true</epoll>
<daemon-status>started</daemon-status>
<loaded-data-models>
<data-model>
<name>IANA-ITU-ALARM-TC-MIB</name>
<revision>2004-09-09</revision>

( snip )

</client>
<client>
<name>ncsMain-alCdb</name>
<type>inactive</type>
</client>
</cdb>
</internal>
</ncs-state>
</data>
</rpc-reply>

 

5. get-schema

--get-schema を使うと NETCONFサーバから、指定した Yang モデルを取得することができます。

$ netconf-console --host 192.168.0.1 --port 2022 -u admin -p admin --get-schema=tailf-ned-cisco-ios
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<data xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring"><![CDATA[// =========================================================================
// CISCO-IOS NED
// =========================================================================

module tailf-ned-cisco-ios {
namespace "urn:ios";
prefix ios;

import tailf-common {
prefix tailf;
}
import ietf-inet-types {
prefix inet;
}
import ietf-yang-types {
prefix yang;
}


// =========================================================================
// REVISION
// =========================================================================

revision 2014-02-12 {
description
"Fixed show live-status for interfaces.";
}

( snip )

/// ========================================================================
// EOF
/// ========================================================================

}
]]></data>
</rpc-reply>

NSO に get-schema を実施する場合の注意事項

NSO は load-path に追加された Yang ファイルについてのみ get-schema の応答を返します。 load-path への Yang ファイルの追加は以下のいずれかの方法で行います。

(1) ncs.conf

 <!-- Where to look for .fxs and snmp .bin files to load -->

<load-path>
<dir>./packages</dir>
<dir>${NCS_DIR}/etc/ncs</dir>

<!-- To disable northbound snmp altogether -->
<!-- comment out the path below -->
<dir>${NCS_DIR}/etc/ncs/snmp</dir>
<dir>./packages/cisco-ios/src/yang</dir> <<< IOS NED の Yang モデルを追加
<dir>./packages/cisco-iosxr/src/yang</dir> <<< IOS-XR NED の Yang モデルを追加
</load-path>

(2) ncs --addloadpath オプション

$ ncs --addloadpath ./packages/cisco-ios/src/yang --addloadpath ./packages/cisco-iosxr/src/yang

load-path の追加結果は、show netconf-state schemas コマンドで確認できます。

admin@ncs# show netconf-state schemas
IDENTIFIER VERSION FORMAT
-----------------------------------------------
tailf-ned-cisco-ios 2014-02-12 yang
tailf-ned-cisco-ios-id yang
tailf-ned-cisco-ios-stats yang
tailf-ned-cisco-ios-xr 2014-02-18 yang
tailf-ned-cisco-ios-xr-id yang

 

6. rpc

--rpc オプションを使って RPC コマンド が記述された XMLファイルを読み込ませることができます。
XMLファイルには <rpc> </rpc> の内側の要素を記載します。

$ netconf-console --host 192.168.0.1 --port 2022 -u admin -p admin --rpc=./rpc.xml
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<ok/>
</rpc-reply>

rpc.xml

<edit-config>
<target>
<running/>
</target>
<config xmlns="http://tail-f.com/ns/config/1.0">
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>CE01</name>
<config>
<interface xmlns="urn:ios">
<Loopback>
<name>0</name>
<ip>
<address>
<primary>
<address>10.0.0.11</address>
<mask>255.255.255.255</mask>
</primary>
</address>
</ip>
</Loopback>
</interface>
</config>
</device>
</devices>
</config>
</edit-config>

 

7. Complete form

オプション無しで XML ファイルを読み込ませることもできます。
この場合、指定するファイルには NETCONF の XMLペイロードと同等の内容をふくめます。

$ netconf-console --host 192.168.0.1 --port 2022 -u admin -p admin ./complete-form.xml
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<ok/>
</rpc-reply>
<?xml version="1.0" encoding="UTF-8"?>
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<capabilities>
<capability>urn:ietf:params:netconf:base:1.0</capability>
</capabilities>
</hello>
]]>]]>
<?xml version="1.0" encoding="UTF-8"?>
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<edit-config>
<target>
<running/>
</target>
<config xmlns="http://tail-f.com/ns/config/1.0">
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>CE01</name>
<config>
<interface xmlns="urn:ios">
<Loopback>
<name>0</name>
<ip>
<address>
<primary>
<address>10.0.0.11</address>
<mask>255.255.255.255</mask>
</primary>
</address>
</ip>
</Loopback>
</interface>
</config>
</device>
</devices>
</config>
</edit-config>
</rpc>
]]>]]>
<?xml version="1.0" encoding="UTF-8"?>
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<close-session/>
</rpc>

 

8. Event stream のサブスクリプション

--create-subscription で event stream をサブスクライブすると netconf-console は NETCONF Notification の受信待ち状態にはいります。

この例では NSO の ncs-alarms をサブスクライブした後に、NSO が管理しているデバイスを停止して NETCONF Notification を発生させています。

$ netconf-console --host 192.168.0.1 --port 2022 -u admin -p admin --create-subscription=ncs-alarms
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<ok/>
</rpc-reply>

===== デバイス停止 =====

<notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
<eventTime>2016-10-24T02:58:46.398353-07:00</eventTime>
<alarm-notification xmlns="http://tail-f.com/ns/ncs-alarms">
<alarm-class>changed-alarm</alarm-class>
<device>www0</device>
<type xmlns:al="http://tail-f.com/ns/ncs-alarms">al:connection-failure</type>
<managed-object xmlns:ncs="http://tail-f.com/ns/ncs">/ncs:devices/ncs:device[ncs:name='www0']</managed-object>
<specific-problem/>
<event-type>communicationsAlarm</event-type>
<has-clear>true</has-clear>
<kind-of-alarm>root-cause</kind-of-alarm>
<probable-cause>0</probable-cause>
<event-time>2016-10-24T09:58:46.366746+00:00</event-time>
<perceived-severity>major</perceived-severity>
<alarm-text>Failed to connect to device www0: connection refused</alarm-text>
</alarm-notification>
</notification>
<?xml version="1.0" encoding="UTF-8"?>
<notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
<eventTime>2016-10-24T02:58:46.401895-07:00</eventTime>
<alarm-notification xmlns="http://tail-f.com/ns/ncs-alarms">
<alarm-class>changed-alarm</alarm-class>
<device>www0</device>
<type xmlns:al="http://tail-f.com/ns/ncs-alarms">al:connection-failure</type>
<managed-object xmlns:ncs="http://tail-f.com/ns/ncs">/ncs:devices/ncs:device[ncs:name='www0']</managed-object>
<specific-problem/>
<event-type>communicationsAlarm</event-type>
<has-clear>true</has-clear>
<kind-of-alarm>root-cause</kind-of-alarm>
<probable-cause>0</probable-cause>
<event-time>2016-10-24T09:58:46.366746+00:00</event-time>
<perceived-severity>major</perceived-severity>
<alarm-text>Failed to connect to device www0: connection refused</alarm-text>
</alarm-notification>
</notification>

NSO の CLI から event stream を確認する方法

NSO の event stream は以下のコマンドで確認できます。

admin@ncs# show netconf streams
REPLAY REPLAY LOG CREATION
NAME DESCRIPTION SUPPORT TIME REPLAY LOG AGED TIME
-----------------------------------------------------------------------------(snip)
NETCONF default NETCONF event stream false - -
ncs-alarms NCS alarms according to tailf-ncs-alarms.yang false - -
ncs-events NCS event according to tailf-ncs-devices.yang true 2016-10-24T09: (snip)
device-notifications NCS events forwarded from devices true 2016-10-24T09:13 (snip)

 

9. Interactive モード

-i オプションを使うと対話形式で RPC コマンドを送ることができます。
シーケンシャルな動作を確認したい場合や、XMLのコピー&ペーストを繰り返し行いたいときに便利です。

$ netconf-console --host 192.168.0.1 --port 2022 -u admin -p admin -i

* Enter a NETCONF operation, end with an empty line

===== Loopback0 に IPアドレスを設定 =====

<edit-config>
<target>
<running/>
</target>
<config xmlns="http://tail-f.com/ns/config/1.0">
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>CE01</name>
<config>
<interface xmlns="urn:ios">
<Loopback>
<name>0</name>
<ip>
<address>
<primary>
<address>10.0.0.1</address>
<mask>255.255.255.255</mask>
</primary>
</address>
</ip>
</Loopback>
</interface>
</config>
</device>
</devices>
</config>
</edit-config>

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<ok/>
</rpc-reply>

* Enter a NETCONF operation, end with an empty line

===== 変更結果を確認 =====

<get-config>
<source>
<running/>
</source>
<filter type="subtree">
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>CE01</name>
<config>
<interface xmlns="urn:ios">
<Loopback>
<name>0</name>
</Loopback>
</interface>
</config>
</device>
</devices>
</filter>
</get-config>

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<data>
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>CE01</name>
<config>
<interface xmlns="urn:ios">
<Loopback>
<name>0</name>
<ip>
<address>
<primary>
<address>10.0.0.1</address>
<mask>255.255.255.255</mask>
</primary>
</address>
</ip>
</Loopback>
</interface>
</config>
</device>
</devices>
</data>
</rpc-reply>

* Enter a NETCONF operation, end with an empty line

Two-phase commit の例 (1) --- abort-transaction ---

この例では Interactive モードで NSO に実装されている NETCONF transaction の拡張機能(※)を使って、Two-phase commit の動作確認を行っています。

tailf-netconf-transactions.yang で定義されています。

$ netconf-console --host 192.168.0.1 --port 2022 -u admin -p admin -i

* Enter a NETCONF operation, end with an empty line

===== start-transaction =====

<start-transaction xmlns="http://tail-f.com/ns/netconf/transactions/1.0">
<target>
<running/>
</target>
</start-transaction>

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<ok/>
</rpc-reply>

* Enter a NETCONF operation, end with an empty line

===== edit-config / IP を 10.0.0.254 に変更 =====


<edit-config>

<target>
<running/>
</target>
<config xmlns="http://tail-f.com/ns/config/1.0">
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>CE01</name>
<config>
<interface xmlns="urn:ios">
<Loopback>
<name>0</name>
<ip>
<address>
<primary>
<address>10.0.0.254</address>
<mask>255.255.255.255</mask>
</primary>
</address>
</ip>
</Loopback>
</interface>
</config>
</device>
</devices>
</config>
</edit-config>

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<ok/>
</rpc-reply>

* Enter a NETCONF operation, end with an empty line

===== abort-transaction =====

<abort-transaction

xmlns="http://tail-f.com/ns/netconf/transactions/1.0"/>

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<ok/>
</rpc-reply>

* Enter a NETCONF operation, end with an empty line

===== get-config / IP が変わっていないことを確認 =====

<get-config>

<source>
<running/>
</source>
<filter type="subtree">
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>CE01</name>
<config>
<interface xmlns="urn:ios">
<Loopback>
<name>0</name>
</Loopback>
</interface>
</config>
</device>
</devices>
</filter>
</get-config>

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<data>
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>CE01</name>
<config>
<interface xmlns="urn:ios">
<Loopback>
<name>0</name>
<ip>
<address>
<primary>
<address>10.0.0.1</address>
<mask>255.255.255.255</mask>
</primary>
</address>
</ip>
</Loopback>
</interface>
</config>
</device>
</devices>
</data>
</rpc-reply>

Two-phase commit の例 (2) --- commit-transaction ---

* Enter a NETCONF operation, end with an empty line

===== start transaction =====

<start-transaction xmlns="http://tail-f.com/ns/netconf/transactions/1.0">

<target>
<running/>
</target>
</start-transaction>

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<ok/>
</rpc-reply>

* Enter a NETCONF operation, end with an empty line

===== edit-config / IP を 10.0.0.254 に変更 =====

<edit-config>

<target>
<running/>
</target>
<config xmlns="http://tail-f.com/ns/config/1.0">
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>CE01</name>
<config>
<interface xmlns="urn:ios">
<Loopback>
<name>0</name>
<ip>
<address>
<primary>
<address>10.0.0.254</address>
<mask>255.255.255.255</mask>
</primary>
</address>
</ip>
</Loopback>
</interface>
</config>
</device>
</devices>
</config>
</edit-config>

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<ok/>
</rpc-reply>

* Enter a NETCONF operation, end with an empty line

===== prepare-transaction =====

<prepare-transaction

xmlns="http://tail-f.com/ns/netconf/transactions/1.0"/>

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<ok/>
</rpc-reply>

* Enter a NETCONF operation, end with an empty line

===== commit-transaction =====

<commit-transaction

xmlns="http://tail-f.com/ns/netconf/transactions/1.0"/>

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<ok/>
</rpc-reply>

* Enter a NETCONF operation, end with an empty line

===== get-config / IP が変わっていることを確認 =====

<get-config>

<source>
<running/>
</source>
<filter type="subtree">
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>CE01</name>
<config>
<interface xmlns="urn:ios">
<Loopback>
<name>0</name>
</Loopback>
</interface>
</config>
</device>
</devices>
</filter>
</get-config>

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<data>
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>CE01</name>
<config>
<interface xmlns="urn:ios">
<Loopback>
<name>0</name>
<ip>
<address>
<primary>
<address>10.0.0.254</address>
<mask>255.255.255.255</mask>
</primary>
</address>
</ip>
</Loopback>
</interface>
</config>
</device>
</devices>
</data>
</rpc-reply>

Two-phase commit の例 (3) --- dry-run ---

この例では NETCONF API から edit-config を発行したあとに NSO の dry-run 機能を使用して変更内容を確認しています。

$ netconf-console --host 192.168.0.1 --port 2022 -u admin -p admin -i

* Enter a NETCONF operation, end with an empty line

===== start-transaction =====

<start-transaction xmlns="http://tail-f.com/ns/netconf/transactions/1.0">
<target>
<running/>
</target>
</start-transaction>

<?xml version="1.0" encoding="UTF-8"?> <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2"> <ok/> </rpc-reply>
* Enter a NETCONF operation, end with an empty line

===== edit-config / IP を 10.0.0.254 に変更 =====
<edit-config> <target> <running/> </target> <config xmlns="http://tail-f.com/ns/config/1.0"> <devices xmlns="http://tail-f.com/ns/ncs"> <device> <name>ios</name> <config> <interface xmlns="urn:ios"> <Loopback> <name>0</name> <ip> <address> <primary> <address>10.0.0.254</address> <mask>255.255.255.255</mask> </primary> </address> </ip> </Loopback> </interface> </config> </device> </devices> </config> </edit-config>

<?xml version="1.0" encoding="UTF-8"?> <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2"> <ok/> </rpc-reply>

* Enter a NETCONF operation, end with an empty line

===== dry-run(prepare-transaction) =====

<prepare-transaction xmlns="http://tail-f.com/ns/netconf/transactions/1.0"> <dryrun xmlns="http://tail-f.com/ns/netconf/ncs"> <outformat>native</outformat> </dryrun> </prepare-transaction> <?xml version="1.0" encoding="UTF-8"?> <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2"> <dryrun-result xmlns="http://tail-f.com/ns/netconf/ncs"> <device> <name>ios</name> <data> interface Loopback0 ip address 10.0.0.254 255.255.255.255 exit </data> </device> </dryrun-result> </rpc-reply>

 

Getting Started

検索バーにキーワード、フレーズ、または質問を入力し、お探しのものを見つけましょう

シスコ コミュニティをいち早く使いこなしていただけるよう役立つリンクをまとめました。みなさんのジャーニーがより良いものとなるようお手伝いします