华为云服务器查询弹性云服务器详情列表_云淘科技

场景描述

本章节指导用户通过云服务器详情列表接口,使用分页参数查询租户下所有云服务器。

本节示例操作包括分页查询,接口支持过滤和排序参数的操作,参数详情请参见“查询云服务器详情列表”。

涉及接口

本示例场景涉及如下接口调用:

指定limit查询云服务器详情列表
指定limit与marker查询云服务器详情列表

操作步骤

指定limit查询云服务器详情列表

接口相关信息

URI格式: GET /v2.1/{project_id}/servers/detail

详情请参见“查询云服务器详情列表”。

请求示例

GET https://{endpoint}/v2.1/743b4c0428d945316666666666666666/servers/detail?limit=100

{endpoint}信息请从地区和终端节点获取。

limit值可根据云服务器数据调整。

响应示例

{
    "servers": [
        ......
        {
            "tenant_id": "743b4c0428d945316666666666666666",
            "metadata": {
            },
            "addresses": {
                "140fd038-c4ae-4c32-ac07-34b525eb6b95": [
                    {
                        "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:e9:91:50",
                        "addr": "192.168.0.178",
                        "OS-EXT-IPS:type": "fixed",
                        "version": 4
                    }
                ]
            },
            "OS-EXT-STS:task_state": null,
            "OS-DCF:diskConfig": "MANUAL",
            "OS-EXT-AZ:availability_zone": "xxx",
            "links": [
                {
                    "rel": "self",
                    "href": "https://ecs.xxx/v2.1/743b4c0428d945316666666666666666/servers/f215afe8-b0c2-41cc-9191-585638166812"
                },
                {
                    "rel": "bookmark",
                    "href": "https://ecs.xxx/743b4c0428d945316666666666666666/servers/f215afe8-b0c2-41cc-9191-585638166812"
                }
            ],
            "OS-EXT-STS:power_state": 4,
            "id": "f215afe8-b0c2-41cc-9191-585638166812",
            "os-extended-volumes:volumes_attached": [
                {
                    "id": "546cf622-b9e5-4784-b659-6881e711f283"
                }
            ],
            "OS-EXT-SRV-ATTR:host": "pod01.xxx",
            "accessIPv4": "",
            "image": {
                "links": [
                    {
                        "rel": "bookmark",
                        "href": "https://ecs.xxx/743b4c0428d945316666666666666666/images/5c13381a-4a54-4ea5-a3b5-e7f7069f19a4"
                    }
                ],
                "id": "5c13381a-4a54-4ea5-a3b5-e7f7069f19a4"
            },
            "OS-SRV-USG:terminated_at": null,
            "accessIPv6": "",
            "created": "2019-08-09T02:35:04Z",
            "hostId": "31397656d6b318d01431f60c481d8425dc58eb421d237a385ceb80ee",
            "OS-EXT-SRV-ATTR:hypervisor_hostname": "nova022@36",
            "flavor": {
                "links": [
                    {
                        "rel": "bookmark",
                        "href": "https://ecs.xxx/743b4c0428d945316666666666666666/flavors/s3.large.4"
                    }
                ],
                "id": "s3.large.4"
            },
            "key_name": null,
            "security_groups": [
                {
                    "name": "sg-1e22"
                }
            ],
            "config_drive": "",
            "OS-EXT-STS:vm_state": "stopped",
            "user_id": "a8c20feabb5245e0bae4ef27618f932b",
            "OS-EXT-SRV-ATTR:instance_name": "instance-004bf55f",
            "name": "ecs-f090",
            "OS-SRV-USG:launched_at": "2019-08-09T02:35:23.000000",
            "updated": "2019-08-13T03:12:39Z",
            "status": "SHUTOFF"
        }
     ],
    "servers_links": [
        {
            "rel": "next",
            "href": "https://ecs.xxx/v2.1/743b4c0428d945316666666666666666/servers/detail?limit=100&marker=f215afe8-b0c2-41cc-9191-585638166812"
        }
    ]
}

指定limit与marker查询云服务器详情列表

接口相关信息

URI格式: GET /v2.1/{project_id}/servers/detail

接口与 步骤1 保持一致。

请求示例

GET https://{endpoint}/v2.1/743b4c0428d945316666666666666666/servers/detail?limit=100&marker=f215afe8-b0c2-41cc-9191-585638166812

接口返回了下一页的接口URI,参考返回body体中的 servers_links 中的href字段,如果不存在该字段,表示已经不存在下一页。

响应示例

{
    "servers": [
        .....
        {
            "tenant_id": "743b4c0428d945316666666666666666",
            "metadata": {
            },
            "addresses": {
                "140fd038-c4ae-4c32-ac07-34b525eb6b95": [
                    {
                        "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:a5:2b:f8",
                        "addr": "192.168.0.169",
                        "OS-EXT-IPS:type": "fixed",
                        "version": 4
                    }
                ]
            },
            "OS-EXT-STS:task_state": null,
            "OS-DCF:diskConfig": "MANUAL",
            "OS-EXT-AZ:availability_zone": "xxxc",
            "links": [
                {
                    "rel": "self",
                    "href": "https://xxx/v2.1/743b4c0428d945316666666666666666/servers/62348919-0188-43ec-aae6-82c1e96c49eb"
                },
                {
                    "rel": "bookmark",
                    "href": "https://ecs.xxx/743b4c0428d945316666666666666666/servers/62348919-0188-43ec-aae6-82c1e96c49eb"
                }
            ],
            "OS-EXT-STS:power_state": 4,
            "id": "62348919-0188-43ec-aae6-82c1e96c49eb",
            "os-extended-volumes:volumes_attached": [
                {
                    "id": "f0bb068a-61c1-4dc8-8455-09857773c3ff"
                }
            ],
            "OS-EXT-SRV-ATTR:host": "pod01.xxx",
            "accessIPv4": "",
            "image": {
                "links": [
                    {
                        "rel": "bookmark",
                        "href": "https://ecs.xxx/743b4c0428d945316666666666666666/images/3a64bd37-955e-40cd-ab9e-129db56bc05d"
                    }
                ],
                "id": "3a64bd37-955e-40cd-ab9e-129db56bc05d"
            },
            "OS-SRV-USG:terminated_at": null,
            "accessIPv6": "",
            "created": "2019-07-27T03:06:48Z",
            "hostId": "31397656d6b318d01431f60c481d8425dc58eb421d237a385ceb80ee",
            "OS-EXT-SRV-ATTR:hypervisor_hostname": "nova022@36",
            "flavor": {
                "links": [
                    {
                        "rel": "bookmark",
                        "href": "https://ecs.xxx/743b4c0428d945316666666666666666/flavors/s3.medium.4"
                    }
                ],
                "id": "s3.medium.4"
            },
            "key_name": null,
            "security_groups": [
                {
                    "name": "sg-1e22"
                }
            ],
            "config_drive": "",
            "OS-EXT-STS:vm_state": "stopped",
            "user_id": "f7e10ccf7abc4757b483895c3e06964a",
            "OS-EXT-SRV-ATTR:instance_name": "instance-004a0eea",
            "name": "test-dx",
            "OS-SRV-USG:launched_at": "2019-07-27T03:07:05.000000",
            "updated": "2019-08-13T03:12:38Z",
            "status": "SHUTOFF"
        }
    ],
    "servers_links": [
        {
            "rel": "next",
            "href": "https://ecs.xxx/v2.1/743b4c0428d945316666666666666666/servers/detail?limit=100&marker=62348919-0188-43ec-aae6-82c1e96c49eb"
        }
    ]
}

汇总查询结果。

参考1持续调用,如果查询的云服务器列表为空,或者返回的body体中不存在servers_links 字段,表明所有云服务器查询完成。

汇总所有查询到的云服务器即当前查询条件下的所有云服务器。

父主题: 应用示例

内容没看懂? 不太想学习?想快速解决? 有偿解决: 联系专家