Reputation: 1097
I've a VPC. Within that VPC, I create a subnet. 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 = {}
>>> 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['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?
Upvotes: 0
Views: 530
Reputation:
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. 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
Upvotes: 2