-
-class SSHForwarder(object):
- def __init__(self, cri, forwarding_flag, *port_pairs):
- self._proc = None
-
- if forwarding_flag == 'R':
- self._host_port = port_pairs[0].remote_port
- command_line = ['-%s%i:localhost:%i' % (forwarding_flag,
- port_pair.remote_port,
- port_pair.local_port)
- for port_pair in port_pairs]
- else:
- self._host_port = port_pairs[0].local_port
- command_line = ['-%s%i:localhost:%i' % (forwarding_flag,
- port_pair.local_port,
- port_pair.remote_port)
- for port_pair in port_pairs]
-
- self._device_port = port_pairs[0].remote_port
-
- self._proc = subprocess.Popen(
- cri.FormSSHCommandLine(['sleep', '999999999'], command_line),
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- stdin=subprocess.PIPE,
- shell=False)
-
- util.WaitFor(lambda: cri.IsHTTPServerRunningOnPort(self._device_port), 60)
- logging.debug('ssh forwarder created: %s', command_line)
-
- @property
- def url(self):
- assert self._proc
- return 'http://localhost:%i' % self._host_port
-
- def Close(self):
- if self._proc:
- self._proc.kill()
- self._proc = None
-