Google Cloud Filestore
The `google-cloud-filestore` client library provides Python access to the Google Cloud Filestore API. Google Cloud Filestore offers fully managed NFS file servers that can be integrated with applications running on Compute Engine virtual machines (VMs) or Google Kubernetes Engine (GKE) clusters, providing high-performance, low-latency shared storage. The library is part of the actively developed `google-cloud-python` monorepo, receiving regular updates across its various client components.
Warnings
- breaking Python 3.8 and older versions are no longer supported. Ensure your environment uses Python 3.9 or newer.
- gotcha You must enable the Filestore API for your Google Cloud project before creating or managing instances. This is a common oversight leading to API permission errors.
- gotcha Authentication is crucial. Ensure Application Default Credentials (ADC) are correctly set up, either by running `gcloud auth application-default login` for local development or by configuring service account credentials in production environments.
- gotcha Filestore instances are zonal or regional. Deploying your Filestore instance in a different zone or region than your Compute Engine VMs or GKE cluster can lead to increased latency and cross-zone networking costs.
- gotcha The client library logs RPC events using Python's standard logging, and these logs might contain sensitive information. By default, these logs are not handled, so you must configure log handling explicitly.
Install
-
pip install google-cloud-filestore
Imports
- CloudFilestoreManagerClient
from google.cloud.filestore_v1 import CloudFilestoreManagerClient
- filestore_v1
from google.cloud import filestore_v1
Quickstart
import os
from google.cloud.filestore_v1 import CloudFilestoreManagerClient
project_id = os.environ.get('GOOGLE_CLOUD_PROJECT', 'your-project-id') # Replace with your GCP project ID
location = 'us-central1' # Replace with a suitable region, e.g., 'us-central1'
def list_filestore_instances():
"""Lists all Filestore instances in a given project and location."""
client = CloudFilestoreManagerClient()
parent = f"projects/{project_id}/locations/{location}"
print(f"Listing Filestore instances in {parent}:")
try:
# The list_instances method returns a PagedAsyncIterator, which can be iterated directly
for instance in client.list_instances(parent=parent):
print(f" Instance: {instance.name.split('/')[-1]} (State: {instance.state.name}, Tier: {instance.tier.name})")
print(f" IP Address: {instance.networks[0].ip_addresses[0] if instance.networks else 'N/A'}")
print(f" Capacity: {instance.capacity_gb} GB")
except Exception as e:
print(f"Error listing instances: {e}")
if __name__ == '__main__':
list_filestore_instances()