Skip to content

Commit

Permalink
Support ippool custom range
Browse files Browse the repository at this point in the history
  • Loading branch information
albinsun committed Jun 19, 2024
1 parent e88447c commit 9a245f6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
10 changes: 6 additions & 4 deletions apiclient/harvester_api/managers/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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,
Expand All @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion harvester_e2e_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
)
Expand Down

0 comments on commit 9a245f6

Please sign in to comment.