【问题标题】:Boto ec2 creating disk takes a long time to be created - PythonBoto ec2创建磁盘需要很长时间才能创建 - Python
【发布时间】:2015-04-23 01:51:59
【问题描述】:

我正在编写关于使用 boto 在 EC2 中创建、附加、分离和销毁 EBS 卷的概念证明:

import time
import ec2.boto

conn = boto.ec2.connect_to_region("us-west-2",
            aws_access_key_id=AWS_ACCESS_KEY,
            aws_secret_access_key=AWS_SECRET_KEY)

reservation = conn.run_instances(
                'ami-1fa78f2f',
                instance_type='m3.medium')

instance = reservation.instances[0]
instance.add_tag('Name', 'volume_test')


while instance.state != 'running':
        time.sleep(10)
        instance.update() # Updates Instance metadata
        print 'Instance state: ', instance.state

print "attempting to attach volume"
vol = conn.create_volume(10, instance.placement)
while vol.status != 'available':
        print 'Vol state: ', vol.status
        time.sleep(20)

vol.attach(instance.id, '/dev/sdh')

这是一个 10GBv 的卷,但它永远不会脱离“正在创建”状态:

# python test.py 
Instance state:  pending
Instance state:  pending
Instance state:  running
attempting to attach volume
Vol state:  creating
Vol state:  creating
Vol state:  creating
Vol state:  creating
Vol state:  creating
Vol state:  creating
Vol state:  creating
Vol state:  creating
Vol state:  creating

是我做错了什么,还是 EC2 太慢而无法创建卷?

【问题讨论】:

    标签: python amazon-web-services amazon-ec2 boto


    【解决方案1】:

    您没有更新循环内的音量。试试这个。

    print "attempting to attach volume"
    vol = conn.create_volume(10, instance.placement)
    while vol.status != 'available':
        print 'Vol state: ', vol.status
        time.sleep(20)
        vol.update()
    

    【讨论】:

    • 对于来自 Google 的用户:vol.status 现在是 vol.state,vol.update 现在是 vol.reload。
    猜你喜欢
    • 2015-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-22
    • 1970-01-01
    • 2014-04-13
    • 2013-10-05
    • 1970-01-01
    相关资源
    最近更新 更多