mirror of
https://github.com/ansible/awx.git
synced 2026-02-19 20:20:06 -03:30
Enhance query string in ad hoc command event save to consider smart inventory
This commit is contained in:
@@ -347,7 +347,6 @@ class AdHocCommandEvent(CreatedModifiedModel):
|
|||||||
return u'%s @ %s' % (self.get_event_display(), self.created.isoformat())
|
return u'%s @ %s' % (self.get_event_display(), self.created.isoformat())
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
from awx.main.models.inventory import Host
|
|
||||||
# If update_fields has been specified, add our field names to it,
|
# If update_fields has been specified, add our field names to it,
|
||||||
# if it hasn't been specified, then we're just doing a normal save.
|
# if it hasn't been specified, then we're just doing a normal save.
|
||||||
update_fields = kwargs.get('update_fields', [])
|
update_fields = kwargs.get('update_fields', [])
|
||||||
@@ -364,16 +363,16 @@ class AdHocCommandEvent(CreatedModifiedModel):
|
|||||||
self.host_name = self.event_data.get('host', '').strip()
|
self.host_name = self.event_data.get('host', '').strip()
|
||||||
if 'host_name' not in update_fields:
|
if 'host_name' not in update_fields:
|
||||||
update_fields.append('host_name')
|
update_fields.append('host_name')
|
||||||
try:
|
if not self.host_id and self.host_name:
|
||||||
if not self.host_id and self.host_name:
|
host_qs = self.ad_hoc_command.inventory.hosts.filter(name=self.host_name)
|
||||||
host_qs = Host.objects.filter(inventory__ad_hoc_commands__id=self.ad_hoc_command_id, name=self.host_name)
|
try:
|
||||||
host_id = host_qs.only('id').values_list('id', flat=True)
|
host_id = host_qs.only('id').values_list('id', flat=True)
|
||||||
if host_id.exists():
|
if host_id.exists():
|
||||||
self.host_id = host_id[0]
|
self.host_id = host_id[0]
|
||||||
if 'host_id' not in update_fields:
|
if 'host_id' not in update_fields:
|
||||||
update_fields.append('host_id')
|
update_fields.append('host_id')
|
||||||
except (IndexError, AttributeError):
|
except (IndexError, AttributeError):
|
||||||
pass
|
pass
|
||||||
super(AdHocCommandEvent, self).save(*args, **kwargs)
|
super(AdHocCommandEvent, self).save(*args, **kwargs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user