Skip to content
This repository was archived by the owner on Sep 12, 2022. It is now read-only.

Commit f97780a

Browse files
Problem: Need ability for admin to modify dynamic settings
In particular for the 'enforcement override' functionality. Currently one has to modify the config file and restart services. Solution: Add the 'Constance' Django plugin and modify logic which currently uses static settings. See: https://github.com/jazzband/django-constance
1 parent 0ebcfc5 commit f97780a

8 files changed

Lines changed: 25 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
2828
### Fixed
2929
- Quota updates concerning volumes would silently fail ([#611](https://github.com/cyverse/atmosphere/pull/611))
3030

31+
### Added
32+
- Added dynamic settings feature ([#613](https://github.com/cyverse/atmosphere/pull/613))
33+
3134
## [v32-1](https://github.com/cyverse/atmosphere/compare/v32-0...v32-1) - 2018-04-17
3235
### Added
3336
- Support multiple hostnames for Atmosphere(1) server ([#602](https://github.com/cyverse/atmosphere/pull/602))

atmosphere/settings/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151

5252
# Django uses this one..
5353
MANAGERS = ADMINS
54+
CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend'
55+
CONSTANCE_DATABASE_CACHE_BACKEND = 'default'
5456

5557
DATABASES = {
5658
'default': {
@@ -92,6 +94,8 @@
9294
'cyverse_allocation',
9395
'service',
9496
'core',
97+
'constance',
98+
'constance.backends.database'
9599
)
96100
SESSION_COOKIE_NAME = 'atmo_sessionid'
97101

atmosphere/settings/local.py.j2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Settings specific to the local deploy.
44
import os
55
import sys
66
import logging
7+
from collections import OrderedDict
78
from datetime import timedelta
89
from celery.schedules import crontab
910

@@ -500,6 +501,11 @@ TACC_API_PASS = ''
500501
TACC_API_URL = ''
501502
{% endif %}
502503

504+
CONSTANCE_CONFIG = OrderedDict([
505+
('ALLOCATION_OVERRIDES_NEVER_ENFORCE', ('', 'Never enforce on these allocation sources. Comma-separated strings.')),
506+
('ALLOCATION_OVERRIDES_ALWAYS_ENFORCE', ('', 'Stop all instances on these allocation sources (nuclear option)')),
507+
])
508+
503509
######
504510
# Atmosphere Plugin Settings
505511
######

cyverse_allocation/plugins/allocation_source.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import uuid
22

33
from django.conf import settings
4+
from constance import config as constance_config
45
from django.core.exceptions import ObjectDoesNotExist
56
from threepio import logger
67

@@ -49,9 +50,9 @@ def _get_enforcement_override(allocation_source):
4950
"""
5051
assert isinstance(allocation_source, AllocationSource)
5152
import core.plugins
52-
if allocation_source.name in getattr(settings, 'ALLOCATION_OVERRIDES_NEVER_ENFORCE', []):
53+
if allocation_source.name in getattr(constance_config, 'ALLOCATION_OVERRIDES_NEVER_ENFORCE', '').split(','):
5354
return core.plugins.EnforcementOverrideChoice.NEVER_ENFORCE
54-
if allocation_source.name in getattr(settings, 'ALLOCATION_OVERRIDES_ALWAYS_ENFORCE', []):
55+
if allocation_source.name in getattr(constance_config, 'ALLOCATION_OVERRIDES_ALWAYS_ENFORCE', '').split(','):
5556
return core.plugins.EnforcementOverrideChoice.ALWAYS_ENFORCE
5657
return core.plugins.EnforcementOverrideChoice.NO_OVERRIDE
5758

dev_requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ decorator==4.1.2 # via ipython, traitlets
4141
defusedxml==0.5.0
4242
deprecation==1.0.1
4343
django-celery-beat==1.0.1
44+
django-constance[database]==2.2.0
4445
django-cors-headers==2.1.0
4546
django-cyverse-auth==1.1.4
4647
django-debug-toolbar==1.8
4748
django-filter==1.0.4
4849
django-jenkins==0.110.0
4950
django-memoize==2.1.0
5051
django-nose==1.4.4
52+
django-picklefield==1.0.0
5153
django-redis-cache==1.7.1
5254
django-sslserver==0.20
5355
django==1.11.4

jetstream/plugins/allocation_source.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from django.conf import settings
1+
from constance import config as constance_config
22

33
from core.models import AllocationSource
44

@@ -44,9 +44,9 @@ def _get_enforcement_override(allocation_source):
4444
"""
4545
assert isinstance(allocation_source, AllocationSource)
4646
import core.plugins
47-
if allocation_source.name in getattr(settings, 'ALLOCATION_OVERRIDES_NEVER_ENFORCE', []):
47+
if allocation_source.name in getattr(constance_config, 'ALLOCATION_OVERRIDES_NEVER_ENFORCE', '').split(','):
4848
return core.plugins.EnforcementOverrideChoice.NEVER_ENFORCE
49-
if allocation_source.name in getattr(settings, 'ALLOCATION_OVERRIDES_ALWAYS_ENFORCE', []):
49+
if allocation_source.name in getattr(constance_config, 'ALLOCATION_OVERRIDES_ALWAYS_ENFORCE', '').split(','):
5050
return core.plugins.EnforcementOverrideChoice.ALWAYS_ENFORCE
5151
return core.plugins.EnforcementOverrideChoice.NO_OVERRIDE
5252

requirements.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ psycopg2
4141
python-ldap
4242
uWSGI
4343

44+
django-constance[database]
45+
4446
## ours
4547
chromogenic
4648
django-cyverse-auth

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ debtcollector==1.17.0 # via oslo.config, oslo.context, oslo.log, oslo.utils,
3131
defusedxml==0.5.0 # via djangorestframework-xml
3232
deprecation==1.0.1 # via openstacksdk
3333
django-celery-beat==1.0.1
34+
django-constance[database]==2.2.0
3435
django-cors-headers==2.1.0
3536
django-cyverse-auth==1.1.4
3637
django-filter==1.0.4
3738
django-memoize==2.1.0
39+
django-picklefield==1.0.0 # via django-constance
3840
django-redis-cache==1.7.1
3941
django-sslserver==0.20
4042
django==1.11.4

0 commit comments

Comments
 (0)