Workbook sample
This is a sample challenge from a full-scale lab of the DevNet Expert Masterclass.
All the features, libraries and platforms used in a lab challenge like this, would have been covered on previous lectures and workbook tasks.
Each of the 4 full-scale lab has between 6 and 10 different challenges each. All of them will be graded during the Masterclass, and individual feedback on your solutions will be provided.
This specific challenge 308 covers the following blueprint items:
2.3 Build, manage, and operate a Python-based CLI application to use a REST API
2.5 Create a RESTCONF or NETCONF payload based on a given YANG module, and interpret the response
2.7 Configure network devices on an existing infrastructure by using NETCONF or RESTCONF, given YANG analysis tools
2.8.c Use of variables and templating
3.1 Create, modify, and troubleshoot scripts by using Python libraries and SDK documentation to automate against APIs (..., IOS XE, ...)
3.2 Automate the configuration of a Cisco IOS XE network device (based on a provided architecture and configuration), including these components:
3.2.a Interfaces
3.2.c VLANs
3.2.g BGP and OSPF neighbors
The initial content of the mentioned 3 files is provided below.
expertconf.py
import click
import requests
import json
requests.packages.urllib3.disable_warnings()
from jinja2 import Template
from ncclient import manager
class OspfRouter():
intf_type = None
intf_ip_addr = None
physical_intf_number = None
subintf_vlan = None
def render_netconf(self):
# Requirement C
netconf_data = ospf_netconf_template.render({
"intf_type": self.intf_type,
"physical_intf_number": self.physical_intf_number,
"subintf_vlan": self.subintf_vlan,
"intf_ip_addr": self.intf_ip_addr
})
return netconf_data
def render_restconf(self):
# Requirement C
restconf_data = ospf_restconf_template.render({"ospf": {
"intf_type": self.intf_type,
"physical_intf_number": self.physical_intf_number,
"subintf_vlan": self.subintf_vlan,
"intf_ip_addr": self.intf_ip_addr
}})
return restconf_data
@click.group()
def expertconf():
pass
@click.command()
# Requirement A
@click.option('--password', prompt=True, hide_input=True)
def ospf(router_address, username, ethsubintf, intfaddr, rfc, password):
router = OspfRouter()
# Requirement D
if rfc == "6241":
# Requirement E
# config = router.render.()
elif rfc == "8040":
# Requirement F
# config = router.render.()
rsp.raise_for_status()
# Requirement A
if __name__ == "__main__":
expertconf()
ospf-6241.j2
# Requirement B
ospf-8040.j2
# Requirement B