mirror of
https://github.com/ansible/awx.git
synced 2026-05-20 07:17:40 -02:30
Initial Database Configuration bootstrap
* Settings manifest, mapping internal settings to what can be used in the database along with type information etc. * Initial Database model * Helper object that overlays database settings on django settings
This commit is contained in:
40
awx/main/conf.py
Normal file
40
awx/main/conf.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) 2015 Ansible, Inc..
|
||||
# All Rights Reserved.
|
||||
|
||||
import json
|
||||
from django.conf import settings as django_settings
|
||||
from awx.main.models.configuration import TowerSettings
|
||||
|
||||
class TowerSettings(object):
|
||||
|
||||
def __getattr__(self, key):
|
||||
ts = TowerSettings.objects.filter(key=name)
|
||||
if not ts.exists:
|
||||
return getattr(django_settings, key)
|
||||
ts = ts[0]
|
||||
if ts.value_type == 'json':
|
||||
converted_type = json.loads(ts.value)
|
||||
elif ts.value_type == 'password':
|
||||
converted_type = ts.value
|
||||
elif ts.value_type == 'list':
|
||||
converted_type = [x.strip() for x in a.split(',')]
|
||||
else:
|
||||
t = getattr(__builtin__, ts.value_type)
|
||||
converted_type = t(ts.value)
|
||||
return converted_type
|
||||
|
||||
def create(key, value):
|
||||
settings_manifest = django_settings.TOWER_SETTINGS_MANIFEST
|
||||
if key not in settings_manifest:
|
||||
raise AttributeError("Tower Setting with key '{0}' does not exist".format(key))
|
||||
settings_entry = settings_manifest[key]
|
||||
setting_actual = TowerSettings.objects.filter(key=key)
|
||||
if not settings_actual.exists():
|
||||
settings_actual = TowerSettings(key=key,
|
||||
description=settings_entry['description'],
|
||||
category=settings_entry['category'],
|
||||
value=value,
|
||||
value_type=settings_entry['type'])
|
||||
else:
|
||||
settings_actual['value'] = value
|
||||
settings_actual.save()
|
||||
42
awx/main/models/configuration.py
Normal file
42
awx/main/models/configuration.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# Copyright (c) 2015 Ansible, Inc.
|
||||
# All Rights Reserved.
|
||||
|
||||
# Python
|
||||
|
||||
# Django
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
|
||||
# Tower
|
||||
from awx.main.models.base import CreatedModifiedModel
|
||||
|
||||
class TowerSettings(CreatedModifiedModel):
|
||||
|
||||
SETTINGS_TYPE_CHOICES = [
|
||||
('string', "String"),
|
||||
('int', 'Integer'),
|
||||
('float', 'Decimal'),
|
||||
('json', 'JSON'),
|
||||
('password', 'Password'),
|
||||
('list', 'List')
|
||||
]
|
||||
|
||||
key = models.CharField(
|
||||
max_length=255,
|
||||
unique=True
|
||||
)
|
||||
description = models.TextField()
|
||||
category = models.CharField(max_length=128)
|
||||
value = models.TextField()
|
||||
value_type = models.CharField(
|
||||
max_length=12,
|
||||
choices=SETTINGS_TYPE_CHOICES
|
||||
)
|
||||
user = models.ForeignKey(
|
||||
'auth.User',
|
||||
related_name='settings',
|
||||
default=None,
|
||||
null=True,
|
||||
editable=False,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user