Skip to content

Commit f42eeb9

Browse files
committed
Allow blocking region operations
1 parent 35d643d commit f42eeb9

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

libcloudforensics/providers/gcp/internal/common.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,20 @@ def GceApi(self) -> 'googleapiclient.discovery.Resource':
242242

243243
def BlockOperation(
244244
self, response: Dict[str, Any],
245-
zone: Optional[str] = None) -> Dict[str, Any]:
245+
zone: Optional[str] = None,
246+
region: Optional[str] = None) -> Dict[str, Any]:
246247
"""Block until API operation is finished.
247248
248249
Args:
249250
response (Dict): GCE API response.
250251
zone (str): Optional. GCP zone to execute the operation in. None means
251252
GlobalZone.
253+
region (str): Optional. GCP region to execute the operation in.
254+
None for zone AND region means GlobalZone.
252255
253256
Returns:
254257
Dict: Holding the response of a get operation on an API object of type
255-
zoneOperations or globalOperations.
258+
zoneOperations, regionOperations or globalOperations.
256259
257260
Raises:
258261
RuntimeError: If API call failed.
@@ -264,10 +267,14 @@ def BlockOperation(
264267
request = service.zoneOperations().get( # pylint: disable=no-member
265268
project=self.project_id, zone=zone, operation=response['name'])
266269
result = request.execute() # type: Dict[str, Any]
270+
elif region:
271+
request = service.regionOperations().get( # pylint: disable=no-member
272+
project=self.project_id, region=region, operation=response['name'])
267273
else:
268274
request = service.globalOperations().get( # pylint: disable=no-member
269275
project=self.project_id, operation=response['name'])
270-
result = request.execute()
276+
277+
result = request.execute() # type: Dict[str, Any]
271278

272279
if 'error' in result:
273280
raise RuntimeError(result['error'])

libcloudforensics/providers/gcp/internal/compute_base_resource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,6 @@ def AddLabels(self,
240240
resource=self.name, project=self.project_id,
241241
body=request_body).execute()
242242
if blocking_call:
243-
self.BlockOperation(response, zone=self.zone)
243+
self.BlockOperation(response, zone=self.zone, region=self.region)
244244

245245
return response

0 commit comments

Comments
 (0)