Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get IP address of the launched instance with Boto

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 ?

like image 453
Malintha Avatar asked Jul 03 '14 07:07

Malintha


People also ask

How can you check the IP address of your instance?

You view the internal and external IP addresses for your instance through either the Google Cloud console, the Google Cloud CLI, or the Compute Engine API. In the Google Cloud console, go to the VM instances page. If the VM instance has an external IP address, it appears under the External IP column.

When we launch EC2 in default VPC does it have an IP address?

When you launch an EC2 instance into a default VPC without specifying a specific subnet, it's automatically launched in one of the default subnets. Every instance in a default subnet receives a private IP address from the pool of addresses associated with that subnet and also a private DNS hostname.


1 Answers

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
like image 118
Thomas Orozco Avatar answered Oct 01 '22 02:10

Thomas Orozco