From 9a245f6041f91ada5424b43c66226247882fab6c Mon Sep 17 00:00:00 2001 From: Albin Sun Date: Wed, 19 Jun 2024 16:51:00 +0800 Subject: [PATCH] Support ippool custom range --- apiclient/harvester_api/managers/networks.py | 10 ++++++---- config.yml | 2 ++ harvester_e2e_tests/conftest.py | 14 +++++++++++++- .../integrations/test_9_rancher_integration.py | 6 +++++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/apiclient/harvester_api/managers/networks.py b/apiclient/harvester_api/managers/networks.py index 0b2f5873d..2cafad049 100644 --- a/apiclient/harvester_api/managers/networks.py +++ b/apiclient/harvester_api/managers/networks.py @@ -72,7 +72,7 @@ class IPPoolManager(BaseManager): PATH_fmt = "{API_VERSION}/harvester/loadbalancer.harvesterhci.io.ippools{name}" API_VERSION = "v1" - def create_data(self, name, ip_pool_subnet, network_id): + def create_data(self, name, ip_pool_subnet, ip_pool_start, ip_pool_end, network_id): return { "type": "loadbalancer.harvesterhci.io.ippool", "metadata": { @@ -81,8 +81,10 @@ def create_data(self, name, ip_pool_subnet, network_id): "spec": { "ranges": [{ "subnet": ip_pool_subnet, + "rangeStart": ip_pool_start, + "rangeEnd": ip_pool_end, "gateway": "", - "type": "cidr" + "type": "range" if ip_pool_start or ip_pool_end else "cidr" }], "selector": { "network": network_id, @@ -95,8 +97,8 @@ def create_data(self, name, ip_pool_subnet, network_id): } } - def create(self, name, ip_pool_subnet, network_id, *, raw=False): - data = self.create_data(name, ip_pool_subnet, network_id) + def create(self, name, ip_pool_subnet, ip_pool_start, ip_pool_end, network_id, *, raw=False): + data = self.create_data(name, ip_pool_subnet, ip_pool_start, ip_pool_end, network_id) path = self.PATH_fmt.format(name="", API_VERSION=self.API_VERSION) return self._create(path, json=data, raw=raw) diff --git a/config.yml b/config.yml index 935c0d40b..a85f0cf49 100644 --- a/config.yml +++ b/config.yml @@ -11,6 +11,8 @@ vlan-id: 1 # Physical NIC for VLAN. Default is "harvester-mgmt" vlan-nic: 'harvester-mgmt' ip-pool-subnet: '192.168.0.0/24' +ip-pool-start: '' +ip-pool-end: '' # Wait time for polling operations wait-timeout: 600 diff --git a/harvester_e2e_tests/conftest.py b/harvester_e2e_tests/conftest.py index 3f4bec056..76dba4bef 100644 --- a/harvester_e2e_tests/conftest.py +++ b/harvester_e2e_tests/conftest.py @@ -100,7 +100,19 @@ def pytest_addoption(parser): '--ip-pool-subnet', action='store', default=config_data['ip-pool-subnet'], - help='IP pool range for load balancer' + help='Subnet of IP pool for load balancer' + ) + parser.addoption( + '--ip-pool-start', + action='store', + default=config_data['ip-pool-start'], + help='Start IP of IP pool for load balancer' + ) + parser.addoption( + '--ip-pool-end', + action='store', + default=config_data['ip-pool-end'], + help='End IP of IP pool for load balancer' ) parser.addoption( '--wait-timeout', diff --git a/harvester_e2e_tests/integrations/test_9_rancher_integration.py b/harvester_e2e_tests/integrations/test_9_rancher_integration.py index cf5304a15..14e451404 100644 --- a/harvester_e2e_tests/integrations/test_9_rancher_integration.py +++ b/harvester_e2e_tests/integrations/test_9_rancher_integration.py @@ -57,8 +57,12 @@ def vlan_network(request, api_client): def ip_pool(request, api_client, unique_name, vlan_network): name = f"ippool-{unique_name}" ip_pool_subnet = request.config.getoption('--ip-pool-subnet') + ip_pool_start = request.config.getoption('--ip-pool-start') + ip_pool_end = request.config.getoption('--ip-pool-end') - code, data = api_client.ippools.create(name, ip_pool_subnet, vlan_network["id"]) + code, data = api_client.ippools.create( + name, ip_pool_subnet, ip_pool_start, ip_pool_end, vlan_network["id"] + ) assert 201 == code, ( f"Failed to create ip pool {name} with error: {code}, {data}" )