虚拟私有云 VPC-示例五:通过子网ID或IP地址查询端口:操作步骤

时间:2023-11-01 16:25:15

操作步骤

  1. 通过子网ID或IP地址过滤查询端口。
    1. 发送“GET https://VPC的Endpoint/v1/{project_id}/ports?fixed_ips=ip_address={ip_address}&fixed_ips=subnet_id={subnet_id}”,

      project_id为项目ID,ip_address为端口资源的IP地址,subnet_id为端口资源所在子网的ID(IPV4/IPV6子网ID,不是网络ID)。

      过滤信息格式举例 fixed_ips=ip_address=192.168.27.75,fixed_ips=subnet_id=f60f887b-60e1-4647-a762-b5c6925909cd

    2. 在Request Header中增加“X-Auth-Token”。
    3. 查看请求响应结果。
      • 请求成功时,响应参数如下,id就是port_id,可以看到端口的详细信息。
        {    "ports": [        {            "id": "6026a064-eacc-4c40-a0fd-9dcc456ad495",            "name": "",            "status": "DOWN",            "admin_state_up": true,            "fixed_ips": [                {                    "subnet_id": "f60f887b-60e1-4647-a762-b5c6925909cd",                    "ip_address": "192.168.27.75"                }            ],            "mac_address": "fa:16:3e:ab:1e:4e",            "network_id": "b033c3b8-59ea-4a15-9f86-648119cdc50a",            "tenant_id": "5f6387106c2048b589b369d96c2f23a2",            "device_id": "",            "device_owner": "neutron:VIP_PORT",            "security_groups": [],            "extra_dhcp_opts": [],            "allowed_address_pairs": [],            "binding:vnic_type": "normal",            "binding:vif_details": {},            "binding:profile": {},            "port_security_enabled": true,            "instance_type": "",            "instance_id": "",            "zone_id": "cn-north-4a"        }    ]}
      • 请求异常时,错误码请参见错误码
  1. 查询端口详情。
    1. 如果已知端口ID,可以通过下面的接口查询端口详情。
    2. 发送“GET https://VPC的Endpoint/v1/{project_id}/ports/{port_id}”,project_id为项目ID,port_id为端口ID。
    3. 在Request Header中增加“X-Auth-Token”。
    4. 查看请求响应结果。
      • 请求成功时,响应参数如下。
        {    "port": {        "id": "6026a064-eacc-4c40-a0fd-9dcc456ad495",        "name": "",        "status": "DOWN",        "admin_state_up": true,        "fixed_ips": [            {                "subnet_id": "f60f887b-60e1-4647-a762-b5c6925909cd",                "ip_address": "192.168.27.75"            }        ],        "mac_address": "fa:16:3e:ab:1e:4e",        "network_id": "b033c3b8-59ea-4a15-9f86-648119cdc50a",        "tenant_id": "5f6387106c2048b589b369d96c2f23a2",        "device_id": "",        "device_owner": "neutron:VIP_PORT",        "security_groups": [],        "extra_dhcp_opts": [],        "allowed_address_pairs": [],        "binding:vnic_type": "normal",        "binding:vif_details": {},        "binding:profile": {},        "port_security_enabled": true,        "instance_type": "",        "instance_id": "",        "zone_id": "cn-north-4a"    }}
      • 请求异常时,错误码请参见错误码
support.huaweicloud.com/api-vpc/zh-cn_topic_0000001564915322.html