Here's the code
In forms.py
from django import forms
class CmdForm(forms.Form):
ip_address = forms.CharField(label='Enter IP address:')
command = forms.CharField(label='Command to execute:')
In Views.py
from django.shortcuts import render
from first_app.forms import CmdForm
from django.http import HttpResponse
def index(request):
my_dict = {'insert_me': ""}
return render(request,'first_app/index.html',context=my_dict)
def form_name_view(request):
if request.method == "POST":
form = CmdForm(request.POST)
if form.is_valid():
from netmiko import ConnectHandler
devices = {
'device_type':'cisco_ios',
'ip':'ip_address',
'username':'mee',
'password':'12345',
'secret':'12345',
}
ipInsert = request.POST.get('ip_address', '')
cmd = request.POST.get('command', '')
netconnect = ConnectHandler(**devices)
#print("connection established with", devices['ip'])
getIP = netconnect.send_command(ipInsert)
output = netconnect.send_command(cmd)
return render(request,'first_app/forms.html', {'form': form, 'output':output, 'getIP':getIP})
else:
form = CmdForm()
return render(request,'first_app/forms.html', {'form': form})
else:
return render(request,'first_app/forms.html', {})
however i m getting the error:-
NetMikoTimeoutException at /Automation_page/ Connection to device timed-out: cisco_ios ip_address:22 Request Method: POST Request URL: http://127.0.0.1:8000/Automation_page/ Django Version: 2.2.3 Exception Type: NetMikoTimeoutException Exception Value:
Connection to device timed-out: cisco_ios ip_address:22 Exception Location: C:\Users\karti\AppData\Local\Programs\Python\Python37-32\lib\site-packages\netmiko\base_connection.py in establish_connection, line 864 Python Executable: C:\Users\karti\AppData\Local\Programs\Python\Python37-32\python.exe Python Version: 3.7.3 Python Path:
['K:\Work\DevNet\first_project', 'C:\Users\karti\AppData\Local\Programs\Python\Python37-32\python37.zip', 'C:\Users\karti\AppData\Local\Programs\Python\Python37-32\DLLs', 'C:\Users\karti\AppData\Local\Programs\Python\Python37-32\lib', 'C:\Users\karti\AppData\Local\Programs\Python\Python37-32', 'C:\Users\karti\AppData\Local\Programs\Python\Python37-32\lib\site-packages']
why i m getting the time-out though my devices are up and running.
thanx to those willing to help.! :-)