为 network-ip-availabilites 响应添加更多信息

https://bugs.launchpad.net/neutron/+bug/2107316

此 RFE 旨在提供关于从 GET /v2.0/network-ip-availabilites 响应中子网中 IP 数量的详细信息 - 子网 cidr 中的可用 IP 数量和分配池中的可用 IP 数量,以及子网 cidr 和分配池中已用 IP 数量。

问题描述

现在 network-ip-availabilites api 的响应包含:(1) total_ips (2) used_ips

(1) total_ips - 子网 cidr,如果没有子网中的分配池 - 每个分配池中 IP 的总和,如果有子网中的分配池

(2) used_ips - 子网中已用 IP 的数量(不考虑分配池)

我们无法从响应中知道分配池中有多少可用 IP。 有一些用例需要我们知道分配池中可用 IP 的数量,例如在网络中创建虚拟机之前检查 IP 可用性。

使用 IPv4 子网时,total_ips 并不显示可用 IP 的确切数量。 total_ips 包含 .0 和 .255,这些 IP 不能用作端口的 IP。

提议的变更

为了解决上述问题,建议添加一个新的 API 扩展 network-ip-availability-details 来扩展 Neutron 中的 network-ip-availability 资源,并添加 ip_availability_details 属性。

服务器端变更

将添加一个新的 API 扩展 network-ip-availability-details。 该扩展添加了一个新的属性 ip_availability_details

该属性包括:(1) total_ips_in_subnet:子网 cidr 中的可用 IP 数量(不包括 IPv4 子网中的 .0、.255)(2) total_ips_in_allocation_pool:每个分配池中 IP 的总和,如果没有分配池则为 0 (3) used_ips_in_subnet:子网中已用 IP 的总和(不考虑分配池)(4) used_ips_in_allocation_pool:每个分配池中已用 IP 的总和,如果没有分配池则为 0

GET /v2.0/network-ip-availabilities/{network_id} 的响应

{
    "network_ip_availability": {
        "subnet_ip_availability": [
            {
                "subnet_id": "44e70d00-80a2-4fb1-ab59-6190595ceb61",
                "subnet_name": "private-subnet",
                "ip_version": 4,
                "cidr": "10.0.0.0/24",
                "total_ips": 256,
                "used_ips": 2,
                "ip_availability_details": {
                  "total_ips_in_subnet": 254,
                  "total_ips_in_allocation_pool": 0,
                  "used_ips_in_subnet": 2,
                  "used_ips_in_allocation_pool": 0
                }
            },
            {
                "subnet_id": "a90623df-00e1-4902-a675-40674385d74c",
                "subnet_name": "ipv6-private-subnet",
                "ip_version": 6,
                "cidr": "fdbf:ac66:9be8::/64",
                "total_ips": 18446744073709551600,
                "used_ips": 2,
                "ip_availability_details": {
                  "total_ips_in_subnet": 18446744073709551616,
                  "total_ips_in_allocation_pool": 18446744073709551600,
                  "used_ips_in_subnet": 2,
                  "used_ips_in_allocation_pool": 1
                }
            }
        ],
        "network_id": "6801d9c8-20e6-4b27-945d-62499f00002e",
        "project_id": "d56d3b8dd6894a508cf41b96b522328c",
        "tenant_id": "d56d3b8dd6894a508cf41b96b522328c",
        "network_name": "private",
        "total_ips": 18446744073709551856,
        "used_ips": 4,
        "ip_availability_details": {
          "total_ips_in_subnet": 18446744073709551870,
          "total_ips_in_allocation_pool": 18446744073709551600,
          "used_ips_in_subnet": 4,
          "used_ips_in_allocation_pool": 1
        }
    }
}

GET /v2.0/network-ip-availabilities 的响应

{
    "network_ip_availabilities": [
        {
            "network_id": "4cf895c9-c3d1-489e-b02e-59b5c8976809",
            "network_name": "public",
            "subnet_ip_availability": [
                {
                    "subnet_id": "44e70d00-80a2-4fb1-ab59-6190595ceb61",
                    "subnet_name": "private-subnet",
                    "ip_version": 4,
                    "cidr": "10.0.0.0/24",
                    "total_ips": 256,
                    "used_ips": 2,
                    "ip_availability_details": {
                      "total_ips_in_subnet": 254,
                      "total_ips_in_allocation_pool": 0,
                      "used_ips_in_subnet": 2,
                      "used_ips_in_allocation_pool": 0
                    }
                },
                {
                    "subnet_id": "a90623df-00e1-4902-a675-40674385d74c",
                    "subnet_name": "ipv6-private-subnet",
                    "ip_version": 6,
                    "cidr": "fdbf:ac66:9be8::/64",
                    "total_ips": 18446744073709551600,
                    "used_ips": 2,
                    "ip_availability_details": {
                      "total_ips_in_subnet": 18446744073709551616,
                      "total_ips_in_allocation_pool": 18446744073709551600,
                      "used_ips_in_subnet": 2,
                      "used_ips_in_allocation_pool": 1
                    }
                }
            ],
            "project_id": "1a02cc95f1734fcc9d3c753818f03002",
            "tenant_id": "1a02cc95f1734fcc9d3c753818f03002",
            "total_ips": 18446744073709551856,
            "used_ips": 4,
            "ip_availability_details": {
              "total_ips_in_subnet": 18446744073709551870,
              "total_ips_in_allocation_pool": 18446744073709551600,
              "used_ips_in_subnet": 4,
              "used_ips_in_allocation_pool": 1
            }
        },
        {
            "network_id": "6801d9c8-20e6-4b27-945d-62499f00002e",
            "network_name": "private",
            "subnet_ip_availability": [
                {
                    "cidr": "10.0.0.0/24",
                    "ip_version": 4,
                    "subnet_id": "44e70d00-80a2-4fb1-ab59-6190595ceb61",
                    "subnet_name": "private-subnet",
                    "total_ips": 256,
                    "used_ips": 2,
                    "ip_availability_details": {
                      "total_ips_in_subnet": 254,
                      "total_ips_in_allocation_pool": 0,
                      "used_ips_in_subnet": 2,
                      "used_ips_in_allocation_pool": 0
                    }
                },
                {
                    "ip_version": 6,
                    "cidr": "fdbf:ac66:9be8::/64",
                    "subnet_id": "a90623df-00e1-4902-a675-40674385d74c",
                    "subnet_name": "ipv6-private-subnet",
                    "total_ips": 18446744073709551600,
                    "used_ips": 2,
                    "ip_availability_details": {
                      "total_ips_in_subnet": 18446744073709551614,
                      "total_ips_in_allocation_pool": 18446744073709551600,
                      "used_ips_in_subnet": 2,
                      "used_ips_in_allocation_pool": 2
                    }
                }
            ],
            "project_id": "d56d3b8dd6894a508cf41b96b522328c",
            "total_ips": 18446744073709551856,
            "used_ips": 4,
            "ip_availability_details": {
              "total_ips_in_subnet": 18446744073709551868,
              "total_ips_in_allocation_pool": 18446744073709551600,
              "used_ips_in_subnet": 4,
              "used_ips_in_allocation_pool": 2
            }
        }
    ]
}

数据库影响

REST API 影响

新的 API 扩展:network-ip-availability-details 引入新的属性 ip_availability_details

客户端影响

openstackclient 和 openstacksdk 中的相关变更,以添加对新属性 ip_availability_details 的支持。

实现

添加新的 API 扩展 network-ip-availability-details。 此扩展通过字段 ip_availability_details 扩展网络 IP 可用性,该字段包含属性 - total_ips_in_subnet、total_ips_in_allocation_pool、used_ips_in_subnet 和 used_ips_in_allocation_pool。

将添加一个新的类 IpAvailabilityDetailsMixin 用于该扩展。 该类计算四个属性的值,并扩展网络 IP 可用性。

负责人

测试

  • 将添加新的测试类和方法来测试 network-ip-availability-details 扩展。

  • neutron-tempest-plugin 中的 Tempest 测试。

参考资料