2024 02 Nihon-Tanken ~Towards a More Inclusive Japan~
ネットワーク機器のAPIあれこれ入門(NetOpsCoding#2)
1. ネットワーク機器のAPIあれこれ入門
How do you wan to talk with your Network Nodes?
Twitter: @ebiken | ebiken.g@gmail.com
ネットワーク機器のAPIあれこれ入門|NetOpsCoding#2|2016/03/04|@ebiken 1
18. ネットワーク機器のAPIあれこれ入門|NetOpsCoding#2|2016/03/04|@ebiken 21
REST (like) な API の分類 (概要)
• URI
• リソース
• リソース+操作
• 常に同じ
• エンコード
• JSON
• XML
• セッション
• 有り:URI/BODYにSessionID
• 無し
• オペレーション
• CLIをBodyに入れて送信
• HTTP METHOD + URI
• URIにコマンド入れる
RESTと記載されてても、(基本)RESTfulではない
• JSON-RPC, XML-RPC, WEB API?
19. Brocade vRouter 5600 (Vyatta)
• URI: コマンドを表す(リソースではなく)
• Encoding符号化: JSON
• 参照・設定、共にセッションを持つ
• Config Workflow
• Ops: one-time output
• Ops: continuous output
• GET /rest/op/<cmd>
• Ops with no session ID will return parameter definitions.
• Very different from RESTful concept.
ネットワーク機器のAPIあれこれ入門|NetOpsCoding#2|2016/03/04|@ebiken 22
Brocade vRouter 5600 (Vyatta)
20. Brocade vRouter 5600 (Vyatta)
ネットワーク機器のAPIあれこれ入門|NetOpsCoding#2|2016/03/04|@ebiken 23
設定投入&適用 Workflow
1. Begin a configuration session
• Config Session ID named "conf-id" will be
generated.
2. make configuration changes
• PUT /rest/conf/<conf-id>/set/<path>
• PUT /rest/conf/<conf-id>/delete/<path>
3. commit changes
• POST /rest/conf/<conf-id>/commit
4. optional: view config
• GET /rest/conf/<conf-id>/<path>
5. save config
• POST /rest/conf/<conf-id>/save
6. Finish configuration session
• DELETE /rest/conf/<conf-id>
CLIをURLにマップしたイメージ
21. Brocade vRouter 5600 (Vyatta)
ネットワーク機器のAPIあれこれ入門|NetOpsCoding#2|2016/03/04|@ebiken 24
参照コマンド (One Time)
• Begin a ops session
• POST /rest/op/show/version
• HTTP/1.1 201 Created
• Location: rest/op/137AA3B22A362CA3
• Get output from the command just
sent
• GET /rest/op/137AA3B22A362CA3
• HTTP/1.1 200 OK
• If request 2nd time, it's gone.
• GET /rest/op/137AA3B22A362CA3
• HTTP/1.1 410 Gone
22. Brocade vRouter 5600 (Vyatta)
ネットワーク機器のAPIあれこれ入門|NetOpsCoding#2|2016/03/04|@ebiken 25
参照コマンド (継続的)
• Begin a ops session (ex: ping)
• POST /rest/op/ping/10.0.0.1
• Get ouput (1st)
• GET /rest/op/02B3479CA1522F2A
• HTTP/1.1 200 OK
• PING 10.3.0.1 (10.3.0.1) 56(84) bytes of
data.
• 64 bytes from 10.3.0.1: icmp_seq=1
ttl=64 time=0.839 ms
• 64 bytes from 10.3.0.1: icmp_seq=2
ttl=64 time=0.846 ms
• ...
• 64 bytes from 10.3.0.1: icmp_seq=18
ttl=64 time=0.821 ms
• Get output (2nd)
• GET /rest/op/02B3479CA1522F2A
• HTTP/1.1 200 OK
• 64 bytes from 10.3.0.1: icmp_seq=19
ttl=64 time=0.799 ms
• 64 bytes from 10.3.0.1: icmp_seq=20
ttl=64 time=0.807 ms
• ...
• Stop a ops session (and the command
ping)
• DELETE /rest/op/02B3479CA1522F2A
.
27. device-name port
JUNOS: XML RPC Single Method
ネットワーク機器のAPIあれこれ入門|NetOpsCoding#2|2016/03/04|@ebiken 30
URI Example
https://198.51.100.1:3000/rpc/get-software-information
... /get-interface-information?terse=&interface-name=ge-0/0/1
method
method parameters
参考:JunosのREST APIを使ってみる
http://qiita.com/kazubu/items/e5e0941f66f6c6f2f55a
28. JUNOS: XML RPC Single Method
ネットワーク機器のAPIあれこれ入門|NetOpsCoding#2|2016/03/04|@ebiken 31
CLIコマンドに対応する RPC method 確認方法
参考:JunosのREST APIを使ってみる
http://qiita.com/kazubu/items/e5e0941f66f6c6f2f55a
30. REST (like) API のタイプ
• (URIでなく)CLIに紐づくRPC Method をBODYに複数記述
ネットワーク機器のAPIあれこれ入門|NetOpsCoding#2|2016/03/04|@ebiken 33
XML RPC Multi Method型 (JUNOS Multi RPC)
Request Response