Skip to content

Commit

Permalink
refactor: change util function as per suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Izquierdo committed Oct 27, 2023
1 parent 63b1497 commit f99e4db
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
5 changes: 4 additions & 1 deletion ansible_rulebook/action/run_job_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def __init__(self, metadata: Metadata, control: Control, **action_args):
self.organization = self.action_args["organization"]
self.job_id = str(uuid.uuid4())
self.job_args = self.action_args.get("job_args", {})
process_controller_host_limit(self)
self.job_args["limit"] = process_controller_host_limit(
self.job_args,
self.helper.control.hosts,
)
self.controller_job = {}

async def __call__(self):
Expand Down
5 changes: 4 additions & 1 deletion ansible_rulebook/action/run_workflow_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def __init__(self, metadata: Metadata, control: Control, **action_args):
self.organization = self.action_args["organization"]
self.job_id = str(uuid.uuid4())
self.job_args = self.action_args.get("job_args", {})
process_controller_host_limit(self)
self.job_args["limit"] = process_controller_host_limit(
self.job_args,
self.helper.control.hosts,
)
self.controller_job = {}

async def __call__(self):
Expand Down
23 changes: 9 additions & 14 deletions ansible_rulebook/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,12 @@ def _builtin_filter_path(name: str) -> Tuple[bool, str]:

# TODO(alex): This function should be removed after the
# controller templates are refactored to deduplicate code
def process_controller_host_limit(template_obj):
if "limit" in template_obj.job_args:
if isinstance(template_obj.job_args["limit"], list):
template_obj.job_args["limit"] = ",".join(
template_obj.job_args["limit"],
)
else:
template_obj.job_args["limit"] = str(
template_obj.job_args["limit"],
)
else:
template_obj.job_args["limit"] = ",".join(
template_obj.helper.control.hosts,
)
def process_controller_host_limit(
job_args: dict,
parent_hosts: list[str],
) -> str:
if "limit" in job_args:
if isinstance(job_args["limit"], list):
return ",".join(job_args["limit"])
return str(job_args["limit"])
return ",".join(parent_hosts)

0 comments on commit f99e4db

Please sign in to comment.