code: def get_ssh_client(ip,
                     ssh_private_key_file,
                     ssh_user='root',
                     port=22,
                     timeout=600,
                     wait_period=10):
      
      if ip in CLIENT_CACHE:
          return CLIENT_CACHE[ip]
  
      start = time.time()
      end = start + timeout
  
      client = None
      while time.time() < end:
          try:
              client = establish_ssh_connection(
                  ip,
                  ssh_private_key_file,
                  ssh_user,
                  port,
                  timeout=wait_period
              )
              execute_ssh_command(client, 'ls')
          except:  # noqa: E722
              if client:
                  client.close()
              wait_period += wait_period
          else:
              CLIENT_CACHE[ip] = client
              return client
  
      raise IpaSSHException(
          'Attempt to establish SSH connection failed.'
      )
docs: Attempt to establish and test ssh connection.