Skip to content

Commit 13556f1

Browse files
committed
adjust kea reservations
1 parent 2aeac6e commit 13556f1

1 file changed

Lines changed: 15 additions & 38 deletions

File tree

  • python/ironic-understack/ironic_understack/dhcp

python/ironic-understack/ironic_understack/dhcp/kea.py

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def get_statistics(self, name=None):
7575
return self._make_request("statistic-get", {"name": name})
7676
return self._make_request("statistic-get-all", {})
7777

78-
def _update_host_reservation(self, hw_address, kea_options=None, remove=False):
78+
def _update_host_reservation(self, hw_address, boot_file_prefix=None, remove=False):
7979
"""Modify a host reservation in the Kea config file or hosts database."""
8080
# TODO(cid) add support/replace with the host database configuration
8181
# option in a central database managed by Ironic; the commands to have
@@ -84,44 +84,30 @@ def _update_host_reservation(self, hw_address, kea_options=None, remove=False):
8484
try:
8585
config = self.get_config()
8686
config["arguments"].pop("hash", None)
87-
dhcp4_config = config["arguments"]["Dhcp4"]
87+
dhcp4_config = config["arguments"]["Dhcp4"]["subnet4"][0]
8888

8989
reservations = dhcp4_config.get("reservations", [])
9090
found = False
9191
for reservation in reservations:
9292
if reservation.get("hw-address") == hw_address:
93-
if "httpclient" in reservation.get("client-classes", []):
94-
boot_file_name = kea_options["http"]["boot_file_name"]
95-
reservation["boot-file-name"] = boot_file_name
96-
next_server = urlparse(boot_file_name).hostname
97-
reservation["next-server"] = next_server
98-
elif "pxeclient" in reservation.get("client-classes", []):
99-
boot_file_name = kea_options["pxe"]["boot_file_name"]
100-
reservation["boot-file-name"] = boot_file_name
101-
next_server = urlparse(boot_file_name).hostname
102-
reservation["next-server"] = next_server
93+
reservation["option-data"] = [
94+
{"name": "boot-file-base", "data": boot_file_prefix}
95+
]
10396
found = True
97+
break
10498
if not found:
105-
boot_file_name = kea_options["http"]["boot_file_name"]
10699
reservations.append(
107100
{
108101
"hw-address": hw_address,
109-
"boot-file-name": kea_options["http"]["boot_file_name"],
110-
"next-server": urlparse(boot_file_name).hostname,
111-
"client-classes": ["httpclient"],
112-
}
113-
)
114-
reservations.append(
115-
{
116-
"hw-address": hw_address,
117-
"boot-file-name": kea_options["pxe"]["boot_file_name"],
118-
"next-server": urlparse(boot_file_name).hostname,
119-
"client-classes": ["pxeclient"],
102+
"option-data": [
103+
{"name": "boot-file-base", "data": boot_file_prefix},
104+
],
120105
}
121106
)
122107
dhcp4_config["reservations"] = reservations
123108

124-
config["arguments"]["Dhcp4"] = dhcp4_config
109+
print(dhcp4_config)
110+
config["arguments"]["Dhcp4"]["subnet4"][0] = dhcp4_config
125111
self.set_config(config["arguments"])
126112
return True
127113
except Exception as e:
@@ -132,20 +118,11 @@ def update_port_dhcp_opts(self, port_id, dhcp_options, context=None):
132118
"""Update DHCP options for a specific port in Kea."""
133119
port = objects.Port.get(context, port_id)
134120

135-
kea_options = {}
136-
print(f"DHCP_OPTIONS: {dhcp_options}")
137121
for opt in dhcp_options:
138-
if opt["opt_name"] == "!175,67":
139-
kea_options["http"] = {
140-
"boot_file_name": opt["opt_value"],
141-
"client_class": "httpclient",
142-
}
143-
elif opt["opt_name"] == "67":
144-
kea_options["pxe"] = {
145-
"boot_file_name": opt["opt_value"],
146-
"client_class": "pxeclient",
147-
}
148-
return self._update_host_reservation(port.address, kea_options)
122+
if opt["opt_name"] == "67":
123+
parsed_url = urlparse(opt["opt_value"])
124+
boot_file_prefix = f"{parsed_url.scheme}://{parsed_url.netloc}/"
125+
return self._update_host_reservation(port.address, boot_file_prefix)
149126

150127
def update_dhcp_opts(self, task, options, vifs=None):
151128
"""Update DHCP options for all ports associated with a node."""

0 commit comments

Comments
 (0)