快速入门:启用 Cloud Location Finder 并运行查询
本页面介绍了如何使用 Google Cloud CLI 启用 Cloud Location Finder,以及如何根据邻近性、管辖区和碳足迹查找云位置。您可以使用 HTTP 请求或 Google Cloud CLI 命令查找位置。
准备工作
- 安装 Google Cloud CLI。
- 如需初始化 Google Cloud CLI,请运行以下命令:
gcloud init
- 启用 Cloud Location Finder API:
gcloud services enable cloudlocationfinder.googleapis.com --project PROJECT
- 添加
cloudlocationfinder.viewer角色:gcloud projects add-iam-policy-binding PROJECT \ --member USER_IDENTIFIER \ --role roles/cloudlocationfinder.viewer- 将 PROJECT 替换为您的项目 ID。
- 将 USER_IDENTIFIER 替换为您的用户账号的标识符。例如,user:myemail@example.com。
探索常见的 Cloud Location Finder 查询
借助 Cloud Location Finder,您可以查询云位置信息库,根据邻近度、地区代码或 Google 无碳能源 (CFE%) 消耗量来确定附近的云位置。以下部分提供了一些常见示例,说明如何与 Cloud Location Finder 代码库进行交互。
Cloud Location Finder 使用 gRPC 转码语法。
- 将 PROJECT 替换为您的项目 ID。
- 将 CLOUD_REGION 替换为源云区域,以查找距离最近的位置,包括云提供商前缀。例如
gcp-us-central1或aws-us-east-1。 - 将 CLOUD_PROVIDER 替换为云提供商,以查找最近的位置。例如
AWS或GCP。
查找最近的云区域
使用此查询可根据您指定的云提供商的邻近性数据,确定距离云位置最近的 Google Cloud 可用区。
HTTP
curl -H "Authorization: Bearer $(gcloud auth print-access-token)" "https://cloudlocationfinder.googleapis.com/v1alpha/projects/PROJECT/locations/global/cloudLocations:search?source_cloud_location=projects/PROJECT/locations/global/cloudLocations/CLOUD_REGION&query=cloud_provider=CLOUD_PROVIDER_CLOUD_PROVIDER%20AND%20cloud_location_type=CLOUD_LOCATION_TYPE_ZONE&page_size=1"
gcloud
gcloud alpha cloudlocationfinder cloud-locations search \
--source-cloud-location=CLOUD_REGION \
--query="cloud_provider=CLOUD_PROVIDER_CLOUD_PROVIDER AND cloud_location_type=CLOUD_LOCATION_TYPE_ZONE" \
--limit=1
查找区域中的所有 Google Distributed Cloud Connected 可用区
使用此查询可列出特定区域内的 Distributed Cloud connected 可用区。
HTTP
curl -H "Authorization: Bearer $(gcloud auth print-access-token)" 'https://cloudlocationfinder.googleapis.com/v1alpha/projects/PROJECT/locations/global/cloudLocations?filter=containing_cloud_location="projects/PROJECT/locations/global/cloudLocations/CLOUD_REGION%20AND%20cloud_provider=CLOUD_PROVIDER_GCP%20AND%20cloud_location_type=CLOUD_LOCATION_TYPE_GDCC_ZONE"'
gcloud
gcloud cloudlocationfinder cloud-locations list --filter='cloud_provider=CLOUD_PROVIDER_GCP AND cloud_location_type=CLOUD_LOCATION_TYPE_GDCC_ZONE AND containing_cloud_location="projects/PROJECT/locations/global/cloudLocations/CLOUD_REGION"'
查找特定地区的区域
使用此查询可根据您提供的地区代码,确定特定地区或管辖区内的区域。
HTTP
curl -H "Authorization: Bearer $(gcloud auth print-access-token)" "https://cloudlocationfinder.googleapis.com/v1alpha/projects/PROJECT/locations/global/cloudLocations:search?source_cloud_location=projects/PROJECT/locations/global/cloudLocations/CLOUD_REGION&query=cloud_provider=CLOUD_PROVIDER_CLOUD_PROVIDER%20AND%20cloud_location_type=CLOUD_LOCATION_TYPE_REGION%20AND%20territory_code=TERRITORY_CODE&page_size=1"
gcloud
gcloud alpha cloudlocationfinder cloud-locations list \
--source-cloud-location=CLOUD_REGION \
--filter="cloud_provider=CLOUD_PROVIDER_CLOUD_PROVIDER AND cloud_location_type=CLOUD_LOCATION_TYPE_REGION" AND filter="territory_code=\"TERRITORY_CODE\"" \
--limit=1
列出可最大限度减少碳足迹的云位置
使用此查询可根据各区域的无碳能源数据 Google Cloud 确定碳足迹最低的区域。
HTTP
curl -H "Authorization: Bearer $(gcloud auth print-access-token)" "https://cloudlocationfinder.googleapis.com/v1alpha/projects/PROJECT/locations/global/cloudLocations?query=cloud_provider=CLOUD_PROVIDER_CLOUD_PROVIDER%20AND%20cloud_location_type=CLOUD_LOCATION_TYPE_REGION&page_size=5"
gcloud
gcloud alpha cloudlocationfinder cloud-locations list \
--filter="cloud_provider=CLOUD_PROVIDER_CLOUD_PROVIDER AND cloud_location_type=CLOUD_LOCATION_TYPE_REGION" \
--limit=5