code: def associate_keys(user_dict, client):
      
      added_keys = user_dict['keypairs']
  
      print ">>>Updating Keys-Machines association"
      for key in added_keys:
          machines = added_keys[key]['machines']
          if machines:
              try:
                  for machine in machines:
                      cloud_id = machine[0]
                      machine_id = machine[1]
                      ssh_user = machine[3]
                      ssh_port = machine[-1]
                      key = client.keys[key]
                      cloud = cloud_from_id(client, cloud_id)
                      cloud.update_machines()
                      mach = machine_from_id(cloud, machine_id)
                      public_ips = mach.info.get('public_ips', None)
                      if public_ips:
                          host = public_ips[0]
                      else:
                          host = ""
                      key.associate_to_machine(cloud_id=cloud_id, machine_id=machine_id, host=host, ssh_port=ssh_port,
                                               ssh_user=ssh_user)
  
                      print "associated machine %s" % machine_id
              except Exception as e:
                  pass
      client.update_keys()
      print
docs: This whole function is black magic, had to however cause of the way we keep key-machine association