From d444bd087376285389c357fbd9d5c2fb9d561446 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Thu, 28 Feb 2013 19:39:01 -0500 Subject: [PATCH] Simplify Django organization, add South support. --- SETUP.md | 52 ++++++++++++++ acom/audits/models.py | 3 - acom/events/models.py | 3 - acom/events/tests.py | 23 ------ acom/events/views.py | 1 - acom/groups/__init__.py | 0 acom/groups/models.py | 3 - acom/groups/tests.py | 23 ------ acom/groups/views.py | 1 - acom/hosts/__init__.py | 0 acom/hosts/models.py | 3 - acom/hosts/tests.py | 23 ------ acom/hosts/views.py | 1 - acom/inventory/__init__.py | 0 acom/inventory/models.py | 3 - acom/inventory/tests.py | 23 ------ acom/inventory/views.py | 1 - acom/jobs/__init__.py | 0 acom/jobs/models.py | 3 - acom/jobs/tests.py | 23 ------ acom/jobs/views.py | 1 - acom/{audits => main}/__init__.py | 0 acom/main/__init__.pyc | Bin 0 -> 127 bytes acom/main/migrations/0001_initial.py | 36 ++++++++++ acom/{events => main/migrations}/__init__.py | 0 acom/main/migrations/__init__.pyc | Bin 0 -> 138 bytes acom/main/models.py | 21 ++++++ acom/main/models.pyc | Bin 0 -> 1235 bytes acom/{audits => main}/tests.py | 0 acom/{audits => main}/views.py | 0 acom/orgs/__init__.py | 0 acom/orgs/models.py | 3 - acom/orgs/tests.py | 23 ------ acom/orgs/views.py | 1 - acom/permissions/__init__.py | 0 acom/permissions/models.py | 3 - acom/permissions/tests.py | 23 ------ acom/permissions/views.py | 1 - acom/projects/__init__.py | 0 acom/projects/models.py | 3 - acom/projects/tests.py | 23 ------ acom/projects/views.py | 1 - acom/reports/__init__.py | 0 acom/reports/models.py | 3 - acom/reports/tests.py | 23 ------ acom/reports/views.py | 1 - acom/settings.pyc | Bin 1906 -> 1990 bytes acom/teams/__init__.py | 0 acom/teams/models.py | 3 - acom/teams/tests.py | 23 ------ acom/teams/views.py | 1 - acom/users/__init__.py | 0 acom/users/models.py | 3 - acom/users/tests.py | 23 ------ acom/users/views.py | 1 - app_setup/setup.yml | 66 ++++++++++++++++++ app_setup/templates/config.j2 | 5 ++ app_setup/templates/db.j2 | 53 ++++++++++++++ app_setup/templates/pg_hba.j2 | 7 ++ app_setup/templates/pg_hba_low.j2 | 5 ++ .../templates/settings.py.j2 | 19 ++--- app_setup/vars/vars.yml | 2 + 62 files changed, 258 insertions(+), 308 deletions(-) create mode 100644 SETUP.md delete mode 100644 acom/audits/models.py delete mode 100644 acom/events/models.py delete mode 100644 acom/events/tests.py delete mode 100644 acom/events/views.py delete mode 100644 acom/groups/__init__.py delete mode 100644 acom/groups/models.py delete mode 100644 acom/groups/tests.py delete mode 100644 acom/groups/views.py delete mode 100644 acom/hosts/__init__.py delete mode 100644 acom/hosts/models.py delete mode 100644 acom/hosts/tests.py delete mode 100644 acom/hosts/views.py delete mode 100644 acom/inventory/__init__.py delete mode 100644 acom/inventory/models.py delete mode 100644 acom/inventory/tests.py delete mode 100644 acom/inventory/views.py delete mode 100644 acom/jobs/__init__.py delete mode 100644 acom/jobs/models.py delete mode 100644 acom/jobs/tests.py delete mode 100644 acom/jobs/views.py rename acom/{audits => main}/__init__.py (100%) create mode 100644 acom/main/__init__.pyc create mode 100644 acom/main/migrations/0001_initial.py rename acom/{events => main/migrations}/__init__.py (100%) create mode 100644 acom/main/migrations/__init__.pyc create mode 100644 acom/main/models.py create mode 100644 acom/main/models.pyc rename acom/{audits => main}/tests.py (100%) rename acom/{audits => main}/views.py (100%) delete mode 100644 acom/orgs/__init__.py delete mode 100644 acom/orgs/models.py delete mode 100644 acom/orgs/tests.py delete mode 100644 acom/orgs/views.py delete mode 100644 acom/permissions/__init__.py delete mode 100644 acom/permissions/models.py delete mode 100644 acom/permissions/tests.py delete mode 100644 acom/permissions/views.py delete mode 100644 acom/projects/__init__.py delete mode 100644 acom/projects/models.py delete mode 100644 acom/projects/tests.py delete mode 100644 acom/projects/views.py delete mode 100644 acom/reports/__init__.py delete mode 100644 acom/reports/models.py delete mode 100644 acom/reports/tests.py delete mode 100644 acom/reports/views.py delete mode 100644 acom/teams/__init__.py delete mode 100644 acom/teams/models.py delete mode 100644 acom/teams/tests.py delete mode 100644 acom/teams/views.py delete mode 100644 acom/users/__init__.py delete mode 100644 acom/users/models.py delete mode 100644 acom/users/tests.py delete mode 100644 acom/users/views.py create mode 100644 app_setup/setup.yml create mode 100644 app_setup/templates/config.j2 create mode 100644 app_setup/templates/db.j2 create mode 100644 app_setup/templates/pg_hba.j2 create mode 100644 app_setup/templates/pg_hba_low.j2 rename acom/settings.py => app_setup/templates/settings.py.j2 (82%) create mode 100644 app_setup/vars/vars.yml diff --git a/SETUP.md b/SETUP.md new file mode 100644 index 0000000000..6f2914cc57 --- /dev/null +++ b/SETUP.md @@ -0,0 +1,52 @@ +SETUP +===== + +This will be an ansible playbook soon! + +For now these are instructions for CentOS 6. + +Install ansible-commander +========================= + +Before proceeding, be aware that this should be installed on it's own +machine (or virtualmachine) as it is going to lock down the database. + +Ansible will install ansible-commander using a playbook, so you first +need to have ansible installed. Do this first and come back here. + +You will also need the EPEL yum repository installed if using CentOS6. + +First edit app_setup/vars/vars.yml to select a database password. + +If you feel like you need to change it, the Django config file is also +templated. See app_setup/templates/setting.py.j2. Most people will +not need to change this. + +run "make setup" to run the ansible setup playbook. It should run +without erros. + +This playbook will: + + * install Django and required software components + * install postgresql and configure authentication + * initialize the database + * initialize the first database table + * synchronize the database and run any migrations + +You may run this setup step again as needed as many times +as you like. + +Test the server +=============== + +make runserver + +access the server on 127.0.0.1:8000 + +Running through Apache +====================== + +TODO. + + + diff --git a/acom/audits/models.py b/acom/audits/models.py deleted file mode 100644 index 71a8362390..0000000000 --- a/acom/audits/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/acom/events/models.py b/acom/events/models.py deleted file mode 100644 index 71a8362390..0000000000 --- a/acom/events/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/acom/events/tests.py b/acom/events/tests.py deleted file mode 100644 index 2247054b35..0000000000 --- a/acom/events/tests.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -This file demonstrates two different styles of tests (one doctest and one -unittest). These will both pass when you run "manage.py test". - -Replace these with more appropriate tests for your application. -""" - -from django.test import TestCase - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.failUnlessEqual(1 + 1, 2) - -__test__ = {"doctest": """ -Another way to test that 1 + 1 is equal to 2. - ->>> 1 + 1 == 2 -True -"""} - diff --git a/acom/events/views.py b/acom/events/views.py deleted file mode 100644 index 60f00ef0ef..0000000000 --- a/acom/events/views.py +++ /dev/null @@ -1 +0,0 @@ -# Create your views here. diff --git a/acom/groups/__init__.py b/acom/groups/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/acom/groups/models.py b/acom/groups/models.py deleted file mode 100644 index 71a8362390..0000000000 --- a/acom/groups/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/acom/groups/tests.py b/acom/groups/tests.py deleted file mode 100644 index 2247054b35..0000000000 --- a/acom/groups/tests.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -This file demonstrates two different styles of tests (one doctest and one -unittest). These will both pass when you run "manage.py test". - -Replace these with more appropriate tests for your application. -""" - -from django.test import TestCase - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.failUnlessEqual(1 + 1, 2) - -__test__ = {"doctest": """ -Another way to test that 1 + 1 is equal to 2. - ->>> 1 + 1 == 2 -True -"""} - diff --git a/acom/groups/views.py b/acom/groups/views.py deleted file mode 100644 index 60f00ef0ef..0000000000 --- a/acom/groups/views.py +++ /dev/null @@ -1 +0,0 @@ -# Create your views here. diff --git a/acom/hosts/__init__.py b/acom/hosts/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/acom/hosts/models.py b/acom/hosts/models.py deleted file mode 100644 index 71a8362390..0000000000 --- a/acom/hosts/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/acom/hosts/tests.py b/acom/hosts/tests.py deleted file mode 100644 index 2247054b35..0000000000 --- a/acom/hosts/tests.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -This file demonstrates two different styles of tests (one doctest and one -unittest). These will both pass when you run "manage.py test". - -Replace these with more appropriate tests for your application. -""" - -from django.test import TestCase - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.failUnlessEqual(1 + 1, 2) - -__test__ = {"doctest": """ -Another way to test that 1 + 1 is equal to 2. - ->>> 1 + 1 == 2 -True -"""} - diff --git a/acom/hosts/views.py b/acom/hosts/views.py deleted file mode 100644 index 60f00ef0ef..0000000000 --- a/acom/hosts/views.py +++ /dev/null @@ -1 +0,0 @@ -# Create your views here. diff --git a/acom/inventory/__init__.py b/acom/inventory/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/acom/inventory/models.py b/acom/inventory/models.py deleted file mode 100644 index 71a8362390..0000000000 --- a/acom/inventory/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/acom/inventory/tests.py b/acom/inventory/tests.py deleted file mode 100644 index 2247054b35..0000000000 --- a/acom/inventory/tests.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -This file demonstrates two different styles of tests (one doctest and one -unittest). These will both pass when you run "manage.py test". - -Replace these with more appropriate tests for your application. -""" - -from django.test import TestCase - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.failUnlessEqual(1 + 1, 2) - -__test__ = {"doctest": """ -Another way to test that 1 + 1 is equal to 2. - ->>> 1 + 1 == 2 -True -"""} - diff --git a/acom/inventory/views.py b/acom/inventory/views.py deleted file mode 100644 index 60f00ef0ef..0000000000 --- a/acom/inventory/views.py +++ /dev/null @@ -1 +0,0 @@ -# Create your views here. diff --git a/acom/jobs/__init__.py b/acom/jobs/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/acom/jobs/models.py b/acom/jobs/models.py deleted file mode 100644 index 71a8362390..0000000000 --- a/acom/jobs/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/acom/jobs/tests.py b/acom/jobs/tests.py deleted file mode 100644 index 2247054b35..0000000000 --- a/acom/jobs/tests.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -This file demonstrates two different styles of tests (one doctest and one -unittest). These will both pass when you run "manage.py test". - -Replace these with more appropriate tests for your application. -""" - -from django.test import TestCase - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.failUnlessEqual(1 + 1, 2) - -__test__ = {"doctest": """ -Another way to test that 1 + 1 is equal to 2. - ->>> 1 + 1 == 2 -True -"""} - diff --git a/acom/jobs/views.py b/acom/jobs/views.py deleted file mode 100644 index 60f00ef0ef..0000000000 --- a/acom/jobs/views.py +++ /dev/null @@ -1 +0,0 @@ -# Create your views here. diff --git a/acom/audits/__init__.py b/acom/main/__init__.py similarity index 100% rename from acom/audits/__init__.py rename to acom/main/__init__.py diff --git a/acom/main/__init__.pyc b/acom/main/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..87b0fe3b1bc603252902fad4c3af71f992556cc5 GIT binary patch literal 127 zcmcckiI=PVi+*4-0~9aPO2Tq^kN`p F001D~9#;SW literal 0 HcmV?d00001 diff --git a/acom/main/models.py b/acom/main/models.py new file mode 100644 index 0000000000..badadac3fc --- /dev/null +++ b/acom/main/models.py @@ -0,0 +1,21 @@ +from django.db import models + +class CommonModel(models.Model): + ''' common model for all object types that have these standard fields ''' + + class Meta: + abstract = True + + name = models.TextField() + description = models.TextField() + creation_date = models.DateField() + db_table = 'inventories' + +class Inventory(CommonModel): + + class Meta: + db_table = 'inventory' + + id = models.AutoField(primary_key=True) + + diff --git a/acom/main/models.pyc b/acom/main/models.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d8cdc36a022a5eb30a32e56266f0fc261f80bc05 GIT binary patch literal 1235 zcmbtT!EVz)5S_J?v`t&6#EF|vC>NR^KnO^Mgiw)ib0L@2#ycU~+TO^!sqmTpAiu(i z8_bM@(*q}B$CKIF*_k)8Ichpj5C>plkxDz$LI! zU{iPi_zv)8k%AonreYoT)&bZN+)R!rj{8l|M3ELpBr0#Q4DpoInXf8eU$dcykdpl! zec>Ys1kOxA771gaL0%7|&1A?yXC$&h(q;lATlpq4 zWtsWqEfz70?FK^@*Cu9bbC0B9z$`>lThrKV<*>B0KcG0*7)=kG%M;j7Na0@NJJ zOct2%iFiyx>)KSPbsWorP;5(HvctUDqBxmlh>a;?cb0ZQwD5wo>DpH~tt_sMsi%gj z=|p8*J?*-CxoPu+T)E#t6eSIJ^*z?nHx5G=nOVrW<+VvgV9 zdoEsZas?95VkjE7iO$#Jc4Z=VZs&BUXwdMMwq%yN>{3UwEb)N4xYLX{oRJu*QSvN3 zQ~U~m54#H6o*DKPW?qug4-}0B4b;PKhH0`>a57!U1Epx7h&b+v^q~*-51Oq^Cwa?+ zbFcn(xt(zCeS34BjRPuYA}{EB%;=_Zm1$aihiw;`DSVWY&+J)zyNzDx$@w-!-gNc= zL{BLI7Ztcu%)}?TX2OKMHT742X_sAkPAE4$=RW0p^8XXdEWPTk&TEb*04|c}r+)yu Ci1mX2 literal 0 HcmV?d00001 diff --git a/acom/audits/tests.py b/acom/main/tests.py similarity index 100% rename from acom/audits/tests.py rename to acom/main/tests.py diff --git a/acom/audits/views.py b/acom/main/views.py similarity index 100% rename from acom/audits/views.py rename to acom/main/views.py diff --git a/acom/orgs/__init__.py b/acom/orgs/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/acom/orgs/models.py b/acom/orgs/models.py deleted file mode 100644 index 71a8362390..0000000000 --- a/acom/orgs/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/acom/orgs/tests.py b/acom/orgs/tests.py deleted file mode 100644 index 2247054b35..0000000000 --- a/acom/orgs/tests.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -This file demonstrates two different styles of tests (one doctest and one -unittest). These will both pass when you run "manage.py test". - -Replace these with more appropriate tests for your application. -""" - -from django.test import TestCase - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.failUnlessEqual(1 + 1, 2) - -__test__ = {"doctest": """ -Another way to test that 1 + 1 is equal to 2. - ->>> 1 + 1 == 2 -True -"""} - diff --git a/acom/orgs/views.py b/acom/orgs/views.py deleted file mode 100644 index 60f00ef0ef..0000000000 --- a/acom/orgs/views.py +++ /dev/null @@ -1 +0,0 @@ -# Create your views here. diff --git a/acom/permissions/__init__.py b/acom/permissions/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/acom/permissions/models.py b/acom/permissions/models.py deleted file mode 100644 index 71a8362390..0000000000 --- a/acom/permissions/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/acom/permissions/tests.py b/acom/permissions/tests.py deleted file mode 100644 index 2247054b35..0000000000 --- a/acom/permissions/tests.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -This file demonstrates two different styles of tests (one doctest and one -unittest). These will both pass when you run "manage.py test". - -Replace these with more appropriate tests for your application. -""" - -from django.test import TestCase - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.failUnlessEqual(1 + 1, 2) - -__test__ = {"doctest": """ -Another way to test that 1 + 1 is equal to 2. - ->>> 1 + 1 == 2 -True -"""} - diff --git a/acom/permissions/views.py b/acom/permissions/views.py deleted file mode 100644 index 60f00ef0ef..0000000000 --- a/acom/permissions/views.py +++ /dev/null @@ -1 +0,0 @@ -# Create your views here. diff --git a/acom/projects/__init__.py b/acom/projects/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/acom/projects/models.py b/acom/projects/models.py deleted file mode 100644 index 71a8362390..0000000000 --- a/acom/projects/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/acom/projects/tests.py b/acom/projects/tests.py deleted file mode 100644 index 2247054b35..0000000000 --- a/acom/projects/tests.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -This file demonstrates two different styles of tests (one doctest and one -unittest). These will both pass when you run "manage.py test". - -Replace these with more appropriate tests for your application. -""" - -from django.test import TestCase - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.failUnlessEqual(1 + 1, 2) - -__test__ = {"doctest": """ -Another way to test that 1 + 1 is equal to 2. - ->>> 1 + 1 == 2 -True -"""} - diff --git a/acom/projects/views.py b/acom/projects/views.py deleted file mode 100644 index 60f00ef0ef..0000000000 --- a/acom/projects/views.py +++ /dev/null @@ -1 +0,0 @@ -# Create your views here. diff --git a/acom/reports/__init__.py b/acom/reports/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/acom/reports/models.py b/acom/reports/models.py deleted file mode 100644 index 71a8362390..0000000000 --- a/acom/reports/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/acom/reports/tests.py b/acom/reports/tests.py deleted file mode 100644 index 2247054b35..0000000000 --- a/acom/reports/tests.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -This file demonstrates two different styles of tests (one doctest and one -unittest). These will both pass when you run "manage.py test". - -Replace these with more appropriate tests for your application. -""" - -from django.test import TestCase - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.failUnlessEqual(1 + 1, 2) - -__test__ = {"doctest": """ -Another way to test that 1 + 1 is equal to 2. - ->>> 1 + 1 == 2 -True -"""} - diff --git a/acom/reports/views.py b/acom/reports/views.py deleted file mode 100644 index 60f00ef0ef..0000000000 --- a/acom/reports/views.py +++ /dev/null @@ -1 +0,0 @@ -# Create your views here. diff --git a/acom/settings.pyc b/acom/settings.pyc index 659ba0531379b8b5035ca6b3d6961cfdb9a22e91..c24372f364ff0c5507ea52ceb266f384415e7793 100644 GIT binary patch delta 356 zcmXYt%}&BV6ot<~YoXB6%Elf3pfQnz9a|xRs0&eOjAk~Zawke+OG3x6G%j4YBrJRa z;{)&xF5LMltXz6qon+2;X3m|Pn_0V`mB#nlvD-h*!5II`VzzlFA1n%x0!l#UKs$>@ z?a2U{Xwe49ViZ8dKiG^CTG9lSAvty+EszUY$hs6WwZTthDbq5j0_lJ}NEfsVSpn@q zdY~;xA5@3j1nomsLE8up4|t%(SAAeG!|^oIsp)sld)iNL;$(9Bphg@-VN7b4#aBUZ zsBMn#Laok{?sOjO0v|6sL2!LB>}vK{`l9A}Y&wyeO~zrfujZrGvAD@qvnEkEiM7dj oGJVwdtGE2KFw$>Yy7^Z(NvB9Fh7Oz6yZIu->GH@rF(4p*0eL`27ytkO delta 275 zcmX@c|A|lM;wN4%nKb>tWCkc;1=0>cT)Z4eq%tr>F*2kwGDI;kq{vLvk*^2REDUBT zK#CPYu|X(yAjQF87RAbt!pRWD#*o6r5XH`r!p#uH0XBsbOmZ;*bw+W6Ngjq29)>7h zh7?|gC_aW1S%xTnh7>u5C;^5PQHCf%h7@^*C?SRv1%@bLh7@UrU=2l}gC?F*Q3g^B zB`iR~&(YTv%m@v34JzRPiUc?Y2Z#FyxlFcal;`IM3OMGb7G)+U>ieaZZ_Z gxsj0#>> 1 + 1 == 2 -True -"""} - diff --git a/acom/teams/views.py b/acom/teams/views.py deleted file mode 100644 index 60f00ef0ef..0000000000 --- a/acom/teams/views.py +++ /dev/null @@ -1 +0,0 @@ -# Create your views here. diff --git a/acom/users/__init__.py b/acom/users/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/acom/users/models.py b/acom/users/models.py deleted file mode 100644 index 71a8362390..0000000000 --- a/acom/users/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/acom/users/tests.py b/acom/users/tests.py deleted file mode 100644 index 2247054b35..0000000000 --- a/acom/users/tests.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -This file demonstrates two different styles of tests (one doctest and one -unittest). These will both pass when you run "manage.py test". - -Replace these with more appropriate tests for your application. -""" - -from django.test import TestCase - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.failUnlessEqual(1 + 1, 2) - -__test__ = {"doctest": """ -Another way to test that 1 + 1 is equal to 2. - ->>> 1 + 1 == 2 -True -"""} - diff --git a/acom/users/views.py b/acom/users/views.py deleted file mode 100644 index 60f00ef0ef..0000000000 --- a/acom/users/views.py +++ /dev/null @@ -1 +0,0 @@ -# Create your views here. diff --git a/app_setup/setup.yml b/app_setup/setup.yml new file mode 100644 index 0000000000..d490a03c89 --- /dev/null +++ b/app_setup/setup.yml @@ -0,0 +1,66 @@ +--- + +# tested only on CentOS6, may need adaptations for other operating systems +# TODO: install any ansible plugins we need +# TODO: set up Apache or Nginx to proxy this application +# TODO: setup celery and any worker processes/requirements + +- hosts: 127.0.0.1 + gather_facts: True + user: root + vars_files: + - vars/vars.yml + + tasks: + + - name: install packages + action: yum name=$item state=installed + with_items: + - postgresql # database client + - postgresql-server # database server + - Django # web stack + - Django-south # migration support + - python-django-tastypie # rest support + - python-psycopg2 + + # the following could probably be included, though ident identification is fiddly + # so we won't use it to create the database and database user + + - name: configure the database authentication more or less open for setup + template: src=templates/pg_hba_low.j2 dest=/var/lib/pgsql/data/pg_hba.conf + + - name: restart postgresql + service: name=postgresql state=restarted + + - name: setup the postgresql user + postgresql_user: > + name=ansible_commander + db=ansible_commander + password=${database_password} + login_user=postgres + priv=ALL + sudo_user: postgres + + - name: create the database + postgresql_db: name=acom state=present + + - name: configure the database authentication for runtime mode + template: src=templates/pg_hba.j2 dest=/var/lib/pgsql/data/pg_hba.conf + + - name: restart postgresql + service: name=postgresql state=restarted + + - name: configure python settings (with database password) + template: src=templates/settings.py.j2 dest=${working_dir}/acom/settings.py + + - name: sync Django database + shell: python ${working_dir}/acom/manage.py syncdb + + - name: sync django database + django_manage: > + command=syncdb + app_path=${working_dir}/acom + + #- name: run south migrations + # command: python ${working_dir}/acom/manage.py migrate db_migrate + diff --git a/app_setup/templates/config.j2 b/app_setup/templates/config.j2 new file mode 100644 index 0000000000..5950f1f8eb --- /dev/null +++ b/app_setup/templates/config.j2 @@ -0,0 +1,5 @@ +[database] +password={{ database_password }} + +[inventory] +secret=TheEnemysGateisDown diff --git a/app_setup/templates/db.j2 b/app_setup/templates/db.j2 new file mode 100644 index 0000000000..441cb920e8 --- /dev/null +++ b/app_setup/templates/db.j2 @@ -0,0 +1,53 @@ +CREATE USER ansible_commander UNENCRYPTED PASSWORD '{{ database_password }}'; + +GRANT ALL on DATABASE ansible_commander TO ansible_commander; +GRANT ALL on DATABASE ansible_commander_test TO ansible_commander; + +\c ansible_commander + +CREATE TABLE thing +( + id BIGSERIAL PRIMARY KEY, + type TEXT +); + +CREATE TABLE properties +( + id BIGSERIAL PRIMARY KEY, + thing_id BIGSERIAL NOT NULL REFERENCES thing(id) ON DELETE CASCADE, + key TEXT NOT NULL, + value TEXT +); + +CREATE UNIQUE INDEX properties_thing_idx ON properties (thing_id, key); +CREATE INDEX properties_key_idx ON properties (key); +CREATE INDEX properties_value_idx ON properties (key, value); +GRANT ALL on TABLE thing TO ansible_commander; +GRANT ALL on TABLE properties TO ansible_commander; +GRANT ALL ON SEQUENCE thing_id_seq TO ansible_commander; +GRANT ALL ON SEQUENCE properties_id_seq TO ansible_commander; + +\c ansible_commander_test + +CREATE TABLE thing +( + id BIGSERIAL PRIMARY KEY, + type TEXT +); + +CREATE TABLE properties +( + id BIGSERIAL PRIMARY KEY, + thing_id BIGSERIAL NOT NULL REFERENCES thing(id) ON DELETE CASCADE, + key TEXT NOT NULL, + value TEXT +); + +CREATE UNIQUE INDEX properties_thing_idx ON properties (thing_id, key); +CREATE INDEX properties_key_idx ON properties (key); +CREATE INDEX properties_value_idx ON properties (key, value); +GRANT ALL on TABLE thing TO ansible_commander; +GRANT ALL on TABLE properties TO ansible_commander; +GRANT ALL ON SEQUENCE thing_id_seq TO ansible_commander; +GRANT ALL ON SEQUENCE properties_id_seq TO ansible_commander; + diff --git a/app_setup/templates/pg_hba.j2 b/app_setup/templates/pg_hba.j2 new file mode 100644 index 0000000000..1d9c0a37f4 --- /dev/null +++ b/app_setup/templates/pg_hba.j2 @@ -0,0 +1,7 @@ +# Database administrative login by UNIX sockets +local all postgres ident + +# TYPE DATABASE USER CIDR-ADDRESS METHOD +local all all md5 +host all all 127.0.0.1/32 md5 +host all all ::1/128 md5 diff --git a/app_setup/templates/pg_hba_low.j2 b/app_setup/templates/pg_hba_low.j2 new file mode 100644 index 0000000000..4df8a874cc --- /dev/null +++ b/app_setup/templates/pg_hba_low.j2 @@ -0,0 +1,5 @@ +# temporary security setup for initial config only + +# TYPE DATABASE USER CIDR-ADDRESS METHOD +local all postgres trust + diff --git a/acom/settings.py b/app_setup/templates/settings.py.j2 similarity index 82% rename from acom/settings.py rename to app_setup/templates/settings.py.j2 index 78c35f832f..486821bc30 100644 --- a/acom/settings.py +++ b/app_setup/templates/settings.py.j2 @@ -11,12 +11,12 @@ MANAGERS = ADMINS DATABASES = { 'default': { - 'ENGINE': 'postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': '', # Or path to database file if using sqlite3. - 'USER': '', # Not used with sqlite3. - 'PASSWORD': '', # Not used with sqlite3. - 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. - 'PORT': '', # Set to empty string for default. Not used with sqlite3. + 'ENGINE': 'postgresql_psycopg2', + 'NAME': 'acom', + 'USER': 'ansible_commander', + 'PASSWORD': '{{ database_password }}', + 'HOST': '', + 'PORT': '', } } @@ -27,7 +27,7 @@ DATABASES = { # timezone as the operating system. # If running in a Windows environment this must be set to the same as your # system time zone. -TIME_ZONE = 'America/NewYork' +TIME_ZONE = 'America/New_York' # Language code for this installation. All choices can be found here: # http://www.i18nguy.com/unicode/language-identifiers.html @@ -89,8 +89,11 @@ INSTALLED_APPS = ( 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', + 'main', + 'south', + # Uncomment the next line to enable the admin: - # 'django.contrib.admin', + #'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', ) diff --git a/app_setup/vars/vars.yml b/app_setup/vars/vars.yml new file mode 100644 index 0000000000..4962518171 --- /dev/null +++ b/app_setup/vars/vars.yml @@ -0,0 +1,2 @@ +--- +database_password: gateIsDown