Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?


Save and Load Junos PyEZ Table XML to and from Files

Junos PyEZ Tables and Views enable you to extract targeted data from operational command output or the selected configuration database on a Junos device. You can export Table data as XML, which enables you to retrieve information for one or more devices and process it at a later time. Junos PyEZ provides the savexml() method for this purpose.

The savexml() method enables you to specify a destination file path for the exported data, and optionally include the device hostname and activity timestamp in the filename. You can control the format of the timestamp using the standard strftime format.

For example, suppose that you want to loop through a list of devices and collect transceiver data using the XcvrTable definition in the jnpr.junos.op.xcvr module. The following code defines a list of device hostnames, prompts the user for a username and password, and then loops through and makes a connection to each device:

At this point. the program does not yet retrieve any transceiver data. Running the program results in the following output:

To collect and log the transceiver data, you associate the Table with each target device, retrieve the data, and save it to a file using the savexml() method. You can include hostname=True and timestamp=True in the savexml() argument list to append the hostname and timestamp to the output filename. If you retrieve data for multiple devices in this manner, you must differentiate the output filename for each device with the hostname, timestamp, or both to prevent the data for one device from overwriting the data for the previous device in the same file.


The path argument assumes that the target directory exists on your local file system.

After adding the additional code to the device loop in the program and then executing the program, you can examine the contents of the target directory. In this example, the hostname and timestamp values are embedded in the filenames.

You can import the XML data at a later time for post processing. To import the data, associate the Table with the XML file instead of a target device. For example: