mirror of
https://github.com/ansible/awx.git
synced 2026-05-20 07:17:40 -02:30
AdHocCommand support added to task manager
This commit is contained in:
@@ -25,6 +25,7 @@ from awx.main.scheduler.partial import (
|
|||||||
InventoryUpdateLatestDict,
|
InventoryUpdateLatestDict,
|
||||||
InventorySourceDict,
|
InventorySourceDict,
|
||||||
SystemJobDict,
|
SystemJobDict,
|
||||||
|
AdHocCommandDict,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Celery
|
# Celery
|
||||||
@@ -42,15 +43,11 @@ class Scheduler():
|
|||||||
status_list = ('pending', 'waiting', 'running')
|
status_list = ('pending', 'waiting', 'running')
|
||||||
|
|
||||||
jobs = JobDict.filter_partial(status=status_list)
|
jobs = JobDict.filter_partial(status=status_list)
|
||||||
'''
|
|
||||||
graph_ad_hoc_commands = [ahc for ahc in AdHocCommand.objects.filter(**kv)]
|
|
||||||
'''
|
|
||||||
inventory_updates = InventoryUpdateDict.filter_partial(status=status_list)
|
inventory_updates = InventoryUpdateDict.filter_partial(status=status_list)
|
||||||
project_updates = ProjectUpdateDict.filter_partial(status=status_list)
|
project_updates = ProjectUpdateDict.filter_partial(status=status_list)
|
||||||
system_jobs = SystemJobDict.filter_partial(status=status_list)
|
system_jobs = SystemJobDict.filter_partial(status=status_list)
|
||||||
|
ad_hoc_commands = AdHocCommandDict.filter_partial(status=status_list)
|
||||||
'''
|
'''
|
||||||
graph_system_jobs = [sj for sj in
|
|
||||||
SystemJob.objects.filter(**kv)]
|
|
||||||
graph_workflow_jobs = [wf for wf in
|
graph_workflow_jobs = [wf for wf in
|
||||||
WorkflowJob.objects.filter(**kv)]
|
WorkflowJob.objects.filter(**kv)]
|
||||||
all_actions = sorted(graph_jobs + graph_ad_hoc_commands + graph_inventory_updates +
|
all_actions = sorted(graph_jobs + graph_ad_hoc_commands + graph_inventory_updates +
|
||||||
@@ -58,7 +55,7 @@ class Scheduler():
|
|||||||
graph_workflow_jobs,
|
graph_workflow_jobs,
|
||||||
key=lambda task: task.created)
|
key=lambda task: task.created)
|
||||||
'''
|
'''
|
||||||
all_actions = sorted(jobs + project_updates + inventory_updates + system_jobs,
|
all_actions = sorted(jobs + project_updates + inventory_updates + system_jobs + ad_hoc_commands,
|
||||||
key=lambda task: task['created'])
|
key=lambda task: task['created'])
|
||||||
return all_actions
|
return all_actions
|
||||||
|
|
||||||
@@ -236,7 +233,7 @@ class Scheduler():
|
|||||||
map(lambda task: self.graph.add_latest_inventory_update(task), latest_inventory_updates)
|
map(lambda task: self.graph.add_latest_inventory_update(task), latest_inventory_updates)
|
||||||
|
|
||||||
def process_inventory_sources(self, inventory_id_sources):
|
def process_inventory_sources(self, inventory_id_sources):
|
||||||
map(lambda inventory_id, inventory_sources: self.graph.add_inventory_sources(inventory_id, inventory_sources), inventory_id_sources)
|
map(lambda (inventory_id, inventory_sources): self.graph.add_inventory_sources(inventory_id, inventory_sources), inventory_id_sources)
|
||||||
|
|
||||||
def process_dependencies(self, dependent_task, dependency_tasks):
|
def process_dependencies(self, dependent_task, dependency_tasks):
|
||||||
for task in dependency_tasks:
|
for task in dependency_tasks:
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from awx.main.scheduler.partial import (
|
|||||||
ProjectUpdateDict,
|
ProjectUpdateDict,
|
||||||
InventoryUpdateDict,
|
InventoryUpdateDict,
|
||||||
SystemJobDict,
|
SystemJobDict,
|
||||||
|
AdHocCommandDict,
|
||||||
)
|
)
|
||||||
class DependencyGraph(object):
|
class DependencyGraph(object):
|
||||||
PROJECT_UPDATES = 'project_updates'
|
PROJECT_UPDATES = 'project_updates'
|
||||||
@@ -140,8 +141,8 @@ class DependencyGraph(object):
|
|||||||
def can_project_update_run(self, job):
|
def can_project_update_run(self, job):
|
||||||
return self.data[self.PROJECT_UPDATES].get(job['project_id'], True)
|
return self.data[self.PROJECT_UPDATES].get(job['project_id'], True)
|
||||||
|
|
||||||
def can_inventory_update_run(self, inventory_source_id):
|
def can_inventory_update_run(self, job):
|
||||||
return self.data[self.INVENTORY_SOURCE_UPDATES].get(inventory_source_id, True)
|
return self.data[self.INVENTORY_SOURCE_UPDATES].get(job['inventory_source_id'], True)
|
||||||
|
|
||||||
def can_job_run(self, job):
|
def can_job_run(self, job):
|
||||||
if self.can_project_update_run(job) is True and \
|
if self.can_project_update_run(job) is True and \
|
||||||
@@ -155,15 +156,20 @@ class DependencyGraph(object):
|
|||||||
def can_system_job_run(self):
|
def can_system_job_run(self):
|
||||||
return self.data[self.SYSTEM_JOB]
|
return self.data[self.SYSTEM_JOB]
|
||||||
|
|
||||||
|
def can_ad_hoc_command_run(self, job):
|
||||||
|
return self.data[self.INVENTORY_UPDATES].get(job['inventory_id'], True)
|
||||||
|
|
||||||
def is_job_blocked(self, job):
|
def is_job_blocked(self, job):
|
||||||
if type(job) is ProjectUpdateDict:
|
if type(job) is ProjectUpdateDict:
|
||||||
return not self.can_project_update_run(job)
|
return not self.can_project_update_run(job)
|
||||||
elif type(job) is InventoryUpdateDict:
|
elif type(job) is InventoryUpdateDict:
|
||||||
return not self.can_inventory_update_run(job['inventory_source_id'])
|
return not self.can_inventory_update_run(job)
|
||||||
elif type(job) is JobDict:
|
elif type(job) is JobDict:
|
||||||
return not self.can_job_run(job)
|
return not self.can_job_run(job)
|
||||||
elif type(job) is SystemJobDict:
|
elif type(job) is SystemJobDict:
|
||||||
return not self.can_system_job_run()
|
return not self.can_system_job_run()
|
||||||
|
elif type(job) is AdHocCommandDict:
|
||||||
|
return not self.can_ad_hoc_command_run(job)
|
||||||
|
|
||||||
def add_job(self, job):
|
def add_job(self, job):
|
||||||
if type(job) is ProjectUpdateDict:
|
if type(job) is ProjectUpdateDict:
|
||||||
@@ -175,6 +181,8 @@ class DependencyGraph(object):
|
|||||||
self.mark_job_template_job(job)
|
self.mark_job_template_job(job)
|
||||||
elif type(job) is SystemJobDict:
|
elif type(job) is SystemJobDict:
|
||||||
self.mark_system_job()
|
self.mark_system_job()
|
||||||
|
elif type(job) is AdHocCommandDict:
|
||||||
|
self.mark_inventory_update(job['inventory_id'])
|
||||||
|
|
||||||
def add_jobs(self, jobs):
|
def add_jobs(self, jobs):
|
||||||
map(lambda j: self.add_job(j), jobs)
|
map(lambda j: self.add_job(j), jobs)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from awx.main.models import (
|
|||||||
InventoryUpdate,
|
InventoryUpdate,
|
||||||
InventorySource,
|
InventorySource,
|
||||||
SystemJob,
|
SystemJob,
|
||||||
|
AdHocCommand,
|
||||||
)
|
)
|
||||||
|
|
||||||
class PartialModelDict(object):
|
class PartialModelDict(object):
|
||||||
@@ -192,3 +193,15 @@ class SystemJobDict(PartialModelDict):
|
|||||||
}
|
}
|
||||||
return [cls(o) for o in cls.model.objects.filter(**kv).values(*cls.get_db_values())]
|
return [cls(o) for o in cls.model.objects.filter(**kv).values(*cls.get_db_values())]
|
||||||
|
|
||||||
|
class AdHocCommandDict(PartialModelDict):
|
||||||
|
FIELDS = (
|
||||||
|
'id', 'created', 'status', 'inventory_id',
|
||||||
|
)
|
||||||
|
model = AdHocCommand
|
||||||
|
|
||||||
|
def get_job_type_str(self):
|
||||||
|
return 'ad_hoc_command'
|
||||||
|
|
||||||
|
def task_impact(self):
|
||||||
|
return 20
|
||||||
|
|
||||||
|
|||||||
@@ -1756,7 +1756,7 @@ class RunAdHocCommand(BaseTask):
|
|||||||
'''
|
'''
|
||||||
Hook for actions to run after ad hoc command has completed.
|
Hook for actions to run after ad hoc command has completed.
|
||||||
'''
|
'''
|
||||||
super(RunAdHocCommand, self).post_run_hook(ad_hoc_command, **kwargs)
|
super(RunAdHocCommand, self).post_run_hook(ad_hoc_command, status, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class RunSystemJob(BaseTask):
|
class RunSystemJob(BaseTask):
|
||||||
|
|||||||
Reference in New Issue
Block a user