交换机通过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="http://www.h3c.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>http://www.h3c.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="http://www.h3c.com/netconf/config:1.0">
<Ifmgr>
<Interfaces/>
</Ifmgr>
</top>
</nc:filter>
</nc:get-config>
<!-- 可选:获取特定参数 -->
<nc:get>
<nc:filter type="subtree">
<!-- 示例:获取系统版本 -->
<top xmlns="http://www.h3c.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="http://www.h3c.com/netconf/config:1.0">
<VLAN>
<VLANs/>
</VLAN>
</top>
</nc:filter>
<nc:filter type="subtree">
<top xmlns="http://www.h3c.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="http://www.h3c.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="http://www.h3c.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="http://www.h3c.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)
暂无评论
亲~登录后才可以操作哦!
确定你的邮箱还未认证,请认证邮箱或绑定手机后进行当前操作
举报
×
侵犯我的权益
×
侵犯了我企业的权益
×
抄袭了我的内容
×
原文链接或出处
诽谤我
×
对根叔社区有害的内容
×
不规范转载
×
举报说明
暂无评论