[MUSIC] Welcome to the Junos XML API Programming Languages module. By the end of this module, you should be able to list the Junos XML API programming languages. Extensible style sheet language transformations, or XSLT, and style sheet language alternative syntax or SLAX were the first programming languages specifically designed to work with the Junos XML API. Starting with Junos 16.1, Python can also be used to perform the same tasks. Any programming language that can establish a network configuration protocol or NETCONF connection. Use the NETCONF protocol, and send well formed XML over that connection, can be used to automate devices running the Junos OS. Juniper provides code libraries for multiple programming languages, including Python, Ruby, Perl and Java. These free libraries make your interaction with NETCONF and the Junos XML API easy. XSLT is a world wide web consortium or W3C standard language for transforming one XML document into another XML document. The basic model consists of an XSLT engine or processor that accepts as input, a script or style sheet, and an XML document. The XSLT engine uses the instructions in the script to process the XML documents hierarchy. The script identifies interesting portions of the XML document, how it should be inspected and what XML output should be generated because XSLT was created to permit generic XML to XML transformations. It is a natural choice for both inspecting Junos configuration syntax and for generating errors and warnings. XSLT includes powerful mechanisms for finding configuration statements that match specific criteria. For more information about XSLT support in Junos, refer to the Juniper automation scripting user guide. An example of an XSLT conditional logic statement is shown in this example, when the host name statement is included at the edit system hierarchy level, change the host name to vmx-1, otherwise issue the warning message missing edit system host name. XSLT is a standard programming language for manipulating XML but it is not a preferred language for most programmers. SLAX is a programming language developed by Juniper engineers to make automating Junos easier. SLAX is now open source. One benefit of SLAX is that it is easier to use than XSLT. SLAX has the same capabilities as XSLT and you can translate back and forth between the two languages. Actually SLAX code is rendered into XSLT before being processed by the XSLT engine. SLAX is preferred by programmers who are not already accustomed to XSLT because SLAX enables the programmers to concentrate on the programming task rather than on learning a new programming syntax. Here is the portion of a SLAX script that invokes that Junos, get configuration remote procedure call or RPC on a local device. Stores the output in the dollar sign results variable and checks for the presence and value of a host name in a Junos device configuration using Extensible Markup Path Language or XPath. Using XSLT instead of familiar if else if and else programming statements you would use when statements and create a program as an XML file. SLAX is C or Java like syntax is more familiar to most programmers. SLAX is widely used by the Junos automation community. For more information about SLAX syntax and capabilities, refer to the Junos automation scripting user guide. The SLAX programming language although similar to C and Java has some limitations because of its close ties to XSLT, Junos OS release 16.1 introduced native python support, bringing the power of Python to Junos. The Python Netcom Protocol Library as well as the Junos PyEZ library are open source. Both are freely available at the GitHub website. You can access the website from the reference links document Junos PyEZ builds on top of the NETCONF library to simplify Junos automation as much as possible. The example Python script uses the Junos PyEZ Library to connect to a Junos device and retrieve information from the device known as facts and prints the facts to the screen. The result of running the script is shown. Other tasks such as viewing or loading device configuration are made easy using Junos PyEZ. A big advantage of using Python for Junos automation is that the same language, libraries and programs can be used for both on-box and off-box automation. Juniper networks provides a Perl module, Junos device to help you quickly and easily develop custom Perl scripts for configuring and monitoring the Junos OS. The module implements a Junos device object that client applications can use to communicate with the Junos XML protocol server. The Pearl distribution includes several sample Perl scripts that illustrate how to use the module to perform various functions. The Junos XML protocol Perl distribution uses the same directory structure for Perl modules as the Comprehensive Perl Archive Network or CPAN. It includes a lib directory for the Junos module and its supporting files, and an examples directory containing sample scripts. The library contains several modules, but client applications directly invoke only the Junos device object. For detailed instructions on installing the JUNOS XML protocol Pearl client and associated sample scripts refer to the Junos XML management protocol developer guide. The NETCONF Java Toolkit, which is available at the Github website provides an object oriented interface for communicating with the Junos Netcomf server. You can access the website from the reference links document. It enables programmers familiar with the Java programming language to create applications that can connect to a Junos device, establish a NETCONF session, execute operational commands, and create XML configuration hierarchies. There are four main classes in the NETCONF Java Toolkit device, which represents a NETCONF for over SSH session to a Junos device NETCONF server. NETCONF session which creates RPC requests and processes the RPC replies from the NETCONF server. XML builder which creates XML encoded data. XML which contains XML encoded data that represents an operational or configuration request or configuration data. For more information about how to use the NETCONF Java Toolkit, refer to the NETCONF Java Toolkit developer guide. The Juniper NETCONF Ruby gem is a NETCONF library for the popular Ruby programming language. The NETCONF Ruby gem available at the GitHub website provides classes and methods that enable Ruby programs to manage Junos devices Using NETCONF. It is installed using the gem install NETCONF command. You can access the website from the reference links document. The source code is also freely available. The example Ruby script displayed connects to the target device and authenticates with the provided username and password. It does not perform any additional actions. In addition to the NETCONF Ruby gem, Juniper also provides the Ruby Easy framework which is built on top of the NETCONF gem enabling automation development without requiring specific Junos XML knowledge. Network administrators of ACME Corp want to automate domain name system or DNS configuration on Junos devices including routers, switches and firewalls. Administrators need to view the existing DNS configuration and change the configuration to include a set of name servers. ACME Corp administrators are most familiar with the Ruby programming language because it is currently being used for server infrastructure automation. This case study uses the NETCONF for Ruby gem but other tools could be used in a similar fashion. Before using the example scripts in a production network environment, avoid the hard coding of user names and passwords for security purposes. Consider using SSH keys instead, avoid hard coding device management IP addresses. Consider passing device host names or IP addresses as parameters when a script is executed, add error handling to manage authentication errors, timeouts and so on. Verify that the Ruby interpreter is installed on the control server. If not, install it using your favorite package manager. Install the Ruby net netconf gem by issuing the gem, install net netcomf command. In this example, an interactive ruby interpreter or IRB is launched. The require net/netconf command returns true meaning both Ruby and the net netconf gem are available since the solution uses off-box scripts enabling NETCONF in the Junos configuration is necessary. The example script reads the DNS server configuration on a target device. The target device, address and login parameters are defined in the login variable. Then a netconf SSH connection is established with a device object. Although detailed coverage of Ruby is beyond the scope of this class. The syntax of the example script is fairly intuitive. A Junos get configuration RPC is executed by calling the RPC method of the dev object and the result is saved to the full config variable. Finally, the full config output is filtered using Xpath, looking for all entries of system/name server/name and printing the name server list using the puts function. The final part of the task, provisioning DNS server configuration is performed using the example script shown. It is similar to the previous script. The two examples could actually be combined into one script, but the example uses two scripts for simplicity. One difference between the two scripts is the RPCs that are executed. This example script uses additional RPs to lock the device configuration, load the new configuration using an XML formatted data variable called DNS config, commit and unlock the device configuration. Existing DNS settings are removed using the name server delete equal to delete XML element. [MUSIC]