From 56b0da30f1861d9d0510ff7e05215374c92817cf Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Tue, 9 Feb 2016 16:20:44 -0500 Subject: [PATCH] adds fact model --- .../migrations/0003_auto_20160209_1615.py | 31 ++++++++++++++++++ awx/main/models/__init__.py | 1 + awx/main/models/fact.py | 32 +++++++++++++++++++ docs/licenses/django-jsonbfield.txt | 27 ++++++++++++++++ requirements/requirements.txt | 1 + 5 files changed, 92 insertions(+) create mode 100644 awx/main/migrations/0003_auto_20160209_1615.py create mode 100644 awx/main/models/fact.py create mode 100644 docs/licenses/django-jsonbfield.txt diff --git a/awx/main/migrations/0003_auto_20160209_1615.py b/awx/main/migrations/0003_auto_20160209_1615.py new file mode 100644 index 0000000000..c489c1d830 --- /dev/null +++ b/awx/main/migrations/0003_auto_20160209_1615.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import jsonbfield.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0002_v300_changes'), + ] + + operations = [ + migrations.CreateModel( + name='Fact', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('timestamp', models.DateTimeField(default=None, editable=False)), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), + ('module', models.CharField(max_length=128)), + ('facts', jsonbfield.fields.JSONField(default={}, blank=True)), + ('host', models.ForeignKey(related_name='facts', to='main.Host')), + ], + ), + migrations.AlterIndexTogether( + name='fact', + index_together=set([('timestamp', 'module', 'host')]), + ), + ] diff --git a/awx/main/models/__init__.py b/awx/main/models/__init__.py index 23cf591e6b..9b00bbc14c 100644 --- a/awx/main/models/__init__.py +++ b/awx/main/models/__init__.py @@ -17,6 +17,7 @@ from awx.main.models.schedules import * # noqa from awx.main.models.activity_stream import * # noqa from awx.main.models.ha import * # noqa from awx.main.models.configuration import * # noqa +from awx.main.models.fact import * # noqa # Monkeypatch Django serializer to ignore django-taggit fields (which break # the dumpdata command; see https://github.com/alex/django-taggit/issues/155). diff --git a/awx/main/models/fact.py b/awx/main/models/fact.py new file mode 100644 index 0000000000..35288c489c --- /dev/null +++ b/awx/main/models/fact.py @@ -0,0 +1,32 @@ +# Copyright (c) 2016 Ansible, Inc. +# All Rights Reserved. + +from django.db import models +from jsonbfield.fields import JSONField + +from awx.main.models import Host + +__all__ = ('Fact', ) + +class Fact(models.Model): + """A model representing a fact returned from Ansible. + Facts are stored as JSON dictionaries. + """ + host = models.ForeignKey( + Host, + related_name='facts', + db_index=True, + on_delete=models.CASCADE, + ) + timestamp = models.DateTimeField(default=None, editable=False) + created = models.DateTimeField(editable=False, auto_now_add=True) + modified = models.DateTimeField(editable=False, auto_now=True) + module = models.CharField(max_length=128) + facts = JSONField(blank=True, default={}) + + class Meta: + app_label = 'main' + index_together = [ + ["timestamp", "module", "host"], + ] + diff --git a/docs/licenses/django-jsonbfield.txt b/docs/licenses/django-jsonbfield.txt new file mode 100644 index 0000000000..5f4f225dd2 --- /dev/null +++ b/docs/licenses/django-jsonbfield.txt @@ -0,0 +1,27 @@ +Copyright (c) Django Software Foundation and individual contributors. +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. Neither the name of Django nor the names of its contributors may be used + to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 48857bc6d2..8f889704fb 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -49,6 +49,7 @@ importlib==1.0.3 ipaddress==1.0.14 iso8601==0.1.10 isodate==0.5.1 +git+https://github.com/chrismeyersfsu/django-jsonbfield@master#egg=django-jsonbfield jsonpatch==1.11 jsonpointer==1.9 jsonschema==2.5.1