code: def ssh_to_task(task) -> paramiko.SSHClient:
    
  
    username = task.ssh_username
    hostname = task.public_ip
    ssh_key_fn = get_keypair_fn()
    print(f"ssh -i {ssh_key_fn} {username}@{hostname}")
    pkey = paramiko.RSAKey.from_private_key_file(ssh_key_fn)
  
    ssh_client = paramiko.SSHClient()
    ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    assert ssh_client
  
    counter = 1
    while True:
      try:
        ssh_client.connect(hostname=hostname, username=username, pkey=pkey)
        if counter % 11 == 0:  # occasionally re-obtain public ip, machine could've gotten restarted
          hostname = task.public_ip
        break
      except Exception as e:
        print(
          f'{task.name}: Exception connecting to {hostname} via ssh (could be a timeout): {e}')
        time.sleep(RETRY_INTERVAL_SEC)
  
    return ssh_client
docs: Create ssh connection to task's machine
  
    returns Paramiko SSH client connected to host.