1+ from urllib .parse import urlparse
2+
13import requests
24from ironic import objects
35from ironic .common import exception
46from ironic .dhcp import base
57from oslo_log import log as logging
6- from urllib .parse import urlparse
78
89from ironic_understack .conf import CONF
910
@@ -74,7 +75,7 @@ def get_statistics(self, name=None):
7475 return self ._make_request ("statistic-get" , {"name" : name })
7576 return self ._make_request ("statistic-get-all" , {})
7677
77- def _update_host_reservation (self , hw_address , boot_file_name = None , remove = False ):
78+ def _update_host_reservation (self , hw_address , kea_options = None , remove = False ):
7879 """Modify a host reservation in the Kea config file or hosts database."""
7980 # TODO(cid) add support/replace with the host database configuration
8081 # option in a central database managed by Ironic; the commands to have
@@ -84,23 +85,38 @@ def _update_host_reservation(self, hw_address, boot_file_name=None, remove=False
8485 config = self .get_config ()
8586 config ["arguments" ].pop ("hash" , None )
8687 dhcp4_config = config ["arguments" ]["Dhcp4" ]
87- next_server = urlparse (boot_file_name ).hostname
8888
8989 reservations = dhcp4_config .get ("reservations" , [])
9090 found = False
9191 for reservation in reservations :
9292 if reservation .get ("hw-address" ) == hw_address :
93- reservation ["boot-file-name" ] = boot_file_name
94- reservation ["next-server" ] = next_server
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
95103 found = True
96- break
97-
98104 if not found :
105+ boot_file_name = kea_options ["http" ]["boot_file_name" ]
106+ reservations .append (
107+ {
108+ "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+ )
99114 reservations .append (
100115 {
101116 "hw-address" : hw_address ,
102- "boot-file-name" : boot_file_name ,
103- "next-server" : next_server ,
117+ "boot-file-name" : kea_options ["pxe" ]["boot_file_name" ],
118+ "next-server" : urlparse (boot_file_name ).hostname ,
119+ "client-classes" : ["pxeclient" ],
104120 }
105121 )
106122 dhcp4_config ["reservations" ] = reservations
@@ -116,13 +132,20 @@ def update_port_dhcp_opts(self, port_id, dhcp_options, context=None):
116132 """Update DHCP options for a specific port in Kea."""
117133 port = objects .Port .get (context , port_id )
118134
119- boot_file_name = ""
135+ kea_options = {}
120136 print (f"DHCP_OPTIONS: { dhcp_options } " )
121137 for opt in dhcp_options :
122- if opt ["opt_name" ].startswith ("!" ):
123- boot_file_name = opt ["opt_value" ]
124- break
125- return self ._update_host_reservation (port .address , boot_file_name )
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 )
126149
127150 def update_dhcp_opts (self , task , options , vifs = None ):
128151 """Update DHCP options for all ports associated with a node."""
0 commit comments