将 drest 输出结果添加到 API 标签页

本指南通过一个示例介绍了如何将 drest 输出结果添加到 API 标签页。

创建客户端虚拟机

此示例在后端(服务器)虚拟机所在的同一地区创建一个客户端虚拟机 (vm-client)。该客户端用于验证负载平衡器的配置,并演示测试部分中所述的预期行为。

控制台

  1. 转到 Google Cloud Console 中的“虚拟机实例”页面。
    转到“虚拟机实例”页面
  2. 点击创建实例
  3. 名称设置为 vm-client
  4. 区域设置为 us-west1-a
  5. 点击管理、安全、磁盘、网络、单独租用并进行以下更改:
    • 点击网络并将 allow-ssh 添加到网络标记
    • 点击网络接口下的修改按钮并进行以下更改,然后点击完成
      • 网络lb-network
      • 子网lb-subnet
      • 主要内部 IP:临时(自动)
      • 外部 IP:临时
  6. 点击创建

gcloud

客户端虚拟机可以位于负载平衡器所在的同一地区的任何区域中,并且可以使用该地区中的任何子网。在此示例中,客户端位于 us-west1-a 区域,并使用与后端虚拟机相同的子网。

gcloud compute instances create vm-client \
    --zone=us-west1-a \
    --image-family=debian-9 \
    --image-project=debian-cloud \
    --tags=allow-ssh \
    --subnet=lb-subnet

API

instances.insert 方法发出 POST 请求。

在使用下面的请求数据之前,请先进行以下替换:

  • PROJECT_ID:您的项目 ID
  • ZONE:us-west1-a
  • NETWORK:lb-network
  • SUBNET:lb-subnet

HTTP 方法和网址:

POST https://www.googleapis.com/compute/v1/projects/`PROJECT_ID`/zones/`ZONE`/instances

请求 JSON 正文:

{
  "kind": "compute#instance",
  "name": "`VM_NAME`",
  "zone": "projects/`PROJECT_ID`/zones/`ZONE`",
  "machineType": "projects/`PROJECT_ID`/zones/`ZONE`/machineTypes/n1-standard-1",
  "displayDevice": {
    "enableDisplay": false
  },
  "metadata": {
    "kind": "compute#metadata",
    "items": []
  },
  "tags": {
    "items": []
  },
  "disks": [
    {
      "kind": "compute#attachedDisk",
      "type": "PERSISTENT",
      "boot": true,
      "mode": "READ_WRITE",
      "autoDelete": true,
      "deviceName": "`VM_NAME`",
      "initializeParams": {
        "sourceImage": "projects/eip-images/global/images/debian-9-drawfork-v20190702",
        "diskType": "projects/`PROJECT_ID`/zones/`ZONE`/diskTypes/pd-standard",
        "diskSizeGb": "10"
      },
      "diskEncryptionKey": {}
    }
  ],
  "canIpForward": false,
  "networkInterfaces": [
    {
      "kind": "compute#networkInterface",
      "subnetwork": "projects/`PROJECT_ID`/regions/us-central1/subnetworks/`SUBNET`",
      "accessConfigs": [
        {
          "kind": "compute#accessConfig",
          "name": "External NAT",
          "type": "ONE_TO_ONE_NAT",
          "networkTier": "PREMIUM"
        }
      ],
      "aliasIpRanges": []
    }
  ],
  "description": "",
  "labels": {},
  "scheduling": {
    "preemptible": false,
    "onHostMaintenance": "MIGRATE",
    "automaticRestart": true,
    "nodeAffinities": []
  },
  "deletionProtection": false,
  "reservationAffinity": {
    "consumeReservationType": "ANY_RESERVATION"
  },
  "serviceAccounts": [
    {
      "email": "893700239234-compute@developer.gserviceaccount.com",
      "scopes": [
        "https://www.googleapis.com/auth/devstorage.read_only",
        "https://www.googleapis.com/auth/logging.write",
        "https://www.googleapis.com/auth/monitoring.write",
        "https://www.googleapis.com/auth/servicecontrol",
        "https://www.googleapis.com/auth/service.management.readonly",
        "https://www.googleapis.com/auth/trace.append"
      ]
    }
  ]
}

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应:

{
 "id": "8061072881391620712",
 "name": "operation-1565289606387-58f9f62f5989c-e582f586-6d22f38d",
 "zone": "https://www.googleapis.com/compute/v1/projects/`PROJECT_ID`/zones/`ZONE`",
 "operationType": "insert",
 "targetLink": "https://www.googleapis.com/compute/v1/projects/`PROJECT_ID`/zones/`ZONE`/instances/`VM_NAME`",
 "targetId": "2977231178150564457",
 "status": "RUNNING",
 "user": "betsyl@google.com",
 "progress": 0,
 "insertTime": "2019-08-08T11:40:07.728-07:00",
 "startTime": "2019-08-08T11:40:07.731-07:00",
 "selfLink": "https://www.googleapis.com/compute/v1/projects/`PROJECT_ID`/zones/`ZONE`/operations/operation-1565289606387-58f9f62f5989c-e582f586-6d22f38d",
 "kind": "compute#operation"
}

后续步骤

  • 开始使用 drest! :)