mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 18:07:36 -02:30
Adjust HostManager and update summary host query
This commit is contained in:
@@ -1936,7 +1936,7 @@ class HostList(ListCreateAPIView):
|
|||||||
if filter_string:
|
if filter_string:
|
||||||
filter_qs = SmartFilter.query_from_string(filter_string)
|
filter_qs = SmartFilter.query_from_string(filter_string)
|
||||||
qs &= filter_qs
|
qs &= filter_qs
|
||||||
return qs.order_by('pk').distinct()
|
return qs.distinct()
|
||||||
|
|
||||||
def list(self, *args, **kwargs):
|
def list(self, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -40,9 +40,11 @@ class HostManager(models.Manager):
|
|||||||
#
|
#
|
||||||
# If we don't disable this, a filter of {'inventory': self.instance} gets automatically
|
# If we don't disable this, a filter of {'inventory': self.instance} gets automatically
|
||||||
# injected by the related object mapper.
|
# injected by the related object mapper.
|
||||||
self.core_filters = {}
|
self.core_filters.pop('inventory', None)
|
||||||
|
|
||||||
qs = qs & q
|
qs = qs & q
|
||||||
return qs.order_by('pk').distinct('name')
|
unique_by_name = qs.order_by('name', 'pk').distinct('name')
|
||||||
|
return qs.filter(pk__in=unique_by_name)
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1195,25 +1195,9 @@ class JobEvent(CreatedModifiedModel):
|
|||||||
pass
|
pass
|
||||||
return hostnames
|
return hostnames
|
||||||
|
|
||||||
def _update_smart_inventory_hosts(self, hostnames):
|
|
||||||
'''If the job the job_event is for was run using a Smart Inventory
|
|
||||||
update the hosts fields related to job history and summary.
|
|
||||||
'''
|
|
||||||
with ignore_inventory_computed_fields():
|
|
||||||
if hasattr(self.job, 'inventory') and self.job.inventory.kind == 'smart':
|
|
||||||
logger.debug(self.job.inventory)
|
|
||||||
smart_hosts = self.job.inventory.hosts.filter(name__in=hostnames)
|
|
||||||
for smart_host in smart_hosts:
|
|
||||||
host_summary = self.job.job_host_summaries.get(host_name=smart_host.name)
|
|
||||||
smart_host.inventory.jobs.add(self.job)
|
|
||||||
smart_host.last_job_id = self.job_id
|
|
||||||
smart_host.last_job_host_summary_id = host_summary.pk
|
|
||||||
smart_host.save()
|
|
||||||
|
|
||||||
def _update_host_summary_from_stats(self, hostnames):
|
def _update_host_summary_from_stats(self, hostnames):
|
||||||
with ignore_inventory_computed_fields():
|
with ignore_inventory_computed_fields():
|
||||||
from awx.main.models.inventory import Host
|
qs = self.job.inventory.hosts.filter(name__in=hostnames)
|
||||||
qs = Host.objects.filter(inventory__jobs__id=self.job_id, name__in=hostnames)
|
|
||||||
job = self.job
|
job = self.job
|
||||||
for host in hostnames:
|
for host in hostnames:
|
||||||
host_stats = {}
|
host_stats = {}
|
||||||
@@ -1269,7 +1253,6 @@ class JobEvent(CreatedModifiedModel):
|
|||||||
|
|
||||||
hostnames = self._hostnames()
|
hostnames = self._hostnames()
|
||||||
self._update_host_summary_from_stats(hostnames)
|
self._update_host_summary_from_stats(hostnames)
|
||||||
self._update_smart_inventory_hosts(hostnames)
|
|
||||||
self.job.inventory.update_computed_fields()
|
self.job.inventory.update_computed_fields()
|
||||||
|
|
||||||
emit_channel_notification('jobs-summary', dict(group_name='jobs', unified_job_id=self.job.id))
|
emit_channel_notification('jobs-summary', dict(group_name='jobs', unified_job_id=self.job.id))
|
||||||
|
|||||||
Reference in New Issue
Block a user