はじめに
NSO では、RESTCONF を経由して、デバイスの要素を変更することが可能です。
YANG patch を使用することで、複数の要素を同時に変更する手順をご紹介します。
1) デバイスの要素を個別に変更する場合
デバイスの要素を個別に変更する場合は、RESTCONFに直接アクセスします。
以下の例では、curlを使用して、ios デバイス (名前:ios0) の class-map (名前:test1) から、match エントリ vlan 1 のみを削除する例をご紹介します。
# curl -u admin:admin http://localhost:8080/restconf/data/tailf-ncs:devices/device=ios0/config/tailf-ned-cisco-ios:class-map=test1/match
<match xmlns="urn:ios" xmlns:ios="urn:ios" xmlns:ncs="http://tail-f.com/ns/ncs">
<vlan>1</vlan>
<vlan>2</vlan>
<vlan>3</vlan>
</match>
#
# curl -X DELETE -u admin:admin http://localhost:8080/restconf/data/tailf-ncs:devices/device=ios0/config/tailf-ned-cisco-ios:class-map=test1/match/vlan=1
#
# curl -u admin:admin http://localhost:8080/restconf/data/tailf-ncs:devices/device=ios0/config/tailf-ned-cisco-ios:class-map=test1/match
<match xmlns="urn:ios" xmlns:ios="urn:ios" xmlns:ncs="http://tail-f.com/ns/ncs">
<vlan>2</vlan>
<vlan>3</vlan>
</match>
2) デバイスの複数の要素を同時に変更する場合
NSO の RESTCONF 経由で、複数の要素を一度に変更する場合は、YANG patch を使用することができます。
YANG patch では、複数のアクションをまとめて実行させることが可能です。
まず、以下の例のように、複数のアクション (今回の例では vlan 2 と vlan 3 の削除) を列挙した YANG patch ファイルを準備します。
なお、target URL の書式については、前出の個別削除の URL の書式をご参考としてください。
# cat delete.xml
<yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
<patch-id>test-patch</patch-id>
<edit>
<edit-id>delete2</edit-id>
<operation>delete</operation>
<target>/tailf-ncs:devices/device=ios0/config/tailf-ned-cisco-ios:class-map=test1/match/vlan=2</target>
</edit>
<edit>
<edit-id>delete3</edit-id>
<operation>delete</operation>
<target>/tailf-ncs:devices/device=ios0/config/tailf-ned-cisco-ios:class-map=test1/match/vlan=3</target>
</edit>
</yang-patch>
次に、以下のように URL とリクエストヘッダを記述し、作成した YANG patch を引数として指定します。
# curl -X PATCH -u admin:admin http://localhost:8080/restconf/data -H "Content-Type:application/yang-patch+xml" -d '@delete.xml'
<yang-patch-status xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
<patch-id>test-patch</patch-id>
<ok/>
</yang-patch-status>#
#
# curl -u admin:admin http://localhost:8080/restconf/data/tailf-ncs:devices/device=ios0/config/tailf-ned-cisco-ios:class-map=test1/match
#