예제 #1
0
    def test_strict_host_key_checking(self):
        t = bgtunnel.open(**self.default_open_kwargs)
        assert 'StrictHostKeyChecking=yes' not in t.get_ssh_options()
        assert 'StrictHostKeyChecking=no' not in t.get_ssh_options()
        t.close()

        for py_val, ssh_val in ((True, 'yes'), (False, 'no')):
            open_kwargs = self.default_open_kwargs.copy()
            open_kwargs['strict_host_key_checking'] = py_val
            t = bgtunnel.open(**open_kwargs)
            assert 'StrictHostKeyChecking={}'.format(ssh_val) in t.get_ssh_options()
            t.close()
예제 #2
0
    def test_strict_host_key_checking(self):
        t = bgtunnel.open(**self.default_open_kwargs)
        assert 'StrictHostKeyChecking=yes' not in t.get_ssh_options()
        assert 'StrictHostKeyChecking=no' not in t.get_ssh_options()
        t.close()

        for py_val, ssh_val in ((True, 'yes'), (False, 'no')):
            open_kwargs = self.default_open_kwargs.copy()
            open_kwargs['strict_host_key_checking'] = py_val
            t = bgtunnel.open(**open_kwargs)
            assert 'StrictHostKeyChecking={}'.format(
                ssh_val) in t.get_ssh_options()
            t.close()
예제 #3
0
 def connect(self):
     self.tunnel = bgtunnel.open(ssh_user=self.ssh_user,
                                 ssh_address=self.ssh_host,
                                 ssh_port=self.ssh_port,
                                 host_address=self.host_address,
                                 host_port=self.host_port,
                                 silent=True)
     self._set_hostport(self.host, self.tunnel.bind_port)
     return httplib.HTTPConnection.connect(self)
예제 #4
0
    def connect_channel(self, host, port):
        try:
            forwarder = bgtunnel.open(ssh_user=self.daemon_user,
                                      ssh_address=host,
                                      host_port=port)
        except SSHTunnelError as ex:
            sys.exit(ex)

        return forwarder
예제 #5
0
def create_tunnel(host, port, ssh_user):
    try:
        tunnel = bgtunnel.open(ssh_user=ssh_user,
                               ssh_address=host,
                               host_port=port)
    except SSHTunnelError as ex:
        sys.exit(ex)

    return tunnel
예제 #6
0
def create_tunnel(host, port, ssh_user):
    try:
        tunnel = bgtunnel.open(ssh_user=ssh_user,
                               ssh_address=host,
                               host_port=port)
    except SSHTunnelError as ex:
        sys.exit(ex)

    return tunnel
 def connect(self):
     self.tunnel = bgtunnel.open(
         ssh_user=self.ssh_user,
         ssh_address=self.ssh_host, ssh_port=self.ssh_port,
         host_address=self.host_address, host_port=self.host_port,
         silent=True
     )
     self._set_hostport(self.host, self.tunnel.bind_port)
     return httplib.HTTPConnection.connect(self)
예제 #8
0
    def __init__(self,
                 name,
                 ip,
                 endpoint=None,
                 docker_port=None,
                 timeout=None,
                 ssh_tunnel=None):
        """Instantiate a new ship.

        Args:
            name (string): the name of the ship.
            ip (string): the IP address of resolvable host name of the host.
            docker_port (int): the port the Docker daemon listens on.
            ssh_tunnel (dict): configuration for SSH tunneling to the remote
                Docker daemon.
        """
        Entity.__init__(self, name)
        self._ip = ip
        self._endpoint = endpoint or ip
        self._docker_port = int(docker_port or self.DEFAULT_DOCKER_PORT)
        self._tunnel = None

        if ssh_tunnel:
            if 'user' not in ssh_tunnel:
                raise exceptions.EnvironmentConfigurationException(
                    'Missing SSH user for ship {} tunnel configuration'.format(
                        self.name))
            if 'key' not in ssh_tunnel:
                raise exceptions.EnvironmentConfigurationException(
                    'Missing SSH key for ship {} tunnel configuration'.format(
                        self.name))

            self._tunnel = bgtunnel.open(ssh_address=self._endpoint,
                                         ssh_user=ssh_tunnel['user'],
                                         ssh_port=int(
                                             ssh_tunnel.get('port', 22)),
                                         host_port=self._docker_port,
                                         silent=True,
                                         identity_file=ssh_tunnel['key'])
            self._backend_url = 'http://localhost:{}'.format(
                self._tunnel.bind_port)

            # Apparently bgtunnel isn't always ready right away and this
            # drastically cuts down on the timeouts
            time.sleep(1)

        else:
            self._backend_url = 'http://{:s}:{:d}'.format(
                self._endpoint, self._docker_port)

        self._backend = docker.Client(base_url=self._backend_url,
                                      version=Ship.DEFAULT_DOCKER_VERSION,
                                      timeout=timeout
                                      or Ship.DEFAULT_DOCKER_TIMEOUT)
예제 #9
0
    def __init__(self, name, ip, endpoint=None, docker_port=None, timeout=None,
                 ssh_tunnel=None):
        """Instantiate a new ship.

        Args:
            name (string): the name of the ship.
            ip (string): the IP address of resolvable host name of the host.
            docker_port (int): the port the Docker daemon listens on.
            ssh_tunnel (dict): configuration for SSH tunneling to the remote
                Docker daemon.
        """
        Entity.__init__(self, name)
        self._ip = ip
        self._endpoint = endpoint or ip
        self._docker_port = int(docker_port or self.DEFAULT_DOCKER_PORT)
        self._tunnel = None

        if ssh_tunnel:
            if 'user' not in ssh_tunnel:
                raise exceptions.EnvironmentConfigurationException(
                    'Missing SSH user for ship {} tunnel configuration'.format(
                        self.name))
            if 'key' not in ssh_tunnel:
                raise exceptions.EnvironmentConfigurationException(
                    'Missing SSH key for ship {} tunnel configuration'.format(
                        self.name))

            self._tunnel = bgtunnel.open(
                ssh_address=self._endpoint,
                ssh_user=ssh_tunnel['user'],
                ssh_port=int(ssh_tunnel.get('port', 22)),
                host_port=self._docker_port,
                silent=True,
                identity_file=ssh_tunnel['key'])
            self._backend_url = 'http://localhost:{}'.format(
                self._tunnel.bind_port)
            
            # Apparently bgtunnel isn't always ready right away and this 
            # drastically cuts down on the timeouts
            time.sleep(1)

        else:
            self._backend_url = 'http://{:s}:{:d}'.format(
                self._endpoint, self._docker_port)

        self._backend = docker.Client(
            base_url=self._backend_url,
            version=Ship.DEFAULT_DOCKER_VERSION,
            timeout=timeout or Ship.DEFAULT_DOCKER_TIMEOUT)
예제 #10
0
    def test_settings(self):
        open_kwargs = self.default_open_kwargs.copy()
        t = bgtunnel.open(**open_kwargs)

        assert t.ssh_user == self.current_user
        assert t.host_port == self.host_port
        assert t.bind_port == self.bind_port
        assert t.ssh_address == self.ssh_address
        assert t.host_address == self.host_address
        assert t.bind_address == self.bind_address
        assert t.get_ssh_options() == [
            '-o', 'BatchMode=yes',
            '-o', 'ConnectionAttempts=1',
            '-o', 'ConnectTimeout=60',
        ]
        t.close()
예제 #11
0
파일: base.py 프로젝트: metakermit/bgtunnel
def test_create_tunnel():
    ssh_address = '1.2.3.4'
    host_address = '5.6.7.8'
    bind_address = '9.10.11.12'
    current_user = getuser()
    host_port = get_available_port()
    bind_port = get_available_port()
    t = bgtunnel.open(ssh_user=current_user, ssh_address=ssh_address,
                      host_address=host_address, bind_address=bind_address,
                      host_port=host_port, bind_port=bind_port,
                      ssh_path=dummy_ssh_cmd)

    assert t.ssh_user == current_user
    assert t.host_port == host_port
    assert t.bind_port == bind_port
    assert t.ssh_address == ssh_address
    assert t.host_address == host_address
    assert t.bind_address == bind_address
예제 #12
0
    def test_settings(self):
        open_kwargs = self.default_open_kwargs.copy()
        t = bgtunnel.open(**open_kwargs)

        assert t.ssh_user == self.current_user
        assert t.host_port == self.host_port
        assert t.bind_port == self.bind_port
        assert t.ssh_address == self.ssh_address
        assert t.host_address == self.host_address
        assert t.bind_address == self.bind_address
        assert t.get_ssh_options() == [
            '-o',
            'BatchMode=yes',
            '-o',
            'ConnectionAttempts=1',
            '-o',
            'ConnectTimeout=60',
        ]
        t.close()
예제 #13
0
    def __init__(self,
                 name,
                 ip,
                 endpoint=None,
                 docker_port=None,
                 socket_path=None,
                 api_version=None,
                 timeout=None,
                 ssh_tunnel=None,
                 tls=None,
                 tls_verify=False,
                 tls_ca_cert=None,
                 tls_cert=None,
                 tls_key=None,
                 ssl_version=None):
        """Instantiate a new ship.

        Args:
            name (string): the name of the ship.
            ip (string): the IP address of resolvable host name of the host.
            docker_port (int): the port the Docker daemon listens on.
            socket_path (string): the path to the unix socket the Docker daemon listens on.
            api_version (string): the API version of the Docker daemon.
            ssh_tunnel (dict): configuration for SSH tunneling to the remote
                Docker daemon.
        """
        Entity.__init__(self, name)
        self._ip = ip
        self._endpoint = endpoint or ip
        self._docker_port = int(docker_port
                                or (self.DEFAULT_DOCKER_TLS_PORT
                                    if tls else self.DEFAULT_DOCKER_PORT))
        self._socket_path = os.path.realpath(
            socket_path) if socket_path else None
        self._tunnel = None

        if ssh_tunnel:
            if 'user' not in ssh_tunnel:
                raise exceptions.EnvironmentConfigurationException(
                    'Missing SSH user for ship {} tunnel configuration'.format(
                        self.name))
            if 'key' not in ssh_tunnel:
                raise exceptions.EnvironmentConfigurationException(
                    'Missing SSH key for ship {} tunnel configuration'.format(
                        self.name))

            self._tunnel = bgtunnel.open(ssh_address=self._endpoint,
                                         ssh_user=ssh_tunnel['user'],
                                         ssh_port=int(
                                             ssh_tunnel.get('port', 22)),
                                         host_port=self._docker_port,
                                         silent=True,
                                         identity_file=ssh_tunnel['key'])

            # Make sure we use https through the tunnel, if tls is enabled
            proto = "https" if (tls or tls_verify) else "http"
            self._backend_url = '{:s}://localhost:{:d}'.format(
                proto, self._tunnel.bind_port)

            # Apparently bgtunnel isn't always ready right away and this
            # drastically cuts down on the timeouts
            time.sleep(1)

        elif self._socket_path is not None:
            self._backend_url = 'unix://{:s}'.format(self._socket_path)

        else:
            proto = "https" if (tls or tls_verify) else "http"
            self._backend_url = '{:s}://{:s}:{:d}'.format(
                proto, self._endpoint, self._docker_port)

        self._tls = None
        if tls:
            self._tls = docker.tls.TLSConfig(verify=tls_verify,
                                             client_cert=(tls_cert, tls_key),
                                             ca_cert=tls_ca_cert,
                                             ssl_version=ssl_version)

        self._backend = docker.Client(base_url=self._backend_url,
                                      version=str(api_version
                                                  or Ship.DEFAULT_API_VERSION),
                                      timeout=timeout
                                      or Ship.DEFAULT_DOCKER_TIMEOUT,
                                      tls=self._tls)
예제 #14
0
    def __init__(self, name, ip, endpoint=None, docker_port=None,
                 socket_path=None, api_version=None, timeout=None,
                 ssh_tunnel=None, tls=None, tls_verify=False,
                 tls_ca_cert=None, tls_cert=None, tls_key=None,
                 ssl_version=None):
        """Instantiate a new ship.

        Args:
            name (string): the name of the ship.
            ip (string): the IP address of resolvable host name of the host.
            docker_port (int): the port the Docker daemon listens on.
            socket_path (string): the path to the unix socket the Docker
                daemon listens on.
            api_version (string): the API version of the Docker daemon.
            ssh_tunnel (dict): configuration for SSH tunneling to the remote
                Docker daemon.
        """
        Entity.__init__(self, name)
        self._ip = ip
        self._endpoint = endpoint or ip
        self._docker_port = int(
            docker_port or
            (self.DEFAULT_DOCKER_TLS_PORT if tls
             else self.DEFAULT_DOCKER_PORT))
        self._socket_path = os.path.realpath(socket_path) \
            if socket_path else None
        self._tunnel = None

        if ssh_tunnel:
            if 'user' not in ssh_tunnel:
                raise exceptions.EnvironmentConfigurationException(
                    'Missing SSH user for ship {} tunnel configuration'.format(
                        self.name))
            if 'key' not in ssh_tunnel:
                raise exceptions.EnvironmentConfigurationException(
                    'Missing SSH key for ship {} tunnel configuration'.format(
                        self.name))

            self._tunnel = bgtunnel.open(
                ssh_address=self._endpoint,
                ssh_user=ssh_tunnel['user'],
                ssh_port=int(ssh_tunnel.get('port', 22)),
                host_port=self._docker_port,
                silent=True,
                identity_file=ssh_tunnel['key'])

            # Make sure we use https through the tunnel, if tls is enabled
            proto = "https" if (tls or tls_verify) else "http"
            self._backend_url = '{:s}://localhost:{:d}'.format(
                proto, self._tunnel.bind_port)

            # Apparently bgtunnel isn't always ready right away and this
            # drastically cuts down on the timeouts
            time.sleep(1)

        elif self._socket_path is not None:
            self._backend_url = 'unix://{:s}'.format(self._socket_path)

        else:
            proto = "https" if (tls or tls_verify) else "http"
            self._backend_url = '{:s}://{:s}:{:d}'.format(
                proto, self._endpoint, self._docker_port)

        self._tls = docker.tls.TLSConfig(
            verify=tls_verify,
            client_cert=(tls_cert, tls_key),
            ca_cert=tls_ca_cert,
            ssl_version=ssl_version) if tls else None

        self._backend = docker.Client(
            base_url=self._backend_url,
            version=str(api_version or Ship.DEFAULT_API_VERSION),
            timeout=timeout or Ship.DEFAULT_DOCKER_TIMEOUT,
            tls=self._tls)
예제 #15
0
파일: setuptunnel.py 프로젝트: andmalc/work
ADDRESS='
import bgtunnel
forwarder = bgtunnel.open(ssh_user='******', ssh_address='1.2.3.4',
            ...                           host_port=1433)