I have a python script that prints console output from a network device and its working great, I get an output like this:Python Console Output
Now I'm trying to run it from a web server with Flask, and It's working great except that the output in the rendered HTML template is one string like this:
display mac-address 44FB-5ABC-9788
---------------------------------------------------------------------------
MAC Address VLAN/VSI/BD Learned-From Type
------------------------------------------------------------------------------
44fb-5abc-9788 1579/-/- Eth-Trunk1 amic
------------------------------------------------------------------------------
Total items displayed = 1
What I want is the same output in the HTML page as python console, here is what I have with flask:
@app.route('/result',methods = ['POST', 'GET'])
def result():
if request.method == 'POST':
hw_input = str(request.form.get("hw"))
commandinput = str(request.form.get("command"))
user = 'user'
passv = 'pass'
passg = 'password'
user_prompt = '.*name:'
pass_prompt = '.*assword:'
hw_prompt = '.*>'
hw_connect = 'telnet ' + hw_input
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname='host', username=user, password=passv)
interact = SSHClientInteraction(ssh_client, timeout=10, display=False)
interact.send(hw_connect)
interact.expect(user_prompt)
interact.send(user)
interact.expect(pass_prompt)
interact.send(passg)
interact.expect(hw_prompt)
interact.send(commandinput)
interact.expect(hw_prompt)
output = interact.current_output_clean
return render_template("result.html",result = output)