Configuration changes using unstructured snippets and templates, or using structured abstractions.
There are two ways to make configuration changes: unstructured and structured. Unstructured changes are simply snippets of Junos OS configurations in any of the supported formats. Templates are snippets that have variables, so that you can quickly and easily produce configurations. Structured changes use well-defined Resource abstractions that have a programmatic approach to performing changes and accessing properties. Resources are analogous to the structured abstractions you would find in IT frameworks such as Puppet and Chef.
Unstructured changes are made using the Config utility. The Config utility provides a load() method that allows you to load either snippets or templates.
You associate a Config utility with a Device variable in one of two ways:
As a standalone variable:
As a bound property:
Once you have associated the Config to the Device, you use it the same way.
Complete coverage of using the load() method is beyond the scope of this topic page. But here are the highlights, and you can do "help(Config.load)" at the Python shell for complete documentation.
You can load a snippet from a file very simply, for example:
The load() method uses the filename extension by default to determine the configuration format ('text','set', or 'xml'). The result of theload() command is currently an XML structure that indicates the success or error of the load request.
Note that load() does NOT commit the change, it only loads it. You can use the Config utility commit_check() and commit()methods to perform those actions.
Loading a template from a file is also very simple. You provide a path to the template file and a dictionary of variables to be used by the template. For example:
Structured changes use a Junos PyEZ widget called a Resource. The Resource provides the necessary micro-framework to interact with the Junos OS configuration in a programmatic way.