O'Reilly logo

JUNOS Automation Cookbook by Adam Chappell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Instantiating the template

For render-graph.py, we leverage the standard Python library framework Template which is very happy to process a text file and make variable substitutions based on a special sequence. So our tool reads in the JSON graph specified on the command line and then reads a template from a default file, graph.html.template.

With both the JSON graph data and template content available to the tool, it uses the Template.substitute() method in order to search through the template text, substituting any occurrences of $graph with the JSON data from the file we specify on the command line. The output is written to a file with a default filename of graph.html.

Both the template filename and the output filename can be customized ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required