Network automation lab 23 of 27
Junos automation: XML API, NETCONF, PyEZ and the REST API
Work up the Junos automation stack on a real vSRX: see the XML behind the CLI, speak NETCONF by hand and with ncclient, use PyEZ for facts, RPCs, tables and safe configuration changes with Jinja2 templates and confirmed commits, then drive the same RPCs through the REST API with cURL.
Run this lab
It needs Lite: its 3 nodes are set to 4 vCPU and 5,632 MB in total. That fits the free demo too.
In your workspace: Shared, then Network Automation - CCNA and CCNP Automation guided labs, then 23 - Junos automation - XML API NETCONF PyEZ and the REST API
- Level
- Intermediate
- Time
- About 90 minutes
- Nodes need
- 4 vCPU, 5,632 MB
- Smallest plan
- Lite
The scenario
The Hull depot's SRX came with the Northern Haulage purchase, and the team wants it managed from code rather than by hand. Juniper built Junos around an XML API, so everything the CLI does can be done by a program. You'll work up that stack in order: see the XML behind the CLI, speak NETCONF by hand, then use the tools built on it, ending with the REST API.
| Device | Platform | Mgmt address | Loopback | AS |
|---|---|---|---|---|
| srx1 | Juniper Junos 24.4 (vSRX) | 10.10.20.41 | 10.255.0.3 | 65003 |
| r1 | Cisco IOS 15.9 (IOSv) | 10.10.20.11 | 10.255.0.1 | 65001 |
srx1 ge-0/0/0 (10.1.13.2/30) connects to r1 Gi0/1 (10.1.13.1/30) with eBGP, so srx1 has a live peer and a BGP route to look at. The login is netops / NetOps-Lab1, exported as $NET_USER and $NET_PASS. On the srx1 console you may be asked to log in: use the same details, then type cli if you land in a shell. PyEZ 2.6.8 (junos-eznc), ncclient and xmllint are on devbox, and your files are in ~/lab.
What you’ll practise
- Find the RPC behind any Junos command and read XML, JSON and set output
- Enable NETCONF and the REST API, and explain the NETCONF hello, capabilities and framing
- Query XML replies with XPath from ncclient, PyEZ and xmllint
- Use PyEZ facts, RPCs, tables and views, and handle its exceptions
- Change configuration from a Jinja2 template with a diff, a commit check and a confirmed commit
- Call the Junos REST API with cURL and Python, and read its error behaviour
The tasks
- The XML behind the CLI
- Turn on the APIs
- NETCONF by hand
- ncclient and XPath
- PyEZ: facts and exceptions
- RPCs from Python
- Tables and views
- Safe configuration from a template
- The REST API
The Lab Tasks pane has the scenario, these tasks, the checks to run, hints and the full solution.
Topology and devices
The network as it opens in EVE-NG, drawn from the lab’s own canvas, and the image each node runs.
Every link, as text
- devbox
eth0to Mgmt (network) - srx1
fxp0to Mgmt (network) - r1
Gi0/0to Mgmt (network) - srx1
ge-0/0/0to r1Gi0/1
| Node | Device | Image in Add Node | Set to |
|---|---|---|---|
| devbox | EVE-NG GUI server (Docker) | eve-gui-server:latest | 1 vCPU, 1,024 MB |
| srx1 | Juniper vSRX NextGen template | vsrxng-24.4R1.9 | 2 vCPU, 4,096 MB |
| r1 | Cisco IOSv | vios-adventerprisek9-m.spa.159-3.m9 | 1 vCPU, 512 MB |
How to open this lab
Sign in to your workspace at
lab.cloudlabbox.com.In File Manager, open Shared, then the folder
Network Automation - CCNA and CCNP Automation guided labs.Open
23 - Junos automation - XML API NETCONF PyEZ and the REST APIand start its nodes, then open Lab Tasks for the scenario and the steps.
The lab is read-only. You can start the nodes and configure the devices, but changes to the topology can’t be saved. To change it, rebuild it in your own folder.
More Network automation labs
Related labs in other courses
CloudLabBox is independent of Cisco. The lab follows exam topics and isn’t vendor training material; vendor names identify the exams and the images in the workspace.