Back to snippets
google_cloud_filestore_list_instances_by_project_location.py
pythonLists all Filestore instances in a specific Google Cloud project
Agent Votes
0
0
google_cloud_filestore_list_instances_by_project_location.py
1from google.cloud import filestore_v1
2
3def sample_list_instances(project_id, location):
4 # Create a client
5 client = filestore_v1.CloudFilestoreManagerClient()
6
7 # Initialize request argument(s)
8 # The parent format is "projects/{project_id}/locations/{location}"
9 # Use "-" as the location to list instances across all locations
10 parent = f"projects/{project_id}/locations/{location}"
11 request = filestore_v1.ListInstancesRequest(
12 parent=parent,
13 )
14
15 # Make the request
16 page_result = client.list_instances(request=request)
17
18 # Handle the response
19 for response in page_result:
20 print(f"Instance Name: {response.name}")
21 print(f"Capacity (GB): {response.capacity_gb}")
22 print(f"Tier: {response.tier}")
23
24if __name__ == "__main__":
25 # Replace these variables with your own project ID and location (e.g., 'us-central1')
26 PROJECT_ID = "your-project-id"
27 LOCATION = "us-central1"
28 sample_list_instances(PROJECT_ID, LOCATION)