code: def establish_ssh_connection(ip,
                               ssh_private_key_file,
                               ssh_user,
                               port,
                               attempts=5,
                               timeout=None):
      
      client = paramiko.SSHClient()
      client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  
      while attempts:
          try:
              client.connect(
                  ip,
                  port=port,
                  username=ssh_user,
                  key_filename=ssh_private_key_file,
                  timeout=timeout
              )
          except:  # noqa: E722
              attempts -= 1
              time.sleep(10)
          else:
              return client
  
      raise IpaSSHException(
          'Failed to establish SSH connection to instance.'
      )
docs: Establish ssh connection and return paramiko client.
  
      Raises:
          IpaSSHException: If connection cannot be established
              in given number of attempts.