在我的代码中,我尝试从AMI创建图像,然后检查新图像的状态。但是,我正在努力解决图像的状态。这是我尝试过的最后一件事:
package_name = "RAY"
promotion_id = "101-234"
print "[....] Package Install Complete"
print "[....] Proceeding to Bake AMI"
imagename = package_name + promotion_id
newimageid = conn.create_image(instance_id=bakeryinstanceid, name=imagename, description="Please Work" )
print "[....] The new Base AMI ID for ", package_name, "is", newimageid
image_status = newimageid.state
这是我得到的错误:
Traceback (most recent call last):
File "./imagecreate.py", line 58, in <module>
image_status = newimageid.state
AttributeError: 'unicode' object has no attribute 'state'
查看新图片状态的最佳方式是什么?
答案 0 :(得分:3)
我相信create_image()
会返回一个包含图片ID的字符串,而不是Image对象。使用您的示例,您应该这样做:
image_status = get_image(newimageid)
然后 image_status.state
应该会显示一个显示图像状态的字符串,可能的值包括&#34;待定&#34;,&#34;可用&#34;和&#34;失败&#34;。
http://boto.readthedocs.org/en/latest/ref/ec2.html#boto.ec2.connection.EC2Connection.get_image http://boto.readthedocs.org/en/latest/ref/ec2.html#boto.ec2.connection.EC2Connection.create_image