在PyEZ中使用RPC调用时,我们将参数添加为命名参数,如rpc.get_interface_information(terse="True", interface-name="xe-0/0/0")
,但是对于配置,选项需要在rpc.get_configuration({"inherit":"inherit", "groups":"groups"})
这些差异的原因是什么?
答案 0 :(得分:2)
描述它的最佳方式是: 对于非配置rpcs,每个项都是它自己的元素,而在PyEZ中,我们使用参数来确定我们是引用元素。
<get-interface-information>
<routing-instance>routing-instance</routing-instance>
<extensive/>
<statistics/>
<media/>
<detail/>
<terse/>
<brief/>
<descriptions/>
<snmp-index>snmp-index</snmp-index>
<switch-port>switch-port</switch-port>
<interface-name>interface-name</interface-name>
</get-interface-information>
对于get-configuration rpc,您引用的所有项实际上都是get-configuration标记本身的属性,而不是rpc中定义的元素。
<get-configuration
[changed="changed"]
[commit-scripts="( apply | apply-no-transients | view )"]
[compare="rollback" [rollback="[0-49]"]]
[database="(candidate | committed)"]
[database-path=$junos-context/commit-context/database-path]
[format="( text | xml )"]
[inherit="( defaults | inherit )"
[groups="groups"] [interface-ranges="interface-ranges"]]
[(junos:key | key )="key"] >
<!-- tag elements for the configuration element to display -->
</get-configuration>
因此,要知道rpc(我们在PyEZ中动态创建)是引用元素还是属性,分别是参数或字典的使用。
希望有所帮助。
答案 1 :(得分:0)
根据Edward的回答,我相信PyEZ RPC调用是使用反射(__call__
方法)实现的,所以今天它不知道有效的RPC调用和args。使其了解的方法是从设备动态加载Netconf架构,并使用它将命名的arg映射到标签或元素。
试图从用户那里抽象出这个调用约定的一个潜在问题是,如果有一个标签和同一个RPC具有相同名称的元素,那么该怎么办 - 不确定今天是否是这种情况,或者有防止这种情况的规则模式,但在这种情况下,调用的用户应该能够控制RPC doc IMHO中的内容。