[英]AWS boto: how to refresh subnet.state after creating it? It's stuck in 'pending' forever and there's no update()
I've a VPC. 我有一个VPC。 Within that VPC, I create a subnet.
在该VPC中,我创建一个子网。 I'd like to be as careful as possible, and not proceed any further until the subnet is truly ready.
我想尽可能地小心,在子网真正准备就绪之前,不要再进行任何操作。 But if I do subnet.state, it always says 'pending', even though it's been active for a while.
但是,如果我执行subnet.state,即使它已经活跃了一段时间,它也会始终显示“ pending”。
>>> subnet = {}
>>> subnet['public'] = conn.create_subnet(vpcid, '10.2.0.0/24')
>>> subnet['public'].state
u'pending'
I tried to do subnet.update() but that doesn't work. 我试着做subnet.update(),但这不起作用。
>>> subnet['public'].update()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Subnet' object has no attribute 'update'
What's the best way to update the state of a subnet object? 更新子网对象状态的最佳方法是什么?
I just ran into this issue a few minutes ago. 几分钟前我刚遇到这个问题。 I would like for there to be an update() method on subnet objects similar to the VPC objects.
我希望在类似于VPC对象的子网对象上有一个update()方法。 Here is my solution:
这是我的解决方案:
#generic subnet creation method
def create_subnet(connection, vpc, cidr, name, test_mode=True):
print("Creating subnet with CIDR block", cidr)
subnet = connection.create_subnet(vpc.id, cidr_block=cidr, dry_run=test_mode)
#wait for subnet to become live
while subnet.state == 'pending':
subnets = connection.get_all_subnets()
for item in subnets:
if item.id == subnet.id:
subnet.state = item.state
time.sleep(5)
#tag the subnet
subnet.add_tag("Name", name)
print("Done")
return subnet
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.