Skip to content

Commit 79e7c8a

Browse files
authored
Remove reference to circular import of get_host_ref for create_mgmt_role_model() (#284)
Signed-off-by: Webster Mudge <[email protected]>
1 parent 0d87809 commit 79e7c8a

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

plugins/module_utils/role_utils.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff 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='{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:

0 commit comments

Comments
 (0)