Skip to content

Commit 0d16fec

Browse files
authored
Allow Region-level blocking operation (#543)
* Add machine_type param to StartAnalysisVm and pass it through to GetOrCreateAnalysisVm * Check variable * Lint * Allow blocking region operations * Lint
1 parent 434ad20 commit 0d16fec

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

libcloudforensics/providers/gcp/internal/common.py

Lines changed: 10 additions & 4 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.
@@ -263,11 +266,14 @@ def BlockOperation(
263266
if zone:
264267
request = service.zoneOperations().get( # pylint: disable=no-member
265268
project=self.project_id, zone=zone, operation=response['name'])
266-
result = request.execute() # type: Dict[str, Any]
269+
elif region:
270+
request = service.regionOperations().get( # pylint: disable=no-member
271+
project=self.project_id, region=region, operation=response['name'])
267272
else:
268273
request = service.globalOperations().get( # pylint: disable=no-member
269274
project=self.project_id, operation=response['name'])
270-
result = request.execute()
275+
276+
result = request.execute() # type: Dict[str, Any]
271277

272278
if 'error' in result:
273279
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)