使用 NETCONF 为配置对象请求特定子标记
在运行 Junos OS 设备的 NETCONF 会话中,为了请求特定子标记元素和配置对象的子标记,客户端应用程序会发出一个标记元素,该标记元素包含代表配置层次结构所有级别的标记元素,从 root(由标记元素表示)到对象的直接父层。 <filter>
<configuration>
要表示请求的对象,应用程序会发出其容器标记元素。要请求特定配置对象,请包含标识符标记元素。对于具有单个标识符的对象,即使实际标识符标记元素有不同的名称,也可以始终使用 <name>
标记元素。实际名称也有效。对于具有多个标识符的对象,必须使用标识符标记元素的实际名称。如果省略标识符标记元素,服务器将为此类型的所有配置对象返回子标记。要选择特定子标记,客户端应用程序会发出所有所需的子标记元素,并发出容器标记元素中的子标记元素。整个请求包含于一个标记 <rpc>
元素中:
<rpc> <get-config> <source> <!-- tag specifying the source configuration --> </source> <filter type="subtree"> <configuration> <!-- opening tags for each parent of the object --> <object> <name>identifier</name> <first-child/> <second-child/> <third-child> <!--tags for descendents--> </third-child> <!-- tag for each additional child to return --> </object> <!-- closing tags for each parent of the object --> </configuration> </filter> </get-config> </rpc> ]]>]]>
有关标记 <source>
元素的信息,请参阅 使用 NETCONF 指定配置信息请求的来源。
NETCONF 服务器返回 和 标记元素 中对象(此处是称为 标识符 <data>
<rpc-reply>
标记元素的对象)的已请求子项 <name>)
。有关开放标记中的属性的信息,请参阅 <configuration>
使用 NETCONF指定配置信息请求的来源 。
<rpc-reply xmlns="URN" xmlns:junos="URL"> <data> <configuration attributes> <!-- opening tags for each parent of the object --> <object> <name>identifier</name> <!-- requested child tags --> </object> <!-- closing tags for each parent of the object --> </configuration> </data> </rpc-reply> ]]>]]>
应用程序还可通过在同一标记元素中包含适当的标记元素来请求相同或其他类型的附加配置 <get-config>
元素。有关详细信息,请参阅 同时使用 NETCONF 请求多个配置元素。
以下示例显示如何针对候选配置中层次结构级别的 192.168.5.0/24 路由仅请求下一跳跃设备的地址。 [edit routing-options static]

以下示例显示如何请求在候选配置的组层次结构级别内为每个物理接口配置的所有逻辑接口的地址。
<rpc> <get-config> <source> <candidate/> </source> <filter type="subtree"> <configuration> <groups> <interfaces> <interface> <unit> <family> <inet> <address/> </inet> </family> </unit> </interface> </interfaces> </groups> </configuration> </filter> </get-config> </rpc>
<rpc-reply xmlns="URN" xmlns:junos="URL"> <data> <configuration xmlns="URL" junos:commit-seconds=seconds junos:commit-localtime="timestamp" junos:commit-user="user"> <groups> <name>re0</name> <interfaces> <interface> <name>lo0</name> <unit> <name>0</name> <family> <inet> <address> <name>127.0.0.1/32</name> </address> </inet> </family> </unit> </interface> <interface> <name>em0</name> <unit> <name>0</name> <family> <inet> <address> <name>198.51.100.1/24</name> </address> <address> <name>198.51.100.11/24</name> </address> </inet> </family> </unit> </interface> </interfaces> </groups> </configuration> </data> </rpc-reply>