In the previous video, we already create a configure menu. Now, in this video, we are 2
going to create a very config menu. Okay let’s just start. Open the visual studio code. 3
First, let’s create a new url, in this case I will create a verify_config url. 4
And this url will be redirected to verify_config function inside viws.py. 5
Now let’s create verify_config function inside views.py. I will copy and paste the 6
script from my note. 7
Okay let’s understand this cript. If we see here, the script is similar with configure 8
function that we have created in the previous video. Here we have an if statement. 9
if request.method is post, then this block script will be executed. 10
But if the request is get, this block script will be executed. 11
If we see here, the template file that we use here is the same template with configure function 12
which is config.html. 13
Okay now let’s understand the script if the request.method is post. 14
Here we define a blank list, later we will use this list to save the result of the verify command. 15
Here we have selected_device_id, mikrotik_command, and cisco_command. Thi is the same thing with 16
the previous video. 17
Then we do looping to the selected_device_id here. We login to the device using paramiko. 18
If the device is mikrotik, we looping to the mikrotik_command and send the command to the 19
mikrotik using exec_command. Then the output of the command will be saved to stdout variable. 20
We don’t need time sleep here. 21
Then, we append the result of the command to the result list. 22
If the device is cisco, we do invoke shell and send the command “terminal length 0”. 23
After that we looping to the cisco_command and send the command to the devices. 24
Don’t forget to always use time sleep if we doing network automation on cisco using paramiko. 25
Then we save the output of the command to the output variable. 26
Last, we append the output to the result list. 27
Here we join the result list using ‘\n’ or enter. 28
Here we return a template file named verify_result.html, and we use result as a context. 29
Now let’s create the template file. I already upload the verify_result.html file to the 30
resource section, so you can just download it and put it to the templates directory. 31
Okay now we have verify_result.html file here. But the name is not correct 32
we must have an underscore here, not dash. 33
Okay now let’s open the browser and navigate to 127.0.0.1:8000/verify_config. 34
Here we can see the verify config menu. We can choose the target devices that we want to verify 35
and put the command to verify configuration on mikrotik or cisco device here. 36
Okay now we have successfully create a verify config menu. We will not doing the test now, 37
we will doing the test later in the next video. 38
But before doing the test, we will create a log menu first. 39
Thankyou for watching and see you on the next video!