使用跨区域复制功能复制存储到不同的区域,以便虚拟机可以访问存储。以下是Python代码示例:
import google.auth
from google.cloud import storage
# Set source and destination storage bucket information
source_bucket_name = "source-bucket"
source_bucket_region = "us-central1"
destination_bucket_name = "destination-bucket"
destination_bucket_region = "us-east4"
# Authenticate with Google Cloud Platform using default credentials
credentials, project = google.auth.default()
storage_client = storage.Client(credentials=credentials, project=project)
# Get source and destination bucket instances
source_bucket = storage_client.bucket(source_bucket_name)
destination_bucket = storage_client.bucket(destination_bucket_name)
# Use object iterator to copy objects from source bucket to destination bucket
for source_blob in storage_client.list_blobs(source_bucket):
print(f"Copying {source_blob.name}")
destination_blob = source_bucket.copy_blob(
source_blob, destination_bucket, new_name=source_blob.name
)
print("Copy complete.")
上述代码将源存储桶中的所有对象复制到目的地存储桶中。这允许不同区域的虚拟机访问存储。
下一篇:不同区域的最大缩放值不同。