【问题标题】:Juniper NETCONF RPC - No data returned瞻博网络 NETCONF RPC - 未返回数据
【发布时间】:2021-04-07 16:10:03
【问题描述】:

我正在尝试将自定义 XML RPC 发送到我的瞻博网络虚拟机。命令如下:

netconf-console --host 192.168.1.100 --port 830 --user xxxx --password xxxx --rpc junos-get-interfaces.xml

<nc:get-config xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<nc:source>
<nc:running/>
</nc:source>
<nc:filter type="xpath" select="/interfaces">
</nc:filter>
</nc:get-config>

自定义 RPC 正在尝试过滤正在运行的配置,以仅检索接口节。但我收到以下回复:

<?xml version='1.0' encoding='UTF-8'?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/12.1R1/junos" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:f0b4fd48-fcb5-4e03-815b-961a19a9b525">
<data>
</data>
</rpc-reply>

但是,框上的 Interfaces 节下有配置。有什么想法吗?我也尝试在 netconf-console CLI 命令中使用 xpath,但它说服务器不支持它

netconf-console --host 192.168.1.100 --port 830 --user xxxx --password xxxx --get-config /native/interfaces 操作失败:MissingCapabilityError - 服务器不支持 [:xpath]

【问题讨论】:

    标签: xml rpc juniper netconf


    【解决方案1】:

    XPath 不是 get-config 的有效过滤器类型。

    &lt;filter&gt; — Enclose the &lt;configuration&gt; tag element. The mandatory type attribute indicates the kind of syntax used to represent the requested configuration elements; the only acceptable value is subtree.

    https://www.juniper.net/documentation/en_US/junos/topics/reference/tag-summary/netconf-get-config.html

    您可以改用过滤器类型子树,如下所述。

    注意:GET-CONF 没有继承属性。如果您需要提取最终配置,即您正在使用“组”节,则需要使用 GET-CONFIGURATION。我将在下面的附加输出中显示差异。 https://www.juniper.net/documentation/en_US/junos/topics/reference/tag-summary/junos-xml-protocol-get-configuration.html

    使用 get-conf 的 get-interfaces.xml 的内容

    <get-config>
        <source>
            <running/>
        </source>
        <filter type="subtree">
            <configuration>
                <interfaces/>
            </configuration>
        </filter>
    </get-config>
    

    在目标主机上运行您的命令:

    netconf-console --host 10.49.162.162 --port 830 --user root --password xxxx --rpc get-interfaces.xml
    

    get-conf 的示例输出:

    root@Ubuntu-Server:~# netconf-console --host 10.49.162.162 --port 830 --user root --password Embe1mpls --rpc get-interfaces.xml 
    <?xml version='1.0' encoding='UTF-8'?>
    <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/18.3I0/junos" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:ae0be5f0-4f9d-45fa-b92f-c161d2a92f2b">
    <data>
    <configuration xmlns="http://xml.juniper.net/xnm/1.1/xnm" junos:commit-seconds="1608495419" junos:commit-localtime="2020-12-20 12:16:59 PST" junos:commit-user="root">
        <interfaces>
            <interface>
                <name>xe-0/0/0</name>
                <unit>
                    <name>0</name>
                    <family>
                        <inet>
                            <address>
                                <name>172.20.0.12/32</name>
                            </address>
                        </inet>
                    </family>
                </unit>
            </interface>
            <interface>
                <name>xe-0/0/1</name>
                <unit>
                    <name>0</name>
                    <family>
                        <inet>
                            <address>
                                <name>172.20.20.0/32</name>
                            </address>
                        </inet>
                    </family>
                </unit>
            </interface>
        </interfaces>
    </configuration>
    </data>
    </rpc-reply>
    

    get-interfaces.xml 的内容使用 get-configuration 和继承

    <get-configuration inherit="inherit">
        <configuration>
            <interfaces/>
        </configuration>
    </get-configuration>
    

    get-configuration 的示例输出:[注意在同一主机上继承的所有附加接口]

    root@Ubuntu-Server:~# netconf-console --host 10.49.162.162 --port 830 --user root --password xxxx --rpc get-interfaces.xml 
    <?xml version='1.0' encoding='UTF-8'?>
    <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/18.3I0/junos" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:92751ca5-8d1f-449c-a3e8-10aba7be249c">
    <configuration xmlns="http://xml.juniper.net/xnm/1.1/xnm" junos:changed-seconds="1608495419" junos:changed-localtime="2020-12-20 12:16:59 PST">
        <interfaces>
            <interface>
                <name>xe-0/0/0</name>
                <unit>
                    <name>0</name>
                    <family>
                        <inet>
                            <address>
                                <name>172.20.0.12/32</name>
                            </address>
                        </inet>
                    </family>
                </unit>
            </interface>
            <interface>
                <name>xe-0/0/1</name>
                <unit>
                    <name>0</name>
                    <family>
                        <inet>
                            <address>
                                <name>172.20.20.0/32</name>
                            </address>
                        </inet>
                    </family>
                </unit>
            </interface>
            <interface>
                <name>lo0</name>
                <unit>
                    <name>0</name>
                    <family>
                        <inet>
                            <address>
                                <name>128.49.162.162/32</name>
                                <primary/>
                            </address>
                        </inet>
                        <iso>
                            <address>
                                <name>47.0005.80ff.f800.0000.0108.0001.1280.4916.2162.00</name>
                            </address>
                        </iso>
                        <inet6>
                            <address>
                                <name>abcd::128:49:162:162/128</name>
                                <primary/>
                            </address>
                        </inet6>
                    </family>
                </unit>
            </interface>
            <interface>
                <name>em0</name>
                <unit>
                    <name>0</name>
                    <family>
                        <inet>
                            <address>
                                <name>10.49.162.162/19</name>
                            </address>
                        </inet>
                    </family>
                </unit>
            </interface>
            <interface>
                <name>em1</name>
                <unit>
                    <name>0</name>
                    <family>
                        <inet>
                            <address>
                                <name>169.254.0.2/24</name>
                            </address>
                        </inet>
                    </family>
                </unit>
            </interface>
        </interfaces>
    </configuration>
    </rpc-reply>
    

    注意:为了帮助找到过滤级别,可以在主机上运行“| display xml”命令来帮助识别正确的标签

    root@vqfx-leaf-01> show configuration interfaces | display xml | display inheritance 
    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/18.3I0/junos">
        <configuration junos:commit-seconds="1608495419" junos:commit-localtime="2020-12-20 12:16:59 PST" junos:commit-user="root">
                <interfaces>
                    <interface>
                        <name>xe-0/0/0</name>
                        <unit>
                            <name>0</name>
                            <family>
                                <inet>
                                    <address>
                                        <name>172.20.0.12/32</name>
                                    </address>
                                </inet>
                            </family>
                        </unit>
                    </interface>
                    <interface>
                        <name>xe-0/0/1</name>
                        <unit>
                            <name>0</name>
                            <family>
                                <inet>
                                    <address>
                                        <name>172.20.20.0/32</name>
                                    </address>
                                </inet>
                            </family>
                        </unit>
                    </interface>
                    <interface>
                        <name>lo0</name>
                        <unit>
                            <name>0</name>
                            <family>
                                <inet>
                                    <address>
                                        <name>128.49.162.162/32</name>
                                        <primary/>
                                    </address>
                                </inet>
                                <iso>
                                    <address>
                                        <name>47.0005.80ff.f800.0000.0108.0001.1280.4916.2162.00</name>
                                    </address>
                                </iso>
                                <inet6>
                                    <address>
                                        <name>abcd::128:49:162:162/128</name>
                                        <primary/>
                                    </address>
                                </inet6>
                            </family>
                        </unit>
                    </interface>
                    <interface>
                        <name>em0</name>
                        <unit>              
                            <name>0</name>
                            <family>
                                <inet>
                                    <address>
                                        <name>10.49.162.162/19</name>
                                    </address>
                                </inet>
                            </family>
                        </unit>
                    </interface>
                    <interface>
                        <name>em1</name>
                        <unit>
                            <name>0</name>
                            <family>
                                <inet>
                                    <address>
                                        <name>169.254.0.2/24</name>
                                    </address>
                                </inet>
                            </family>
                        </unit>
                    </interface>
                </interfaces>
        </configuration>
        <cli>
            <banner>{master:0}</banner>
        </cli>
    </rpc-reply>
    

    【讨论】:

      【解决方案2】:

      如果您尝试通过 netconf-console CLI 命令将--get-config--xpath 一起使用,您可以执行以下操作:

      netconf-console --host 192.168.1.100 --port 830 --user xxxx --password xxxx --get-config --xpath /native/interfaces
      

      【讨论】:

        猜你喜欢
        • 2016-03-01
        • 1970-01-01
        • 2022-12-04
        • 2012-07-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多