Skip to content

Commit

Permalink
[1LP][RFR] Added delete_file_from_bucket & delete_image to GoogleClou…
Browse files Browse the repository at this point in the history
…dSystem (#238)

* fixed delete_bucket on GoogleCloudSystem (#237)

removed lambda

* fixed delete_file_from_bucket
  • Loading branch information
ohiliazo authored and mshriver committed Apr 12, 2018
1 parent 6526060 commit aa4bbda
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions wrapanapi/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,21 @@ def create_image(self, image_name, bucket_url, timeout=360):
"rawDisk": {"source": bucket_url}
}
operation = images.insert(project=self._project, body=data).execute()
wait_for(lambda: self._nested_operation_wait(operation['name'], zone=False), delay=0.5,
num_sec=timeout, message=" Creating image {}".format(image_name))
wait_for(self._nested_operation_wait,
func_kwargs={'operation_name': operation['name'], 'zone': False},
delay=0.5, num_sec=timeout, message=" Creating image {}".format(image_name))

def delete_image(self, image_name, timeout=360):
""" Delete image
Args:
image_name: Unique name of image
timeout: time to wait for operation (default=360)
"""
operation = self._compute.images().delete(project=self._project, image=image_name).execute()

wait_for(self._nested_operation_wait,
func_kwargs={'operation_name': operation['name'], 'zone': False},
delay=0.5, num_sec=timeout, message=" Deleting image {}".format(image_name))

def delete_bucket(self, bucket_name):
""" Delete bucket
Expand Down Expand Up @@ -265,7 +278,21 @@ def get_file_from_bucket(self, bucket_name, file_name):
except errors.HttpError as error:
if "Not Found" in error.content:
self.logger.info(
"File {} was not found in bucket {}".format(bucket_name, file_name))
"File {} was not found in bucket {}".format(file_name, bucket_name))
else:
raise error
return {}

def delete_file_from_bucket(self, bucket_name, file_name):
if self.bucket_exists(bucket_name):
try:
data = self._storage.objects().delete(bucket=bucket_name,
object=file_name).execute()
return data
except errors.HttpError as error:
if "No such object" in error.content:
self.logger.info(
"File {} was not found in bucket {}".format(file_name, bucket_name))
else:
raise error
return {}
Expand Down

0 comments on commit aa4bbda

Please sign in to comment.