【问题标题】:How to get IP address of the launched instance with Boto如何使用 Boto 获取已启动实例的 IP 地址
【发布时间】:2014-08-24 04:22:39
【问题描述】:

我正在使用 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_address和private_ip_address为空。如何获取启动实例的ip_address?

【问题讨论】:

    标签: python amazon-ec2 boto openstack


    【解决方案1】:

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

    【讨论】:

    • 我遇到了这个问题,在它进入“运行”状态 5 秒后再次调用 instance.update() 解决了它。
    • 一个实例不能有多个ip地址吗?
    • 如果想要私有IP地址,可以使用instance.private_ip_address
    猜你喜欢
    • 1970-01-01
    • 2020-06-27
    • 2013-04-26
    • 1970-01-01
    • 2016-09-18
    • 2017-01-02
    • 2015-03-24
    • 2016-08-31
    • 1970-01-01
    相关资源
    最近更新 更多