Thẻ không thể được thực hiện cho đến khi cá thể đã được tạo. Mặc dù hàm này được gọi là create_instance, nhưng nó thực sự làm là đặt trước và dụ. Sau đó, trường hợp đó có thể hoặc không thể được khởi chạy. (Thông thường, nhưng đôi khi ...)
Vì vậy, bạn không thể thêm thẻ cho đến khi thẻ được khởi chạy. Và không có cách nào để nói nó được tung ra mà không bỏ phiếu cho nó. Giống như vậy:
reservation = conn.run_instances(...)
# NOTE: this isn't ideal, and assumes you're reserving one instance. Use a for loop, ideally.
instance = reservation.instances[0]
# Check up on its status every so often
status = instance.update()
while status == 'pending':
time.sleep(10)
status = instance.update()
if status == 'running':
instance.add_tag("Name","{{INSERT NAME}}")
else:
print('Instance status: ' + status)
return None
# Now that the status is running, it's not yet launched. The only way to tell if it's fully up is to try to SSH in.
if status == "running":
retry = True
while retry:
try:
# SSH into the box here. I personally use fabric
retry = False
except:
time.sleep(10)
# If we've reached this point, the instance is up and running, and we can SSH and do as we will with it. Or, there never was an instance to begin with.
Nguồn
2012-05-24 02:39:35
Bạn thực sự có thể chỉ định thẻ tại thời điểm tạo thời gian - xem câu trả lời của tôi: https://stackoverflow.com/a/43723682/4988742 –