File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -337,13 +337,34 @@ def create_mgmt_role_model(
337337    mgmt_role  =  ApiRole (type = str (role_type ).upper ())
338338
339339    # Host assignment 
340-     host_ref  =  get_host_ref (api_client , hostname , host_id )
340+     if  hostname :
341+         host_ref  =  next (
342+             (
343+                 h 
344+                 for  h  in  HostsResourceApi (api_client ).read_hosts ().items 
345+                 if  h .hostname  ==  hostname 
346+             ),
347+             None ,
348+         )
349+     elif  host_id :
350+         try :
351+             host_ref  =  HostsResourceApi (api_client ).read_host (host_id )
352+         except  ApiException  as  ex :
353+             if  ex .status  !=  404 :
354+                 raise  ex 
355+             else :
356+                 host_ref  =  None 
357+     else :
358+         raise  RoleException ("Specify either 'hostname' or 'host_id'" )
359+ 
341360    if  host_ref  is  None :
342361        raise  RoleHostNotFoundException (
343362            f"Host not found: hostname='{ hostname } { host_id }  
344363        )
345364    else :
346-         mgmt_role .host_ref  =  host_ref 
365+         mgmt_role .host_ref  =  ApiHostRef (
366+             host_id = host_ref .host_id , hostname = host_ref .hostname 
367+         )
347368
348369    # Role override configurations 
349370    if  config :
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments