remove facts_latest in favor of ansible_facts

* Closer align our facts data structure with ansible facts data
structure for purposes of ... wait for it ... 2-way fact caching
This commit is contained in:
Chris Meyers
2017-04-17 14:27:33 -04:00
parent 14a03d2cb5
commit 55268a8ff0
7 changed files with 57 additions and 73 deletions

View File

@@ -19,7 +19,7 @@ from django.utils.timezone import now
# AWX
from awx.api.versioning import reverse
from awx.main.constants import CLOUD_PROVIDERS
from awx.main.fields import ImplicitRoleField
from awx.main.fields import ImplicitRoleField, JSONBField
from awx.main.managers import HostManager
from awx.main.models.base import * # noqa
from awx.main.models.unified_jobs import * # noqa
@@ -382,6 +382,11 @@ class Host(CommonModelNameNotUnique):
editable=False,
help_text=_('Inventory source(s) that created or modified this host.'),
)
ansible_facts = JSONBField(
blank=True,
default={},
help_text=_('Arbitrary JSON structure of most recent ansible_facts, per-host.'),
)
objects = HostManager()
@@ -444,6 +449,16 @@ class Host(CommonModelNameNotUnique):
# Use .job_host_summaries.all() to get jobs affecting this host.
# Use .job_events.all() to get events affecting this host.
'''
We don't use timestamp, but we may in the future.
'''
def update_ansible_facts(self, module, facts, timestamp=None):
if module == "ansible":
self.ansible_facts.update(facts)
else:
self.ansible_facts[module] = facts
self.save()
class Group(CommonModelNameNotUnique):
'''