如何使用Boto获取已启动实例的IP地址

时间:2022-07-25 02:57:02

I am launching instance in openstack using boto

我正在使用boto在openstack中启动实例

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

newMachine具有与已启动实例相关的信息。我努力了

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 ?

并且变量的ip_address和private_ip_address为空。如何获取已启动实例的ip_address?

1 个解决方案

#1


11  

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).

刷新值,直到实例进入运行状态。此时,IP应该存在(并不是说在实例处于运行状态之前你可以对IP做任何事情)。

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

#1


11  

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).

刷新值,直到实例进入运行状态。此时,IP应该存在(并不是说在实例处于运行状态之前你可以对IP做任何事情)。

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