def tear_down_gce_cluster(conf):
credentials = GoogleCredentials.get_application_default()
gce = discovery.build("compute", "v1", credentials=credentials)
zone_operations = []
for node in conf["nodes"]:
print("Deleting node on virtual machine {}...".format(node["vmID"]))
zone_operations.append(delete_instance(gce, node["vmID"]))
for op in zone_operations:
while True:
result = gce.zoneOperations().get(project=GCP_PROJECT_ID, zone=GCE_ZONE_ID, operation=op["name"]).execute()
if result["status"] == "DONE":
# if "error" in result: raise Exception(result["error"]) # TODO handle error
print("Deleted node on virtual machine {}".format(result["targetLink"].split("/")[-1]))
break
sleep(1)
print("Cluster torn down correctly. Bye!")
评论列表
文章目录