Jeremy Schulman has been working hard developing the Junos EZ library for Python, and one of the changes I mentioned that he had proposed before was to use YAML to define data tables, to make it simpler for us non-programmers to customize the data we want to use.
He moved so fast, in fact, that by the time I had published “Getting Busy With the Junos EZ Library” where I mentioned YAML, Jeremy had already updated some of the modules to use YAML!
This means two things:
- The format of the table data files has changed
- You may need to install some more software so that the updated files will work!
Read on; I’ll keep it reasonably short!
Installing YAML in Ubuntu
I’m assuming that you have already completed all the necessary steps to install Python and the Junos EZ library on Ubuntu. If so, there’s one more simple command to run.
sudo pip-2.7 install pyyaml
You’ll likely see an error when this is installed:
build/temp.linux-i686-2.7/check_libyaml.c:2:18: fatal error: yaml.h: No such file or directory
libyaml is not found or a compiler error: forcing --without-libyaml
But it’s ok; libyaml is not actually required and the installation script handles the error. All you really care about is the end result:
Successfully installed pyyaml
Before and After
What difference does YAML make? Well, less than you’d think, but let’s compare the format of the “old” Python file (ethport.py) to the new “YAML” file (ethport.yml).
EthPortTable, to recap, tells Python what information needs to be queried from the Juniper device. The original ethport.py is relatively simple, but has to have correct syntax:
|EthPortTable in Python (ethport.py)|
The YAML version is laid out in a hierarchical fashion using keys and values. The levels of indentation define the levels of the hierarchy – e.g. media and interface_name are elements within args. YAML can make laying data out really quite simple, and the key: value format is consistent and straightforward. This latest version also report on aggregated-ethernet (ae) interfaces:
|EthPortTable in YAML (ethport.yml)|
EthPortView defines the data that’s extracted from EthPortTable and presented to the user. Here’s the old version in Python:
|EthPortView in Python (ethport.py)|
And now here’s the much-simplified version in YAML. Note that in additional to the format change, some additional fields are being grabbed, and the data is reorganized slightly:
|EthPortView in YAML (ethport.yml)|
I do think that the YAML version is significantly simpler to read and create, so I’m looking forward to playing with this.
For reference, the ethport.py module is still there, and is now a static placeholder to pull in and interpret the ethport.yml YAML file; you don’t need to mess with ethport.py any more.
Keep on coding!