8

I am launching instance in openstack using boto

myinstance = conn.run_instances('ami-0000007d',min_count=1,max_count=1, instance_type = 'm1.small')

newmachine=myinstance.instances[0]

newMachine has the info related to the launched instance. I have tried

vars(newmachine)

and the ip_address and private_ip_address of variables are empty. How can I obtain the ip_address of the launched instance ?

Malintha
  • 4,512
  • 9
  • 48
  • 82

1 Answers1

13

Refresh the value until the instance enters Running state. At that point, the IP should be present (not that there's anything you could do with the IP before the instance is in running state).

reservation = conn.run_instances(...)

instance = reservation.instances[0]

while instance.update() != "running":
    time.sleep(5)  # Run this in a green thread, ideally

print instance.ip_address
Thomas Orozco
  • 53,284
  • 11
  • 113
  • 116