"get chassis mac-address" YAML problem

232 views
Skip to first unread message

jason.d...@gallaudet.edu

unread,
Jun 5, 2017, 9:47:51 AM6/5/17
to Junos Python EZ
I'm trying to get the chassis MAC address from a switch, and I'm having some sort of RPC/YAML problem.  Can someone help me troubleshoot this please?

Thanks,

Jason

from jnpr.junos import Device
from jnpr.junos.factory.factory_loader import FactoryLoader
import yaml
import pprint

yaml_data="""
---
junos_chassis_mac_address_table:
  rpc: get-chassis-mac-addresses
  item: chassis-mac-information
  view: junos_chassis_mac_address_view
  key: slot

junos_chassis_mac_address_view:
  fields:
    slot: slot
    mac_address: mac-address
    mac_count: count
"""

dev = Device(host='xxx', user='xxx', password='xxx')
dev.open()

globals().update(FactoryLoader().load(yaml.load(yaml_data)))

mac = junos_chassis_mac_address_view(dev)
mac.get()
print mac.keys()
print mac.values()

dev.close()

Stacy Smith

unread,
Jun 5, 2017, 10:08:29 AM6/5/17
to Junos Python EZ
Hi Jason,

Can you please provide the output of `show chassis mac-address | display xml` from your device?

In addition, it might be helpful if you can provide the output your seeing from running your script.

Thanks,
--Stacy

jason.d...@gallaudet.edu

unread,
Jun 5, 2017, 10:35:50 AM6/5/17
to Junos Python EZ
Sure.  Here is the display xml:

> show chassis mac-addresses | display xml
    <chassis-mac-information>
        <fpc-mac-information>
            <slot>0</slot>
            <mac-address>xx:xx:xx:xx:xx:00</mac-address>
            <count>96</count>
        </fpc-mac-information>
    </chassis-mac-information>
    <cli>
        <banner>{master:0}</banner>
    </cli>
</rpc-reply>

The python traceback:

Traceback (most recent call last):
  File "getmac.py", line 26, in <module>
    mac = junos_chassis_mac_address_view(dev)
TypeError: __init__() takes exactly 3 arguments (2 given)

Jason

Stacy Smith

unread,
Jun 5, 2017, 11:05:46 AM6/5/17
to Junos Python EZ
Here's a working example with differences highlighted in red.

user@h0:~$ cat table_test.py 
from jnpr.junos import Device
from jnpr.junos.factory.factory_loader import FactoryLoader
import yaml
import pprint

yaml_data="""
---
junos_chassis_mac_address_table:
  rpc: get-chassis-mac-addresses
  item: fpc-mac-information
  view: junos_chassis_mac_address_view
  key: slot

junos_chassis_mac_address_view:
  fields:
    slot: slot
    mac_address: mac-address
    mac_count: count
"""

globals().update(FactoryLoader().load(yaml.load(yaml_data)))

mac = junos_chassis_mac_address_table(path='chassis_mac.xml')
mac.get()
print mac.keys()
print mac.values()

Here's the data file I used just because I didn't have quick/easy access to a device that produced this output.

user@h0:~$ cat chassis_mac.xml 
<chassis-mac-information>
    <fpc-mac-information>
        <slot>0</slot>
        <mac-address>xx:xx:xx:xx:xx:00</mac-address>
        <count>96</count>
    </fpc-mac-information>
</chassis-mac-information>

and here's the result of running it.

user@h0:~$ python ./table_test.py
['0']
[[('slot', '0'), ('mac_count', '96'), ('mac_address', 'xx:xx:xx:xx:xx:00')]]

Hope this helps.
--Stacy

jason.d...@gallaudet.edu

unread,
Jun 5, 2017, 11:10:36 AM6/5/17
to Junos Python EZ
Thank you for finding my mistakes.

It appears that this command can return multiple MAC addresses from more than once source, as seen by the example results in this link: https://www.juniper.net/documentation/en_US/junos/topics/reference/command-summary/show-chassis-mac-addresses.html

As a pair of follow-up questions:
1) What is involved in getting this to handle more complex results?
2) Is it possible to get this rolled into the source distribution?  What is needed to do so?

Thanks again,

Jason

Stacy Smith

unread,
Jun 5, 2017, 11:28:18 AM6/5/17
to Junos Python EZ
On Monday, June 5, 2017 at 9:10:36 AM UTC-6, jason.d...@gallaudet.edu wrote:
It appears that this command can return multiple MAC addresses from more than once source, as seen by the example results in this link: https://www.juniper.net/documentation/en_US/junos/topics/reference/command-summary/show-chassis-mac-addresses.html

I think there are two issues here.

1) On your platform, there could be multiple slots each with their own base MAC address and count.

2) The output of this RPC is, unfortunately, not uniform across Junos platforms. As an example, here's the output from a vMX:
user@r0> show chassis mac-addresses | display xml 
    <chassis-mac-addresses>
        <mac-address-information>
            <public-base-address>00:05:86:58:68:00</public-base-address>
            <public-count>1984</public-count>
            <private-base-address>00:05:86:58:6f:c0</private-base-address>
            <private-count>64</private-count>
        </mac-address-information>
    </chassis-mac-addresses>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>

 
As a pair of follow-up questions:
1) What is involved in getting this to handle more complex results?

Can you explain what you mean by "more complex results"?

If you're asking about #1 above (multi-slot output), it's already handled by your table/view. There will be one item returned for every <fpc-mac-information> XML element, and each of those items will be keyed off the value of the <slot> XML element.

If you're asking about how to handle the differences in output between different platforms, then you would need to write more complex XPath expressions that included logical ORs.

I recommend taking a look at "Automating Junos Administration" which covers creation of custom tables/views in detail.
 
2) Is it possible to get this rolled into the source distribution?  What is needed to do so?

Users can submit a pull request on GitHub with new tables/views. However, we try hard to make sure the tables/views included with PyEZ work across Junos platforms. Due to the inherit differences in the RPC output between platforms, it is unlikely we would accept a table/view for this RPC into the PyEZ distribution.

We are considering creating a separate repository for user-created, -contributed, and -supported tables and  views. Unfortunately, I don't have a timeframe for when (or even if) that's going to happen.

--Stacy
Reply all
Reply to author
Forward
0 new messages