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

2024-03-29 13:06:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用boto在openstack中启动实例

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

newmachine=myinstance.instances[0]

newMachine拥有与启动的实例相关的信息。我试过了

vars(newmachine)

变量的ip地址和私有ip地址为空。如何获取已启动实例的ip地址?


Tags: instances实例instancerunipopenstack地址count
1条回答
网友
1楼 · 发布于 2024-03-29 13:06:06

刷新该值,直到实例进入运行状态。此时,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

相关问题 更多 >