Skip to content

Commit a10682c

Browse files
authored
Create new ListSnapshots method in GCP Compute module (#538)
* Update deps * Update python versions * Create new ListSnapshots method
1 parent 4effe14 commit a10682c

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

  • libcloudforensics/providers/gcp/internal

libcloudforensics/providers/gcp/internal/compute.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,33 @@ def ListInstances(self) -> Dict[str, 'GoogleComputeInstance']:
237237

238238
return instances
239239

240+
def ListSnapshots(self, filter_string: str | None = None) -> Dict[str, Any]:
241+
"""List snapshots in project.
242+
243+
Args:
244+
filter_string: Filter for the snapshot query.
245+
246+
Returns:
247+
Dict[str, Any]: Dictionary mapping snapshot IDs (str)
248+
to their respective snapshot description.
249+
See:
250+
https://docs.cloud.google.com/compute/docs/reference/rest/v1/snapshots/list
251+
"""
252+
snapshots = {}
253+
gce_snapshot_client = self.GceApi().snapshots() # pylint: disable=no-member
254+
responses = common.ExecuteRequest(
255+
gce_snapshot_client,
256+
'list',
257+
{'project': self.project_id, 'filter': filter_string},
258+
)
259+
260+
for response in responses:
261+
for snapshot in response.get('items', []):
262+
name = snapshot['name']
263+
snapshots[name] = snapshot
264+
265+
return snapshots
266+
240267
def ListMIGSByInstanceName(self, location: str) -> Dict[str, str]:
241268
"""Gets a mapping from instance names to their managed instance group.
242269

0 commit comments

Comments
 (0)