/ / AWS boto: come aggiornare subnet.state dopo averlo creato? È bloccato in 'sospeso' per sempre e non c'è aggiornamento () - python, amazon-web-services, boto

Boto di AWS: come aggiornare subnet.state dopo averlo creato? È bloccato in 'sospeso' per sempre e non c'è aggiornamento () - python, amazon-web-services, boto

Ho un VPC. All'interno di quel VPC, creo una sottorete. Mi piacerebbe essere il più attento possibile e non procedere oltre finché la sottorete non è veramente pronta, ma se faccio subnet.state, dice sempre "in sospeso", anche se è attivo da un po '.

>>> subnet = {}
>>> subnet["public"] = conn.create_subnet(vpcid, "10.2.0.0/24")
>>> subnet["public"].state
u"pending"

Ho provato a fare subnet.update () ma non funziona.

>>> subnet["public"].update()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: "Subnet" object has no attribute "update"

Qual è il modo migliore per aggiornare lo stato di un oggetto subnet?

risposte:

2 per risposta № 1

Mi sono imbattuto in questo problema pochi minuti fa. Mi piacerebbe che ci fosse un metodo update () sugli oggetti subnet simili agli oggetti VPC. Ecco la mia soluzione:

#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