def delete(config, disk_name=None, disk_zone=None): # TODO: implement
# submit a request to the gce api for a new disk with the given parameters
# if inputs is not None, run a pipeline job to populate the disk
projectId = config.project_id
zones = [disk_zone if disk_zone is not None else x for x in config.zones.split(',')]
credentials = GoogleCredentials.get_application_default()
http = credentials.authorize(httplib2.Http())
if credentials.access_token_expired:
credentials.refresh(http)
gce = discovery.build('compute', 'v1', http=http)
for z in zones:
try:
resp = gce.disks().delete(project=projectId, zone=z, disk=disk_name).execute()
except HttpError as e:
raise DataDiskError("Couldn't delete data disk {n}: {reason}".format(n=disk_name, reason=e))
while True:
try:
result = gce.zoneOperations().get(project=projectId, zone=z, operation=resp['name']).execute()
except HttpError:
break
else:
if result['status'] == 'DONE':
break
评论列表
文章目录