@@ -190,17 +190,14 @@ def _check_if_client_should_be_skipped(self):
190190 logger .warning ("Tried to deploy to existing opsi server %s. Skipping!" , self .host )
191191 raise SkipClientException (f"Not deploying to server { self .host } ." )
192192
193- def _get_ip_address (self , host_id , host_name ):
194- if self .deployment_method == 'ip' :
195- return forceIPAddress (self .host )
196-
197- logger .notice ("Querying for ip address of host %s" , host_id )
193+ def _get_ip_address (self , host_name ):
194+ logger .notice ("Querying for ip address of host %s" , self .host )
198195 ip_address = ''
199- logger .info ("Getting host %s by name" , host_id )
196+ logger .info ("Getting host %s by name" , self . host )
200197 try :
201- ip_address = socket .gethostbyname (host_id )
198+ ip_address = socket .gethostbyname (self . host )
202199 except Exception as err : # pylint: disable=broad-except
203- logger .warning ("Failed to get ip address for host %s by syscall: %s" , host_id , err )
200+ logger .warning ("Failed to get ip address for host %s by syscall: %s" , self . host , err )
204201
205202 if ip_address :
206203 logger .notice ("Got ip address %s from syscall" , ip_address )
@@ -234,15 +231,15 @@ def _ping_client(self, ip_address):
234231 else :
235232 logger .warning ("No ping response received from %s" , ip_address )
236233
237- def _create_host_if_not_existing (self , host_id , ip_address ):
238- if not self .backend .host_getIdents (type = 'OpsiClient' , id = host_id ):
239- logger .notice ("Getting hardware ethernet address of host %s" , host_id )
234+ def _create_host_if_not_existing (self , ip_address ):
235+ if not self .backend .host_getIdents (type = 'OpsiClient' , id = self . host ):
236+ logger .notice ("Getting hardware ethernet address of host %s" , self . host )
240237 mac = self ._get_mac_address (ip_address )
241238 if not mac :
242239 logger .warning ("Failed to get hardware ethernet address for IP %s" , ip_address )
243240
244241 client_config = {
245- "id" : host_id ,
242+ "id" : self . host ,
246243 "hardwareAddress" : mac ,
247244 "ipAddress" : ip_address ,
248245 "description" : "" ,
@@ -252,41 +249,41 @@ def _create_host_if_not_existing(self, host_id, ip_address):
252249 client_config .update (self .additional_client_settings )
253250 logger .debug ("Updated config now is: %s" , client_config )
254251
255- logger .notice ("Creating client %s" , host_id )
252+ logger .notice ("Creating client %s" , self . host )
256253 self .backend .host_createObjects ([OpsiClient (** client_config )])
257254 self ._client_created_by_script = True
258255
259- def _put_client_into_group (self , client_id ):
256+ def _put_client_into_group (self ):
260257 if not self .group :
261258 return
262259
263260 mapping = {
264261 "type" : "ObjectToGroup" ,
265262 "groupType" : "HostGroup" ,
266263 "groupId" : self .group ,
267- "objectId" : client_id ,
264+ "objectId" : self . host ,
268265 }
269266 try :
270267 self .backend .objectToGroup_createObjects ([mapping ])
271- logger .notice ("Added %s to group %s" , client_id , self .group )
268+ logger .notice ("Added %s to group %s" , self . host , self .group )
272269 except Exception as err : # pylint: disable=broad-except
273- logger .warning ("Adding %s to group %s failed: %s" , client_id , self .group , err )
270+ logger .warning ("Adding %s to group %s failed: %s" , self . host , self .group , err )
274271
275- def _assign_client_to_depot (self , client_id ):
272+ def _assign_client_to_depot (self ):
276273 if not self .depot :
277274 return
278275
279276 depot_assignment = {
280277 "configId" : "clientconfig.depot.id" ,
281278 "values" : [self .depot ],
282- "objectId" : client_id ,
279+ "objectId" : self . host ,
283280 "type" : "ConfigState" ,
284281 }
285282 try :
286283 self .backend .configState_createObjects ([depot_assignment ])
287- logger .notice ("Assigned %s to depot %s" , client_id , self .depot )
284+ logger .notice ("Assigned %s to depot %s" , self . host , self .depot )
288285 except Exception as err : # pylint: disable=broad-except
289- logger .warning ("Assgining %s to depot %s failed: %s" , client_id , self .depot , err )
286+ logger .warning ("Assgining %s to depot %s failed: %s" , self . host , self .depot , err )
290287
291288 @staticmethod
292289 def _get_mac_address (ip_address ):
@@ -313,11 +310,11 @@ def network_address(self):
313310 raise ValueError ("No network address set!" )
314311 return self ._network_address
315312
316- def _set_network_address (self , host_id , host_name , ip_address ):
313+ def _set_network_address (self , host_name , ip_address ):
317314 if self .deployment_method == 'hostname' :
318315 self ._network_address = host_name
319316 elif self .deployment_method == 'fqdn' :
320- self ._network_address = host_id
317+ self ._network_address = self . host
321318 else :
322319 self ._network_address = ip_address
323320
@@ -332,10 +329,10 @@ def _set_client_agent_to_installing(self, host_id, product_id):
332329 )
333330 self .backend .productOnClient_updateObjects ([poc ])
334331
335- def _remove_host_from_backend (self , host ):
332+ def _remove_host_from_backend (self ):
336333 try :
337- logger .notice ("Deleting client %s from backend" , host )
338- self .backend .host_deleteObjects ([host ])
334+ logger .notice ("Deleting client %s from backend" , self . host )
335+ self .backend .host_deleteObjects ([self . host ])
339336 except Exception as err : # pylint: disable=broad-except
340337 logger .error (err )
341338
@@ -357,13 +354,13 @@ def evaluate_success(self):
357354
358355 def prepare_deploy (self ):
359356 host_name = self .host .split ('.' )[0 ]
360- ip_address = self ._get_ip_address (self . host , host_name )
357+ ip_address = self ._get_ip_address (host_name )
361358 self ._ping_client (ip_address )
362- self ._set_network_address (self . host , host_name , ip_address )
359+ self ._set_network_address (host_name , ip_address )
363360
364- self ._create_host_if_not_existing (self . host , ip_address )
365- self ._put_client_into_group (self . host )
366- self ._assign_client_to_depot (self . host )
361+ self ._create_host_if_not_existing (ip_address )
362+ self ._put_client_into_group ()
363+ self ._assign_client_to_depot ()
367364
368365 self .host_object = self .backend .host_getObjects (type = 'OpsiClient' , id = self .host )[0 ]
369366 secret_filter .add_secrets (self .host_object .opsiHostKey )
@@ -410,7 +407,7 @@ def run(self):
410407 self .result = "failed:unknownreason"
411408 logger .error ("Deployment to %s failed: %s" , self .host , error )
412409 if self ._client_created_by_script and self .host_object and not self .keep_client_on_failure :
413- self ._remove_host_from_backend (self . host_object )
410+ self ._remove_host_from_backend ()
414411
415412 finally :
416413 self .cleanup ()
0 commit comments