How to use the sshtunnel.ammendfromconfig function in sshtunnel

To help you get started, we’ve selected a few sshtunnel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stephank / libvirtweb / rfbproxy.py View on Github external
# Thus, when reading this piece of code, one might say that it flows a bit like:
   # ajax_console -> black voodoo magic -> connectVNC

   d = defer.Deferred()
   def genericfailure(failure):
      d.errback(failure)
      return failure

   # FIXME: Dirty nasty deferreds being passed around in inappropriate places
   reactor = parent.transport.reactor
   factory = RFBProxyClientFactory(parent, d)

   # Should we tunnel over SSH?
   if 'sshhost' in info:
      sshtunnel.ammendfromconfig(info)

      def sshconnect(service):
         protocol = factory.buildProtocol(None)
         transport = sshtunnel.RFBSSHChannel(protocol)
         request = forwarding.packOpen_direct_tcpip(
               (info['vnchost'], info['vncport']),    # The remote endpoint
               ('localhost', 0))                      # The local endpoint
         log.msg("Opening VNC connection to %s:%d over SSH tunnel" % (info['vnchost'], info['vncport']))
         service.openChannel(transport, request)
         return service

      sshtunnel.getservice(reactor, info).addCallbacks(sshconnect, genericfailure)

   # We shouldn't tunnel, set up a regular connection
   else:
      log.msg("Attempting VNC connection to %s:%d" % (info['vnchost'], info['vncport']))