change facts_recent to facts_latest

This commit is contained in:
Chris Meyers
2017-04-05 16:50:38 -04:00
parent 02795e526c
commit ee09bca558
6 changed files with 22 additions and 22 deletions

View File

@@ -2264,12 +2264,12 @@ class RoleAccess(BaseAccess):
return False
class FactRecentAccess(BaseAccess):
class FactLatestAccess(BaseAccess):
model = FactRecent
model = FactLatest
def get_queryset(self):
return FactRecent.objects.distinct()
return FactLatest.objects.distinct()
register_access(User, UserAccess)
@@ -2304,4 +2304,4 @@ register_access(WorkflowJobTemplateNode, WorkflowJobTemplateNodeAccess)
register_access(WorkflowJobNode, WorkflowJobNodeAccess)
register_access(WorkflowJobTemplate, WorkflowJobTemplateAccess)
register_access(WorkflowJob, WorkflowJobAccess)
register_access(FactRecent, FactRecentAccess)
register_access(FactLatest, FactLatestAccess)

View File

@@ -9,7 +9,7 @@ from psycopg2.extensions import AsIs
# AWX
import awx.main.fields
from awx.main.models import FactRecent
from awx.main.models import FactLatest
class Migration(migrations.Migration):
@@ -20,13 +20,13 @@ class Migration(migrations.Migration):
operations = [
migrations.CreateModel(
name='FactRecent',
name='FactLatest',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('timestamp', models.DateTimeField(default=None, help_text='Date and time of the corresponding fact scan gathering time.', editable=False)),
('module', models.CharField(max_length=128)),
('facts', awx.main.fields.JSONBField(default={}, help_text='Arbitrary JSON structure of module facts captured at timestamp for a single host.', blank=True)),
('host', models.ForeignKey(related_name='facts_recent', to='main.Host', help_text='Host for the facts that the fact scan captured.')),
('host', models.ForeignKey(related_name='facts_latest', to='main.Host', help_text='Host for the facts that the fact scan captured.')),
],
),
migrations.AlterField(
@@ -35,10 +35,10 @@ class Migration(migrations.Migration):
field=awx.main.fields.JSONBField(default={}, help_text='Arbitrary JSON structure of module facts captured at timestamp for a single host.', blank=True),
),
migrations.AlterIndexTogether(
name='factrecent',
name='factlatest',
index_together=set([('timestamp', 'module', 'host')]),
),
migrations.RunSQL([("CREATE INDEX fact_recent_facts_default_gin ON %s USING gin"
"(facts jsonb_path_ops);", [AsIs(FactRecent._meta.db_table)])],
[('DROP INDEX fact_recent_facts_default_gin;', None)]),
migrations.RunSQL([("CREATE INDEX fact_latest_facts_default_gin ON %s USING gin"
"(facts jsonb_path_ops);", [AsIs(FactLatest._meta.db_table)])],
[('DROP INDEX fact_latest_facts_default_gin;', None)]),
]

View File

@@ -6,13 +6,13 @@ from django.utils.translation import ugettext_lazy as _
from awx.main.fields import JSONBField
__all__ = ('Fact', 'FactRecent')
__all__ = ('Fact', 'FactLatest')
class FactRecent(models.Model):
class FactLatest(models.Model):
host = models.ForeignKey(
'Host',
related_name='facts_recent',
related_name='facts_latest',
db_index=True,
on_delete=models.CASCADE,
help_text=_('Host for the facts that the fact scan captured.'),
@@ -33,10 +33,10 @@ class FactRecent(models.Model):
@staticmethod
def add_fact(host_id, module, timestamp, facts):
qs = FactRecent.objects.filter(host_id=host_id, module=module)
qs = FactLatest.objects.filter(host_id=host_id, module=module)
qs.delete()
fact_obj = FactRecent.objects.create(host_id=host_id, module=module, timestamp=timestamp, facts=facts)
fact_obj = FactLatest.objects.create(host_id=host_id, module=module, timestamp=timestamp, facts=facts)
return fact_obj
@@ -91,7 +91,7 @@ class Fact(models.Model):
@staticmethod
def add_fact(host_id, module, timestamp, facts):
FactRecent.add_fact(host_id=host_id, module=module, timestamp=timestamp, facts=facts)
FactLatest.add_fact(host_id=host_id, module=module, timestamp=timestamp, facts=facts)
fact_obj = Fact.objects.create(host_id=host_id, module=module, timestamp=timestamp, facts=facts)
fact_obj.save()