We will now review the topics discussed through some use cases that are being used as common scenarios. These use cases, along with helping us to understand the concepts, can also be leveraged or enhanced to create complex automation that can perform actions at very large scale.
Use cases
Using regular expressions (regex)
Let us examine a basic use of regex by parsing a base configuration containing the interface configuration of a router.
The task is to identify the interfaces that have trunk enabled:
import re
sampletext="""
interface fa0/1
switchport mode trunk
no shut
interface fa0/0
no shut
interface fa1/0
switchport mode trunk
no shut
interface fa2/0
shut
interface fa2/1
switchport mode trunk
no shut
interface te3...