Implement fact caching service and mongo reference handler

This commit is contained in:
Matthew Jones
2015-02-20 16:56:35 -05:00
parent fed4262ee2
commit fd1668dfd8
5 changed files with 82 additions and 9 deletions

View File

@@ -4,13 +4,35 @@
import logging
from django.core.management.base import NoArgsCommand
from django.utils.timezone import now
from awx.main.models import * # noqa
from awx.main.socket import Socket
from pymongo import MongoClient
logger = logging.getLogger('awx.main.commands.run_fact_cache_receiver')
class FactCacheReceiver(object):
pass
def __init__(self):
self.client = MongoClient('localhost', 27017)
def process_fact_message(self, message):
host = message['host']
facts = message['facts']
host_db = self.client.host_facts
host_collection = host_db[host]
facts.update(dict(tower_host=host, datetime=now()))
host_collection.insert(facts)
def run_receiver(self):
with Socket('fact_cache', 'r') as facts:
for message in facts.listen():
print("Message received: " + str(message))
if 'host' not in message or 'facts' not in message:
continue
self.process_fact_message(message)
class Command(NoArgsCommand):
'''