私はVPCです。そのVPC内にサブネットを作成します。 なるべく慎重にして、サブネットの準備ができるまでそれ以上先に進めないようにしたいのですが、subnet.stateを実行すると、しばらくアクティブであっても常に「保留」と表示されます。
>>> subnet = {}
>>> subnet["public"] = conn.create_subnet(vpcid, "10.2.0.0/24")
>>> subnet["public"].state
u"pending"
subnet.update()を実行しようとしましたが、うまくいきません。
>>> subnet["public"].update()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: "Subnet" object has no attribute "update"
サブネットオブジェクトの状態を更新するための最良の方法は何ですか?
回答:
回答№1は2数分前にこの問題に遭遇しました。私は、VPCオブジェクトに似たサブネットオブジェクトのupdate()メソッドが欲しいのですが。これが私の解決策です:
#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