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

Try it free for 30 minutesRun it on Lite from £3 a day

The free demo needs no card and no email. Every lab plan includes every guided lab.

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.

DevicePlatformMgmt addressLoopbackAS
srx1Juniper Junos 24.4 (vSRX)10.10.20.4110.255.0.365003
r1Cisco IOS 15.9 (IOSv)10.10.20.1110.255.0.165001

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

  1. The XML behind the CLI
  2. Turn on the APIs
  3. NETCONF by hand
  4. ncclient and XPath
  5. PyEZ: facts and exceptions
  6. RPCs from Python
  7. Tables and views
  8. Safe configuration from a template
  9. 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.

Topology of Junos automation - XML API NETCONF PyEZ and the REST API3 nodes and 1 network, 4 links. Every link is listed as text below the diagram.devboxsrx1r1Mgmteth0ge-0/0/0Gi0/1fxp0Gi0/0
3 nodes and 1 network, with the interface names each link uses. On a narrow screen, scroll the diagram sideways.
Nodes in Junos automation: XML API, NETCONF, PyEZ and the REST API, with the image each runs and the vCPU and RAM it’s set to
NodeDeviceImage in Add NodeSet to
devboxEVE-NG GUI server (Docker)eve-gui-server:latest1 vCPU, 1,024 MB
srx1Juniper vSRX NextGen templatevsrxng-24.4R1.92 vCPU, 4,096 MB
r1Cisco IOSvvios-adventerprisek9-m.spa.159-3.m91 vCPU, 512 MB

How to open this lab

  1. Sign in to your workspace at lab.cloudlabbox.com.

  2. In File Manager, open Shared, then the folder Network Automation - CCNA and CCNP Automation guided labs.

  3. Open 23 - Junos automation - XML API NETCONF PyEZ and the REST API and 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

All 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.