Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions libcloudforensics/providers/gcp/internal/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,20 @@ def GceApi(self) -> 'googleapiclient.discovery.Resource':

def BlockOperation(
self, response: Dict[str, Any],
zone: Optional[str] = None) -> Dict[str, Any]:
zone: Optional[str] = None,
region: Optional[str] = None) -> Dict[str, Any]:
"""Block until API operation is finished.

Args:
response (Dict): GCE API response.
zone (str): Optional. GCP zone to execute the operation in. None means
GlobalZone.
region (str): Optional. GCP region to execute the operation in.
None for zone AND region means GlobalZone.

Returns:
Dict: Holding the response of a get operation on an API object of type
zoneOperations or globalOperations.
zoneOperations, regionOperations or globalOperations.

Raises:
RuntimeError: If API call failed.
Expand All @@ -263,11 +266,14 @@ def BlockOperation(
if zone:
request = service.zoneOperations().get( # pylint: disable=no-member
project=self.project_id, zone=zone, operation=response['name'])
result = request.execute() # type: Dict[str, Any]
elif region:
request = service.regionOperations().get( # pylint: disable=no-member
project=self.project_id, region=region, operation=response['name'])
else:
request = service.globalOperations().get( # pylint: disable=no-member
project=self.project_id, operation=response['name'])
result = request.execute()

result = request.execute() # type: Dict[str, Any]

if 'error' in result:
raise RuntimeError(result['error'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,6 @@ def AddLabels(self,
resource=self.name, project=self.project_id,
body=request_body).execute()
if blocking_call:
self.BlockOperation(response, zone=self.zone)
self.BlockOperation(response, zone=self.zone, region=self.region)

return response
Loading