mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 14:57:39 -02:30
Initial implementation of fact api endpoints
This commit is contained in:
@@ -17,4 +17,4 @@ try:
|
||||
connect(settings.MONGO_DB)
|
||||
register_key_transform(get_db())
|
||||
except ConnectionError:
|
||||
logger.warn('Failed to establish connect to MongDB "%s"' % (settings.MONGO_DB))
|
||||
logger.warn('Failed to establish connect to MongoDB "%s"' % (settings.MONGO_DB))
|
||||
|
||||
@@ -78,7 +78,7 @@ class Fact(Document):
|
||||
}
|
||||
|
||||
try:
|
||||
facts = Fact.objects.filter(**kv)
|
||||
facts = Fact.objects.filter(**kv).order_by("-timestamp")
|
||||
if not facts:
|
||||
return None
|
||||
return facts[0]
|
||||
@@ -97,7 +97,7 @@ class Fact(Document):
|
||||
'module': module,
|
||||
}
|
||||
|
||||
return FactVersion.objects.filter(**kv).values_list('timestamp')
|
||||
return FactVersion.objects.filter(**kv).order_by("-timestamp").values_list('timestamp')
|
||||
|
||||
@staticmethod
|
||||
def get_single_facts(hostnames, fact_key, fact_value, timestamp, module):
|
||||
@@ -126,6 +126,9 @@ class Fact(Document):
|
||||
}
|
||||
fields = {
|
||||
'fact.%s.$' % fact_key : 1,
|
||||
'host': 1,
|
||||
'timestamp': 1,
|
||||
'module': 1,
|
||||
}
|
||||
facts = Fact._get_collection().find(kv, fields)
|
||||
#fact_objs = [Fact(**f) for f in facts]
|
||||
@@ -136,11 +139,10 @@ class Fact(Document):
|
||||
fact_objs.append(Fact(**f))
|
||||
return fact_objs
|
||||
|
||||
|
||||
class FactVersion(Document):
|
||||
timestamp = DateTimeField(required=True)
|
||||
host = ReferenceField(FactHost, required=True)
|
||||
module = StringField(max_length=50, required=True)
|
||||
module = StringField(max_length=50, required=True)
|
||||
fact = ReferenceField(Fact, required=True)
|
||||
# TODO: Consider using hashed index on module. django-mongo may not support this but
|
||||
# executing raw js will
|
||||
@@ -150,4 +152,3 @@ class FactVersion(Document):
|
||||
'module'
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user