Gets the SSH client.

        This will check that the connection is still alive first, and reconnect
        if necessary.
179702
def get_client(self):
        
        if self._ssh is None:
            self._connect()
            return self._ssh
        else:
            try:
                chan = self._ssh.get_transport().open_session()
            except (socket.error, paramiko.SSHException):
                logger.warning("Lost connection, reconnecting...")
                self._ssh.close()
                self._connect()
            else:
                chan.close()
            return self._ssh
71622
def _get_ssl_sock(self):
        """"""
        assert self.scheme == u"https", self
        raw_connection = self.url_connection.raw._connection
        if raw_connection.sock is None:
            # sometimes the socket is not yet connected
            # see https://github.com/kennethreitz/requests/issues/1966
            raw_connection.connect()
        return raw_connection.sock
1371076
private function getClient()
    {
        if ($this->client === null) {
            $this->client = new $this->clientClassName($this->config->hostname, [
                'credentials' => \Grpc\ChannelCredentials::createInsecure(),
            ]);
        }

        return $this->client;
    }
383415
@Override
    public Client getClientInstance()
    {
        // if threadsafe recycle the same single instance; if not create a new
        // instance

        if (isThreadSafe())
        {
            logger.info("Returning threadsafe used client instance for persistence unit : " + persistenceUnit);
            if (client == null)
            {
                client = instantiateClient(persistenceUnit);
            }
        }
        else
        {
            logger.debug("Returning fresh client instance for persistence unit : " + persistenceUnit);
            // no need to hold a client reference.
            return instantiateClient(persistenceUnit);
        }

        return client;
    }
231275
public static Client getClient(ClientConfig config, String[] servers,
            int port) throws Exception {
        config.setTopologyChangeAware(true); // Set client to be topology-aware
        final Client client = ClientFactory.createClient(config);
        for (String server : servers) {
            // Try connecting servers one by one until we have a success
            try {
                client.createConnection(server.trim(), port);
                break;
            } catch(IOException e) {
                // Only swallow the exceptions from Java network or connection problems
                // Unresolved hostname exceptions will be thrown
            }
        }
        if (client.getConnectedHostList().isEmpty()) {
            throw new Exception("Unable to connect to any servers.");
        }
        return client;
    }
944656
def get_client_sock(addr):
    ""
    s = _socket.create_connection(addr)
    s.setsockopt(_socket.SOL_SOCKET, _socket.SO_REUSEADDR, True)
    s.setblocking(False)
    return s
1068167
def is_ssh_available(host, port=22):
    
    s = socket.socket()
    try:
        s.connect((host, port))
        return True
    except:
        return False
146938
def ssh_client(host):
    
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(host)
    return ssh
1053318
def get_client_ip(self):
        """"""

        if self.client_ip:
            return self.client_ip

        try:
            client = os.environ.get('SSH_CONNECTION',
                                    os.environ.get('SSH_CLIENT'))
            self.client_ip = client.split()[0]
            self.logdebug('client_ip: %s\n' % self.client_ip)
            return self.client_ip
        except:
            raise SSHEnvironmentError('cannot identify the ssh client '
                                      'IP address')
1100692
def _build_ssh_client(self):
        """"""
        # Create instance of SSHClient object
        remote_conn_pre = paramiko.SSHClient()

        # Load host_keys for better SSH security
        if self.system_host_keys:
            remote_conn_pre.load_system_host_keys()
        if self.alt_host_keys and path.isfile(self.alt_key_file):
            remote_conn_pre.load_host_keys(self.alt_key_file)

        # Default is to automatically add untrusted hosts (make sure appropriate for your env)
        remote_conn_pre.set_missing_host_key_policy(self.key_policy)
        return remote_conn_pre
723343
def _waitForSSHPort(self):
        
        logger.debug('Waiting for ssh port to open...')
        for i in count():
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            try:
                s.settimeout(a_short_time)
                s.connect((self.effectiveIP, 22))
                logger.debug('...ssh port open')
                return i
            except socket.error:
                pass
            finally:
                s.close()
1324664
def client_port(self):
        """"""
        address = self._client.getpeername()
        if isinstance(address, tuple):
            return address[1]

        # Maybe a Unix domain socket connection.
        return 0
244949
def needs_ssh(hostname, _socket=None):
    
    if hostname.lower() in ['localhost', '127.0.0.1', '127.0.1.1']:
        return False
    _socket = _socket or socket
    fqdn = _socket.getfqdn()
    if hostname == fqdn:
        return False
    local_hostname = _socket.gethostname()
    local_short_hostname = local_hostname.split('.')[0]
    if local_hostname == hostname or local_short_hostname == hostname:
        return False
    return True
758374
def is_connected(self):
        
        if self._client is not None:
            try:
                self._client.server_info()
            except ConnectionFailure:
                return False
            return True
        else:
            return False
63006
def get_connection(self, internal=False):
        
        # Determine the connection string to use.
        connect_string = self.connect_string
        if internal:
            connect_string = self.internal_connect_string

        # Stripe Redis protocol prefix coming from the API.
        connect_string = connect_string.strip('redis://')
        host, port = connect_string.split(':')

        # Build and return the redis client.
        return redis.StrictRedis(host=host, port=port, password=self._password)
509635
def _check_ssh(self, *args):
        """"""
        ssh = subprocess.Popen(
            args,
            stdin=subprocess.DEVNULL,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL)
        ssh.wait()
        return ssh.returncode == 0
1162626
def get_bitcoind_client():
    
    bitcoind_opts = get_bitcoin_opts()
    bitcoind_host = bitcoind_opts['bitcoind_server']
    bitcoind_port = bitcoind_opts['bitcoind_port']
    bitcoind_user = bitcoind_opts['bitcoind_user']
    bitcoind_passwd = bitcoind_opts['bitcoind_passwd']
    
    return create_bitcoind_service_proxy(bitcoind_user, bitcoind_passwd, server=bitcoind_host, port=bitcoind_port)