弹性云服务器 ECS-API版本选择建议:微版本请求样例

时间:2024-11-14 16:41:59

微版本请求样例

假设使用弹性云服务器详情信息列表API接口查询"OS-EXT-SRV-ATTR:hostname"字段。

  • 使用v2接口,不加微版本号
    • GET: https://{Endpoint}/v2/74610f3a5ad941998e91f076297ecf27/servers/detail

      其中{Endpoint}为 IAM 的终端节点,请参考终端节点获取。

    • Headers:

      Content-Type

      application/json

      X-Auth-Token

      ${token}

    • 响应消息体:
      {
        "servers": [
          {
            "tenant_id": "74610f3a5ad941998e91f076297ecf27",
            "addresses": {
              "05d4fb93-84e5-4964-853b-32992ffef627": [
                {
                  "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:20:17:95",
                  "OS-EXT-IPS:type": "fixed",
                  "addr": "192.168.0.228",
                  "version": 4
                },
                {
                  "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:20:17:95",
                  "OS-EXT-IPS:type": "floating",
                  "addr": "192.168.51.61",
                  "version": 4
                }
              ]
            },
            "metadata": {},
            "OS-EXT-STS:task_state": null,
            "OS-DCF:diskConfig": "MANUAL",
            "OS-EXT-AZ:availability_zone":"az1-dc1",
            "links": [
              {
                "rel": "self",
                "href": "https://None/v2.1/74610f3a5ad941998e91f076297ecf27/servers/89c312bb-285a-4026-a237-d441908c2f9e"
              },
              {
                "rel": "bookmark",
                "href": "https://None/74610f3a5ad941998e91f076297ecf27/servers/89c312bb-285a-4026-a237-d441908c2f9e"
              }
            ],
            "OS-EXT-STS:power_state": 1,
            "id": "89c312bb-285a-4026-a237-d441908c2f9e",
            "os-extended-volumes:volumes_attached": [
              {
                "id": "c70c4b8e-33bd-4d1f-ab16-14a5a38cdeaf"
              }
            ],
            "OS-EXT-SRV-ATTR:host": "pod05.test.01",
            "image": {
              "links": [
                {
                  "rel": "bookmark",
                  "href": "https://None/74610f3a5ad941998e91f076297ecf27/images/1189efbf-d48b-46ad-a823-94b942e2a000"
                }
              ],
              "id": "1189efbf-d48b-46ad-a823-94b942e2a000"
            },
            "OS-SRV-USG:terminated_at": null,
            "accessIPv4": "",
            "accessIPv6": "",
            "created": "2018-05-11T03:21:56Z",
            "hostId": "fc7a8ff86bac050f0d9454b1b078dcc97060e819acbf06f04c3e338f",
            "OS-EXT-SRV-ATTR:hypervisor_hostname": "nova012@7",
            "key_name": "id_rsa",
            "flavor": {
              "links": [
                {
                  "rel": "bookmark",
                  "href": "https://None/74610f3a5ad941998e91f076297ecf27/flavors/s3.small.1"
                }
              ],
              "id": "s3.small.1"
            },
            "security_groups": [
              {
                "name": "default"
              }
            ],
            "config_drive": "",
            "OS-EXT-STS:vm_state": "active",
            "OS-EXT-SRV-ATTR:instance_name": "instance-0016c624",
            "user_id": "f79791beca3c48159ac2553fff22e166",
            "name": "zt-test",
            "progress": 0,
            "OS-SRV-USG:launched_at": "2018-05-11T03:22:16.701600",
            "updated": "2018-05-11T03:22:51Z",
            "status": "ACTIVE"
          }
        ]
      }
    • 结论:响应消息体中没有"OS-EXT-SRV-ATTR:hostname"字段。
  • 使用v2.1接口,加微版本号
    • GET: https://{Endpoint}/v2.1/74610f3a5ad941998e91f076297ecf27/servers/detail

      其中{Endpoint}为IAM的终端节点,请参考终端节点获取。

    • Headers:

      Content-Type

      application/json

      X-Auth-Token

      ${token}

      X-OpenStack-Nova-API-Version

      2.26

    • 响应消息体:
      {
        "servers": [
          {
            "tenant_id": "74610f3a5ad941998e91f076297ecf27",
            "addresses": {
              "05d4fb93-84e5-4964-853b-32992ffef627": [
                {
                  "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:20:17:95",
                  "OS-EXT-IPS:type": "fixed",
                  "addr": "192.168.0.228",
                  "version": 4
                },
                {
                  "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:20:17:95",
                  "OS-EXT-IPS:type": "floating",
                  "addr": "192.168.51.61",
                  "version": 4
                }
              ]
            },
            "metadata": {},
            "OS-EXT-STS:task_state": null,
            "description": "zt-test",
            "OS-EXT-SRV-ATTR:hostname": "zt-test",
            "OS-DCF:diskConfig": "MANUAL",
            "OS-EXT-AZ:availability_zone":"az-test-01",
            "links": [
              {
                "rel": "self",
                "href": "https://None/v2.1/74610f3a5ad941998e91f076297ecf27/servers/89c312bb-285a-4026-a237-d441908c2f9e"
              },
              {
                "rel": "bookmark",
                "href": "https://None/74610f3a5ad941998e91f076297ecf27/servers/89c312bb-285a-4026-a237-d441908c2f9e"
              }
            ],
            "OS-EXT-STS:power_state": 1,
            "id": "89c312bb-285a-4026-a237-d441908c2f9e",
            "os-extended-volumes:volumes_attached": [
              {
                "delete_on_termination": true,
                "id": "c70c4b8e-33bd-4d1f-ab16-14a5a38cdeaf"
              }
            ],
            "locked": false,
            "OS-EXT-SRV-ATTR:kernel_id": "",
            "OS-EXT-SRV-ATTR:host":"pod05.test.01" ,
            "OS-EXT-SRV-ATTR:ramdisk_id": "",
            "image": {
              "links": [
                {
                  "rel": "bookmark",
                  "href": "https://None/74610f3a5ad941998e91f076297ecf27/images/1189efbf-d48b-46ad-a823-94b942e2a000"
                }
              ],
              "id": "1189efbf-d48b-46ad-a823-94b942e2a000"
            },
            "accessIPv4": "",
            "OS-SRV-USG:terminated_at": null,
            "accessIPv6": "",
            "OS-EXT-SRV-ATTR:launch_index": 0,
            "created": "2018-05-11T03:21:56Z",
            "OS-EXT-SRV-ATTR:user_data": null,
            "hostId": "fc7a8ff86bac050f0d9454b1b078dcc97060e819acbf06f04c3e338f",
            "OS-EXT-SRV-ATTR:reservation_id": "r-pbqmaxer",
            "OS-EXT-SRV-ATTR:root_device_name": "/dev/vda",
            "host_status": "UP",
            "OS-EXT-SRV-ATTR:hypervisor_hostname": "nova012@7",
            "tags": [],
            "key_name": "id_rsa",
            "flavor": {
              "links": [
                {
                  "rel": "bookmark",
                  "href": "https://None/74610f3a5ad941998e91f076297ecf27/flavors/s3.small.1"
                }
              ],
              "id": "s3.small.1"
            },
            "security_groups": [
              {
                "name": "default"
              }
            ],
            "config_drive": "",
            "OS-EXT-STS:vm_state": "active",
            "OS-EXT-SRV-ATTR:instance_name": "instance-0016c624",
            "user_id": "f79791beca3c48159ac2553fff22e166",
            "name": "zt-test",
            "progress": 0,
            "OS-SRV-USG:launched_at": "2018-05-11T03:22:16.701600",
            "updated": "2018-05-11T03:22:51Z",
            "status": "ACTIVE"
          }
        ]
      }
    • 结论:响应消息体中有"OS-EXT-SRV-ATTR:hostname"字段。
support.huaweicloud.com/api-ecs/ecs_01_0006.html