mirror of
https://github.com/ansible/awx.git
synced 2026-08-05 20:40:01 -02:30
Merge pull request #6242 from chrismeyersfsu/implement-6203
associate insights machine id w/ host on fact scan
This commit is contained in:
@@ -12,6 +12,7 @@ from kombu.mixins import ConsumerMixin
|
||||
from django.core.management.base import NoArgsCommand
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
from django.db import IntegrityError
|
||||
|
||||
# AWX
|
||||
from awx.main.models.jobs import Job
|
||||
@@ -120,6 +121,14 @@ class FactBrokerWorker(ConsumerMixin):
|
||||
ret = self._do_fact_scan_create_update(host_obj, module_name, facts, self.timestamp)
|
||||
|
||||
if job.store_facts is True:
|
||||
if module_name == 'insights':
|
||||
system_id = facts.get('system_id', None)
|
||||
host_obj.insights_system_id = system_id
|
||||
try:
|
||||
host_obj.save()
|
||||
except IntegrityError:
|
||||
host_obj.insights_system_id = None
|
||||
logger.warn('Inisghts system_id %s not assigned to host %s because it already exists.' % (system_id, host_obj.pk))
|
||||
self._do_gather_facts_update(host_obj, module_name, facts, self.timestamp)
|
||||
|
||||
message.ack()
|
||||
|
||||
@@ -236,4 +236,15 @@ class Migration(migrations.Migration):
|
||||
migrations.DeleteModel(
|
||||
name='Permission',
|
||||
),
|
||||
|
||||
# Insights
|
||||
migrations.AddField(
|
||||
model_name='host',
|
||||
name='insights_system_id',
|
||||
field=models.TextField(default=None, help_text='Red Hat Insights host unique identifier.', null=True, db_index=True, blank=True),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='host',
|
||||
unique_together=set([('insights_system_id', 'inventory'), ('name', 'inventory')]),
|
||||
),
|
||||
]
|
||||
|
||||
@@ -353,7 +353,7 @@ class Host(CommonModelNameNotUnique):
|
||||
|
||||
class Meta:
|
||||
app_label = 'main'
|
||||
unique_together = (("name", "inventory"),) # FIXME: Add ('instance_id', 'inventory') after migration.
|
||||
unique_together = (("name", "inventory"), ("insights_system_id", "inventory"),) # FIXME: Add ('instance_id', 'inventory') after migration.
|
||||
ordering = ('name',)
|
||||
|
||||
inventory = models.ForeignKey(
|
||||
@@ -414,6 +414,13 @@ class Host(CommonModelNameNotUnique):
|
||||
default={},
|
||||
help_text=_('Arbitrary JSON structure of most recent ansible_facts, per-host.'),
|
||||
)
|
||||
insights_system_id = models.TextField(
|
||||
blank=True,
|
||||
default=None,
|
||||
null=True,
|
||||
db_index=True,
|
||||
help_text=_('Red Hat Insights host unique identifier.'),
|
||||
)
|
||||
|
||||
objects = HostManager()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user