Table Item Reference
When you define a Table, you define the XPath expression for each item. From the table definition, line 8, you can see that each item is
<physical-interface>
. Therefore every other field XPath expression is "relative" to the
<physical-interface>
. While you do not need to be an expert with XPath expression syntax, you do need a basic understanding. If XPath is new to you, please review the W3Schools link on the sidebar.
Field Item Reference
Now that you have your table item point of reference, you can define your fields accordingly. For example, the "operational status" value,
oper-status
, is directly "under" the physical-interface. So the XPath expression is very simple, it's just
oper-status
. That field is defined in the view on line 6. The left-hand side of the colon (:) is what you will use in Python, in this case
oper
. If you were using this table in the Python shell, you could do something like the following, assuming
dev
is a connected Device instance:
4 |
>>> from jnpr.junos.op.ethport import * |
5 |
>>> eths = EthPortTable(dev) |
7 |
EthPortTable:srx210: 8 items |
8 |
>>> eths['ge-0/0/0'].oper |
At a minimum, you must define fields
within your view, as illustrated in lines 5 through 10. Any field definition you include here is relative to the Table item.
You can additionally define field groups. The idea behind field groups is that you want to reference Junos XML items that are contained by other XML elements. For example, looking at the RPC output, you can see that there is a group of fields enclosed by <if-device-flags>. If you want to use values in that group ("node-set" in XPath parlance), you have the following two choices:
You could reference the XPath explicitly like this:
3 |
present: if-device-flags/present |
4 |
running: if-device-flags/running |
Or, you could define a group and then set up a field group definition:
To create a group, declare a group name under the groups
keyword. In this example, the group name is flags
. You then define the XPath expression relative from the table item to the XPath node-set. Since if-device-flags
is a direct child of physical-interface, this is a simple expression, just if-device-flags
. You can declare multiple groups. If you don't use groups, then you don't include it in the View definition.
As you can see, the field group name is "fields_
" followed by the name of the group, so in this case fields_flags
. The choice to use groups or not is entirely up to you; it's really meant as a "shortcut" so you don't have to keep re-keying repetitive XPath expressions. From a Python coding perspective, there is no difference; you access the running
value in the same way.
Field Item Values
By default, field items are stored as strings. When you want something different, such as a number, you need to define the field slightly differently. For example, review the mtu
definition on line 8. You can see how the field is defined to make it an integer (int). Another case is when the Junos XML field does not have a value, rather it is a "flag". You can define a field as flag so that you get True or False if the flag is present or missing. For example, review line 17, and then this Python shell output:
1 |
>>> eths['ge-0/0/0'].present |