Help Center> Elastic Load Balance> API Reference> Examples> Querying the ID of an ECS Used as a Backend Server

Querying the ID of an ECS Used as a Backend Server

Scenarios

Call APIs to obtain the ID of an ECS used as a backend server of a load balancer.

Prerequisites

You have created a load balancer, a backend server group, and a backend server.

Procedure

  1. Obtain the IP address and subnet ID of the backend server using its ID.
    1. Send GET https://{elb_endpoint}/v2/{project_id}/elb/pools/{pool_id}/members/{member_id}. project_id indicates the project ID, pool_id indicates the backend server group ID, and member_id indicates the backend server ID.
    2. Add X-Auth-Token to the request header.
    3. Check the response and obtain the IP address and subnet ID.
      • The request is successful if the following response is displayed:
        {
        "member": {
            "project_id": "060576782980d5762f9ec014dd2f1148",
            "address": "192.168.0.74",
            "protocol_port": 666,
            "subnet_id": "e9a4264c-9b81-4eed-9543-37edaa2a9dfc",
            "operating_status": "OFFLINE",
            "admin_state_up": false,
            "id": "da72609c-919f-4a35-8c50-b834b9026358",
            "weight": 1,
            "tenant_id": "060576782980d5762f9ec014dd2f1148",
            "name": ""
            }
        }
      • If the request is abnormal, locate the fault by referring to Error Codes.
  2. Query the VPC port based on the IP address and subnet ID of the backend server.
    1. Send GET https://{vpc_endpoint}/v1/{project_id}/ports?fixed_ips=ip_address={ip_address}. project_id indicates the project ID, and ip_address indicates the IP address obtained in step c.
      • The request is successful if the following response is displayed:
        {
            "ports": [
                {
                    "id": "d00f9c13-412f-4855-8af3-de5d8c24cd60",
                    "name": "test",
                    "status": "DOWN",
                    "admin_state_up": "true",
                    "fixed_ips": [
                        {
                            "subnet_id": "70f2e74b-e660-410a-b754-0ca46744348a",
                            "ip_address": "10.128.1.10"
                        }
                    ],
                    "dns_name": "",
                    "mac_address": "fa:16:3e:d7:f2:6c",
                    "network_id": "5b808927-13c9-4e60-a4f4-ed6ffe225167",
                    "tenant_id": "43f2d1cca56a40729dcb17212482f34d",
                    "device_id": "50f2e74b-e660-410a-b754-0ca43988348a",
                    "device_owner": "ELB",
                    "security_groups": [
                        "02b4e8ee-74fa-4a31-802e-5490df11245e"
                    ],
                    "extra_dhcp_opts": [],
                    "allowed_address_pairs": [],
                    "binding:vnic_type": "normal"
            ]
        }
    2. Traverse the obtained port list and check whether fixed_ips contained in each ports parameter contains subnet_id and the value of subnet_id is consistent with the subnet ID obtained in step c. If this requirement is met, the port is the one to be queried, and the value of device_id is the ID of the ECS used as the backend server.