How to get IP address of the launched instance with Boto
Asked Answered
B

1

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 ?

Brottman answered 3/7, 2014 at 7:0 Comment(0)
P
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
Propitiatory answered 3/7, 2014 at 7:20 Comment(3)
I had a problem with this and calling instance.update() again 5 seconds after it entered "running" state solved it.Hamamelidaceous
Can an instance not have multiple ip addresses?Chameleon
if you want the private IP address, you can use instance.private_ip_addressTenedos

© 2022 - 2024 — McMap. All rights reserved.