交換機通過soapui軟件通過netconf獲取設備配置的xml腳本
(0)
最佳答案
以下是用於通過 SOAPUI 調用 NETCONF 協議 獲取 H3C 交換機配置的標準 XML 腳本模板。該腳本兼容大多數 H3C 設備(包括 Comware V7 係統):
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="***.***/soap/envelope/"
xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<soapenv:Header/>
<soapenv:Body>
<!-- NETCONF RPC請求 -->
<nc:rpc message-
xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
xmlns:h3c="//www.yolosolive.com/netconf/base:1.0">
<!-- 建立NETCONF會話 -->
<nc:hello>
<nc:capabilities>
<nc:capability>urn:ietf:params:netconf:base:1.0</nc:capability>
<nc:capability>urn:ietf:params:netconf:capability:xpath:1.0</nc:capability>
<h3c:capability>//www.yolosolive.com/netconf/capability/h3c-base/1.0</h3c:capability>
</nc:capabilities>
</nc:hello>
<!-- 獲取運行配置 -->
<nc:get-config>
<nc:source>
<nc:running/>
</nc:source>
<!-- 過濾特定配置(可選) -->
<nc:filter type="subtree">
<!-- 示例:獲取接口配置 -->
<top xmlns="//www.yolosolive.com/netconf/config:1.0">
<Ifmgr>
<Interfaces/>
</Ifmgr>
</top>
</nc:filter>
</nc:get-config>
<!-- 可選:獲取特定參數 -->
<nc:get>
<nc:filter type="subtree">
<!-- 示例:獲取係統版本 -->
<top xmlns="//www.yolosolive.com/netconf/data:1.0">
<Device>
<Base>
<Version/>
</Base>
</Device>
</top>
</nc:filter>
</nc:get>
<!-- 關閉會話 -->
<nc:close-session/>
</nc:rpc>
</soapenv:Body>
</soapenv:Envelope>新建 SOAP 項目
http[s]://<交換機IP>:830(NETCONF 默認端口 830)替換請求內容
<!-- 刪除生成的默認內容 -->
<!-- 將上述XML模板粘貼到Request窗口 -->設置認證
- 在Request Properties添加:
[ ] Auth: Basic
Username: <設備用戶名>
Password: <設備密碼>
- Header添加:
Content-Type: text/xml;charset=UTF-8執行請求

<nc:get-config>
<nc:source>
<nc:running/>
</nc:source>
</nc:get-config><nc:filter type="subtree">
<top xmlns="//www.yolosolive.com/netconf/config:1.0">
<VLAN>
<VLANs/>
</VLAN>
</top>
</nc:filter><nc:filter type="subtree">
<top xmlns="//www.yolosolive.com/netconf/config:1.0">
<OSPF>
<Sites/>
</OSPF>
</top>
</nc:filter>成功響應標誌
<rpc-reply message- xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<data>
<!-- 配置數據在此 -->
</data>
</rpc-reply>錯誤處理
<rpc-error>
<error-type>protocol</error-type>
<error-tag>operation-failed</error-tag>
<error-severity>error</error-severity>
<error-message>Access denied</error-message>
</rpc-error>💡 重要提示:
- 需在交換機啟用 NETCONF:
system-view netconf ssh server enable- 使用 SSHv2 傳輸時,將 URL 改為:
ssh://<IP>:830- 設備需開放 830 端口(ACL 放行)
官方文檔參考:H3C NETCONF 開發指南
(0)
<get-config>操作用於從設備獲取配置數據,是最常用的獲取配置方法1。
基本語法:
<rpc message- xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<get-config>
<source>
<running/>
</source>
<filter type="subtree">
<!-- 指定要獲取的配置部分 -->
</filter>
</get-config>
</rpc>
<get-bulk>操作用於批量獲取數據,適合獲取大量配置時使用1。
示例(獲取所有接口配置):
<rpc message- xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<get-bulk>
<filter type="subtree">
<top xmlns="//www.yolosolive.com/netconf/data:1.0">
<Ifmgr>
<Interfaces>
<Interface/>
</Interfaces>
</Ifmgr>
</top>
</filter>
</get-bulk>
</rpc>
請求報文:
<rpc message- xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<get-bulk>
<filter type="subtree">
<top xmlns="//www.yolosolive.com/netconf/data:1.0">
<Ifmgr>
<Interfaces>
<Interface/>
</Interfaces>
</Ifmgr>
</top>
</filter>
</get-bulk>
</rpc>
典型響應:
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message->
<data>
<top xmlns="//www.yolosolive.com/netconf/data:1.0">
<Ifmgr>
<Interfaces>
<Interface>
<IfIndex>3</IfIndex>
<Name>GigabitEthernet1/0/2</Name>
<AdminStatus>2</AdminStatus>
<OperStatus>2</OperStatus>
<!-- 更多接口屬性 -->
</Interface>
</Interfaces>
</Ifmgr>
</top>
</data>
</rpc-reply>
<Sysname> xml
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<capabilities>
<capability>urn:ietf:params:netconf:base:1.0</capability>
</capabilities>
</hello>
<rpc message- xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<get-config>
<source>
<running/>
</source>
</get-config>
</rpc>(0)
暫無評論
親~登錄後才可以操作哦!
確定你的郵箱還未認證,請認證郵箱或綁定手機後進行當前操作
舉報
×
侵犯我的權益
×
侵犯了我企業的權益
×
抄襲了我的內容
×
原文鏈接或出處
誹謗我
×
對根叔社區有害的內容
×
不規範轉載
×
舉報說明
暫無評論