diff --git a/libcloudforensics/providers/gcp/internal/common.py b/libcloudforensics/providers/gcp/internal/common.py index b1812441..683b587e 100644 --- a/libcloudforensics/providers/gcp/internal/common.py +++ b/libcloudforensics/providers/gcp/internal/common.py @@ -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. @@ -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']) diff --git a/libcloudforensics/providers/gcp/internal/compute_base_resource.py b/libcloudforensics/providers/gcp/internal/compute_base_resource.py index a206b5f5..46b46b57 100644 --- a/libcloudforensics/providers/gcp/internal/compute_base_resource.py +++ b/libcloudforensics/providers/gcp/internal/compute_base_resource.py @@ -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