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

NETCONF の XMLサブツリーフィルタリング を使用して、get-config への応答に含まれるコンフィグの範囲を指定する例を紹介します。

確認に使用した環境は以下の通りです。

  • NETCONFサーバ: CSR1000v / IOS XE 3.6(1)S
  • NETCONFクライアント: netconf-console

 

※ netconf-console の --rpc オプションやインタラクティブモードを使って XML を送信する場合は以下のように<rpc>, </rpc> を除く必要がありますのでご注意ください。

$ netconf-console --host 192.168.0.1 --port 830 -u cisco -p cisco -i

* Enter a NETCONF operation, end with an empty line
<get-config>
<source>
<running/>
</source>
</get-config>

netconf-console についてはこちらの記事も参考にしてください。
NETCONF: netconf-console の使い方

 

 

 

1. フィルタ無し

(1) フィルタ要素を含まない: 全てのコンフィグを取得

リクエストがフィルタ要素 <filter> </filter> を含まない場合、応答には全てのコンフィグ(※)が含まれます。

※ YANG でモデル化されている全てのコンフィグです。CLI から設定可能な全てのコンフィグではありません。

  • Request
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<get-config>
<source>
<running/>
</source>
</get-config>
</rpc>
  • Reply
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<data>
<native xmlns="http://cisco.com/ns/yang/ned/ios">

( 省略 )

</routing>
</data>
</rpc-reply>

(2) 空のフィルタ

空のフィルタが指定された場合、マッチするコンテンツが無いと判断されて空の応答が返ります。

  • Request
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<get-config>
<source>
<running/>
</source>
<filter type="subtree">
</filter>
</get-config>
</rpc>
  • Reply
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<data/>
</rpc-reply>

 

2. ネームスペースを使ったフィルタリング

xmlns に続く urn:ietf:params:xml:ns:yang:ietf-interfaces がネームスペースです。
xmlns の前にある interfaces は、このネームスペースの最上位にあるコンテナです。

応答には interfaces 配下の全ての子要素が含まれます。

  • Request
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<get-config>
<source>
<running/>
</source>
<filter type="subtree">
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"/>
</filter>
</get-config>
</rpc>
  • Reply
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<data>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>GigabitEthernet1</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
<enabled>true</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>10.0.0.1</ip>
<netmask>255.255.255.0</netmask>
</address>
</ipv4>
<ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
</interface>
<interface>
<name>GigabitEthernet2</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
<enabled>true</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>192.168.0.1</ip>
<netmask>255.255.255.0</netmask>
</address>
</ipv4>
<ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
</interface>
<interface>
<name>GigabitEthernet3</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
<enabled>true</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>172.16.0.1</ip>
<netmask>255.255.0.0</netmask>
</address>
</ipv4>
<ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
</interface>
</interfaces>
</data>
</rpc-reply>

 

3. Containment Node を使ったフィルタリング

全インタフェースのコンフィグを取得

Containment Node は子要素を持つコンテナです。Containment Node を指定してフィルタリングした場合、応答には Containment Node 配下の全ての子要素が含まれます。

この例では interfaces 配下の Containment Node である interface を指定してフィルタリングしています。

応答には interface 配下の全てのコンフィグが含まれます。
interfaces 配下には interface 以外の子要素は無いため、応答に含まれるコンフィグは 2 の例と同じです。

  • Request
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<get-config>
<source>
<running/>
</source>
<filter type="subtree">
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface/>
</interfaces>
</filter>
</get-config>
</rpc>
  • XPath ( netconf-console の xpath オプションを使って同様のリクエストを送っている例 )
$ netconf-console --host 192.168.0.1 --port 830 -u cisco -p cisco --get-config --xpath /interfaces/interface
  • Reply
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<data>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>GigabitEthernet1</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
<enabled>true</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>10.0.0.1</ip>
<netmask>255.255.255.0</netmask>
</address>
</ipv4>
<ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
</interface>
<interface>
<name>GigabitEthernet2</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
<enabled>true</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>192.168.0.1</ip>
<netmask>255.255.255.0</netmask>
</address>
</ipv4>
<ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
</interface>
<interface>
<name>GigabitEthernet3</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
<enabled>true</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>172.16.0.1</ip>
<netmask>255.255.0.0</netmask>
</address>
</ipv4>
<ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
</interface>
</interfaces>
</data>
</rpc-reply>

 

4. Selection Node を使ったフィルタリング

(1) 特定の1要素: インタフェース名のリストを取得

<name/> や <name> </name> のように空の要素として表現されているリーフノード( 子要素を持たないノード )は Selection Node と呼ばれます。Selection Node を指定してフィルタリングした場合、応答には Selection Node の値が含まれます。 Selection Node と同階層の他要素は含まれません。

この例では interface コンテナに含まれるリーフノード、name( インタフェース名 ) を Selection Node としてフィルタリングしています。

応答には name( インタフェース名 ) のリストが含まれます。

  • Request
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<get-config>
<source>
<running/>
</source>
<filter type="subtree">
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name/>
</interface>
</interfaces>
</filter>
</get-config>
</rpc>
  • XPath
$ netconf-console --host 192.168.0.1 --port 830 -u cisco -p cisco --get-config --xpath /interfaces/interface/name
  • Reply
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<data>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>GigabitEthernet1</name>
</interface>
<interface>
<name>GigabitEthernet2</name>
</interface>
<interface>
<name>GigabitEthernet3</name>
</interface>
</interfaces>
</data>
</rpc-reply>

(2) 複数の要素: IPアドレスとネットマスクのリストを取得

この例では ipv4 コンテナに含まれるリーフノード addressnetmaskSelection Node としてフィルタの対象に指定しています。

応答には IPアドレスとネットマスクのリストが含まれます。

  • Request
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<get-config>
<source>
<running/>
</source>
<filter type="subtree">
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip/>
<netmask/>
</address>
</ipv4>
</interface>
</interfaces>
</filter>
</get-config>
</rpc>
  • XPath ( netconf-console の制約のため、パイプをエスケープしています )
$ netconf-console --host 192.168.0.1 --port 830 -u cisco -p cisco --get-config --xpath /interfaces/interface/ipv4/address/ip \| /interfaces/interface/ipv4/address/netmask
  • Reply
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<data>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>192.168.0.1</ip>
<netmask>255.255.255.0</netmask>
</address>
</ipv4>
</interface>
<interface>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>192.168.0.1</ip>
<netmask>255.255.255.0</netmask>
</address>
</ipv4>
</interface>
<interface>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>172.16.0.1</ip>
<netmask>255.255.0.0</netmask>
</address>
</ipv4>
</interface>
</interfaces>
</data>
</rpc-reply>

 

5. Content Match Node を使ったフィルタリング

(1) 特定のインスタンス: Gi2 のコンフィグを取得

<name>GigabitEthernet2</name> のように値をもつリーフノードは Content Match Node と呼ばれます。Content Match Node を指定してフィルタリングした場合、応答には条件に合致するインスタンス( この例では GigabitEthernet2 )に紐付くコンフィグが含まれます。

また、この例のように Content Match Node と同階層の Containment Node/Selection Node が指定されていない場合、応答には Content Match Node と同階層の他要素  (type, enabled, ipv4 等) も含まれます。

  • Request
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<get-config>
<source>
<running/>
</source>
<filter type="subtree">
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>GigabitEthernet2</name>
</interface>
</interfaces>
</filter>
</get-config>
</rpc>
  • XPath ( netconf-console の制約のため、ダブルクォーテーションをエスケープしています )
$ netconf-console --host 192.168.0.1 --port 830 -u cisco -p cisco --get-config --xpath /interfaces/interface[name=\"GigabitEthernet2\"]
  • Reply
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<data>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>GigabitEthernet2</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
<enabled>true</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>192.168.0.1</ip>
<netmask>255.255.255.0</netmask>
</address>
</ipv4>
<ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
</interface>
</interfaces>
</data>
</rpc-reply>

(2) 複数のインスタンス: Gi2 と Gi3 のコンフィグを取得

この例では name( インタフェース名 ) の値として GigabitEthernet2 と GigabitEthernet3 を持つことを条件とする Content Match Node を使ってフィルタリングしています。応答には条件に合致するインスタンスのコンフィグが含まれます。

  • Request
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<get-config>
<source>
<running/>
</source>
<filter type="subtree">
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>GigabitEthernet2</name>
</interface>
<interface>
<name>GigabitEthernet3</name>
</interface>
</interfaces>
</filter>
</get-config>
</rpc>
  • XPath ( netconf-console の制約のため、ダブルクォーテーションをエスケープしています )
$ netconf-console --host 192.168.0.1 --port 830 -u cisco -p cisco --get-config --xpath /interfaces/interface[name=\"GigabitEthernet2\" or name=\"GigabitEthernet3\"]
  • Reply
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<data>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>GigabitEthernet2</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
<enabled>true</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>192.168.0.1</ip>
<netmask>255.255.255.0</netmask>
</address>
</ipv4>
<ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
</interface>
<interface>
<name>GigabitEthernet3</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
<enabled>true</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>172.16.0.1</ip>
<netmask>255.255.0.0</netmask>
</address>
</ipv4>
<ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
</interface>
</interfaces>
</data>
</rpc-reply>

(3) 任意の数のインスタンス: /24 が設定された IPアドレスを取得

この例では ipv4 コンテナ配下のリーフノード netmask に "255.255.255.0" の値を持つことを条件とする Content Match Node を使ってフィルタリングしています。

netmask の値を事前に把握している必要はありません。条件に合致する IPアドレスが全て表示されます。

  • Request
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<get-config>
<source>
<running/>
</source>
<filter type="subtree">
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<netmask>255.255.255.0</netmask>
</address>
</ipv4>
</interface>
</interfaces>
</filter>
</get-config>
</rpc>
  • XPath ( netconf-console の制約のため、ダブルクォーテーションをエスケープしています )
$ netconf-console --host 192.168.0.1 --port 830 -u cisco -p cisco --get-config --xpath /interfaces/interface/ipv4/address[netmask=\"255.255.255.0\"]
  • XPath interface のレベルからコンフィグを取得する場合
$ netconf-console --host 192.168.0.1 --port 830 -u cisco -p cisco --get-config --xpath /interfaces/interface[ipv4/address/netmask=\"255.255.255.0\"]
  • Reply
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<data>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>10.0.0.1</ip>
<netmask>255.255.255.0</netmask>
</address>
</ipv4>
</interface>
<interface>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>192.168.0.1</ip>
<netmask>255.255.255.0</netmask>
</address>
</ipv4>
</interface>
</interfaces>
</data>
</rpc-reply>

(4) Content Match Node + Selection Node

この例のように Content Match Node と同階層の Selection Node が指定されている場合、応答には条件に合致する Content Match Node と Selection Node の値が含まれます。同階層の他要素は含まれません。

  • Request
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<get-config>
<source>
<running/>
</source>
<filter type="subtree">
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>GigabitEthernet2</name>
<enabled/>
</interface>
</interfaces>
</filter>
</get-config>
</rpc>
  • XPath ( netconf-console の制約のため、ダブルクォーテーションをエスケープしています )
$ netconf-console --host 192.168.0.1 --port 830 -u cisco -p cisco --get-config --xpath /interfaces/interface[name=\"GigabitEthernet2\"]/enabled
  • Reply
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<data>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>GigabitEthernet2</name>
<enabled>true</enabled>
</interface>
</interfaces>
</data>
</rpc-reply>

 

(5) Content Match Node + Containment Node

この例のように Content Match Node と同階層の Containment Node が指定されている場合、応答には条件に合致する Content Match Node の値と Containment Node 配下の要素が含まれます。同階層の他要素は含まれません。

  • Request
<get-config>
<source>
<running/>
</source>
<filter type="subtree">
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>GigabitEthernet2</name>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
</interface>
</interfaces>
</filter>
</get-config>
  • XPath ( netconf-console の制約のため、ダブルクォーテーションをエスケープしています )
$ netconf-console --host 192.168.0.1 --port 830 -u cisco -p cisco --get-config --xpath /interfaces/interface[name=\"GigabitEthernet2\"]/ipv4
  • Reply
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<data>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>GigabitEthernet2</name>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>192.168.0.1</ip>
<netmask>255.255.255.0</netmask>
</address>
</ipv4>
</interface>
</interfaces>
</data>
</rpc-reply>

 

Getting Started

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

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