views:

43

answers:

0

How can I get data from paramiko channel class in real-time? I have 2 functions, the first one calls the second one from a HttpResponse (a generator basically):

return HttpResponse(ssh_exec(request, job_id))

ssh_exec:

def ssh_exec(request, job_id):
  job = ssh_job.objects.get(id=job_id)
  cmd_to_use = str(job.command) 
  client = paramiko.SSHClient()
  client.load_system_host_keys()
  client.connect('localhost', username='myuser', password='mypass')
  transport = client.get_transport()
  channel = transport.open_session()
  channel.exec_command(cmd_to_use)
  yield render_to_string('view.html', {'id': id, 'cmd': cmd_to_use})
  while not channel.exit_status_ready():
    response = channel.recv(128)
    yield "<li>%s</li>\n" % response
    log_file = log_file + response
    if job.cancel:
      client.close()
      job.log = log_file
      job.save()
  yield "</ul></div></div></td></tr></tbody></table></html>\n"
  job.save()

This only gives me the first line of output. How can I make it stream the output data? Thanks in advance