Execute
NDFC Python

At this point, you are ready to execute your command line program to provision new VRF(s) and Network(s) to your NDFC instance as well as perform the attachment to the leaf switches that are defined in your YAML data.

Step 1 - Create Shell Script to Set ND Password as Env Var

First, let's create a quick shell script to set an environment variable for your ND user's password. Again, your command line program will first try to leverage an environment variable named ND_PASSWORD for authentication purposes with your ndfc ndclient object.



touch ~/workspace/ndfclab/scripts/ndfc_access_info.sh
cat <<EOF >> ~/workspace/ndfclab/scripts/ndfc_access_info.sh
export ND_PASSWORD=cisco.123
 
EOF


Step 2 - Source the Shell Script to Set Env Var

Source the simple shell script to set the ND_PASSWORD env variable.


source ndfc_access_info.sh

You can check if your env variable is set by issuing the below command in your VSCode terminal window:


env | grep ND_PASSWORD


$ env | grep ND_PASSWORD
ND_PASSWORD=cisco.123

Step 3 - Execute Overlay Script to Get Current VRFs

Your code is ready to go and you're ready to authenticate with NDFC. Execute your command line program to get your current VRFs. These should be the ones created with the NDFC GUI and Postman.


python overlay_script.py --nd 10.15.0.98 --username admin --fabric fabric-stage --get vrfs 


Processing VRFs ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:01
               NDFC VRFs                
┏━━━━━━━━━━━━┳━━━━━━━┳━━━━━━┳━━━━━━━━━━┓
┃ VRF        ┃ VNI   ┃ VLAN ┃ Status   ┃
┡━━━━━━━━━━━━╇━━━━━━━╇━━━━━━╇━━━━━━━━━━┩
│ PostmanVRF │ 50001 │ 2001 │ DEPLOYED │
└────────────┴───────┴──────┴──────────┘

Step 4 - Execute Overlay Script to Get Current Networks

Execute your command line program to get your current Networks. These should be the ones created with the NDFC GUI and Postman.


python overlay_script.py --nd 10.15.0.98 --username admin --fabric fabric-stage --get networks 


Processing networks ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:01
                             NDFC Networks                              
┏━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Network     ┃ VNI   ┃ VLAN ┃ Anycast Gw      ┃ VRF        ┃ Status   ┃
┡━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ PostmanNet1 │ 30001 │ 2301 │ 192.168.11.1/24 │ PostmanVRF │ DEPLOYED │
└─────────────┴───────┴──────┴─────────────────┴────────────┴──────────┘

Step 5 - Execute Overlay Script to Deploy VRFs and Networks with Python

Execute your command line program by passing in the YAML data to drive the creation of a new VRF and Networks with attachment to your specified leaf switches.


python overlay_script.py --nd 10.15.0.98 --username admin --fabric fabric-stage --filename overlay_vars.yml 


VRF PythonVRF created successfully!
VRF PythonVRF attached successfully!
VRF PythonVRF deployed successfully!
Network PythonNet1 created successfully!
Network PythonNet1 attached successfully!
Network PythonNet1 deployed successfully!

Step 6 - Re-Execute Overlay Script to Get Current VRFs

Execute your command line program to get your current VRFs which should display your newly created PythonVRF alongside your NDFC GUI and Postman VRFs.


python overlay_script.py --nd 10.15.0.98 --username admin --fabric fabric-stage --get vrfs 


Processing VRFs ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:01
               NDFC VRFs                
┏━━━━━━━━━━━━┳━━━━━━━┳━━━━━━┳━━━━━━━━━━┓
┃ VRF        ┃ VNI   ┃ VLAN ┃ Status   ┃
┡━━━━━━━━━━━━╇━━━━━━━╇━━━━━━╇━━━━━━━━━━┩
│ PostmanVRF │ 50001 │ 2001 │ DEPLOYED │
│ PythonVRF  │ 50002 │ 2002 │ DEPLOYED │
└────────────┴───────┴──────┴──────────┘

Step 7 - Execute Overlay Script to Get Current Networks

Execute your command line program to get your current Networks which should display your newly created PythonNet1 alongside your NDFC GUI and Postman Networks.


python overlay_script.py --nd 10.15.0.98 --username admin --fabric fabric-stage --get networks 


Processing networks ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:01
                             NDFC Networks                              
┏━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Network     ┃ VNI   ┃ VLAN ┃ Anycast Gw      ┃ VRF        ┃ Status   ┃
┡━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ PostmanNet1 │ 30001 │ 2301 │ 192.168.11.1/24 │ PostmanVRF │ DEPLOYED │
│ PythonNet1  │ 30002 │ 2302 │ 172.16.1.1/24   │ PythonVRF  │ DEPLOYED │
└─────────────┴───────┴──────┴─────────────────┴────────────┴──────────┘

Step 8 - Log Back Into NDFC If Required

Navigate back to your browser tab where NDFC is located and log back in if needed.

  1. Ensure Fabric Controller is selected
  2. Click Manage
  3. Click Fabrics



  4. Double-click the fabric-stage



Step 9 - Review Updated Fabric Dashboard

Review your updated fabric dashboard that now shows three (2) VRFs (L3VNIs) and Networks (L2VNIs) each.



Step 10 - Review VRFs

Navigate to VRFs and review VRF:

  1. Click VRFs
  2. Confirm PythonVRF was created and deployed to your leaf switches
  3. Double-click PythonVRF to review the VRF details



Step 11 - Review VRFs Attachments

Navigate to VRF Attachments:

  1. Click VRF Attachments
  2. Confirm PythonVRF was deployed and attached to your switches



Step 12 - Review VRF Associated Network(s)

Navigate to Networks:

  1. Click Networks
  2. Confirm PythonNet1 is associated to PythonVRF and deployed to your switches
  3. Click the close button



Step 13 - Review Networks

Navigate to Networks and review Networks and attachments:

  1. Click Networks
  2. Confirm PythonNet1 was created and deployed to your leaf switches
  3. Double-click PythonNet1 to review the Network details



Step 14 - Review Network Attachments

Navigate to Networks and review Networks and attachments:

  1. Click Network Attachments
  2. Confirm PythonNet1 was deployed and attached to your switches



Step 15 - Review Network Associated VRF(s)

Navigate to VRFs:

  1. Click VRF
  2. Confirm PythonVRF is associated to PythonNet1 and deployed to your switches
  3. Click the close button




Step 16 - Close All Open VSCode Tabs For Python in Preparation for Ansible

Navigate back to your VSCode application. On the keyword press Ctrl + K + W. This should close all open tabs to clear your workspace for the next section, Ansible!

As you can see by writing this code, there are quite a bit of packages to manage, classes and functions to define in architecting your Python objects, and manage your variables to drive your automation. This lab is only showing a simple, mix of ways to achieve this to expose you to various things and aspects in Python. In going down this path with Python, you're essentially starting to define, architect, and create your own framework. This is something you can definitely tackle. However, this is also where something like Ansible is very convenient, powerful, and ready to go - it's a framework that handles all this today, with a simplified, low-coding approach.

Continue to the next section to get started with Ansible for NDFC!