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

Commit

Permalink
Problem: Need ability for admin to modify dynamic settings
Browse files Browse the repository at this point in the history
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
  • Loading branch information
julianpistorius committed Apr 24, 2018
1 parent 0ebcfc5 commit f97780a
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
### Fixed
- Quota updates concerning volumes would silently fail ([#611](https://github.com/cyverse/atmosphere/pull/611))

### Added
- Added dynamic settings feature ([#613](https://github.com/cyverse/atmosphere/pull/613))

## [v32-1](https://github.com/cyverse/atmosphere/compare/v32-0...v32-1) - 2018-04-17
### Added
- Support multiple hostnames for Atmosphere(1) server ([#602](https://github.com/cyverse/atmosphere/pull/602))
Expand Down
4 changes: 4 additions & 0 deletions atmosphere/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

# Django uses this one..
MANAGERS = ADMINS
CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend'
CONSTANCE_DATABASE_CACHE_BACKEND = 'default'

DATABASES = {
'default': {
Expand Down Expand Up @@ -92,6 +94,8 @@
'cyverse_allocation',
'service',
'core',
'constance',
'constance.backends.database'
)
SESSION_COOKIE_NAME = 'atmo_sessionid'

Expand Down
6 changes: 6 additions & 0 deletions atmosphere/settings/local.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Settings specific to the local deploy.
import os
import sys
import logging
from collections import OrderedDict
from datetime import timedelta
from celery.schedules import crontab

Expand Down Expand Up @@ -500,6 +501,11 @@ TACC_API_PASS = ''
TACC_API_URL = ''
{% endif %}

CONSTANCE_CONFIG = OrderedDict([
('ALLOCATION_OVERRIDES_NEVER_ENFORCE', ('', 'Never enforce on these allocation sources. Comma-separated strings.')),
('ALLOCATION_OVERRIDES_ALWAYS_ENFORCE', ('', 'Stop all instances on these allocation sources (nuclear option)')),
])

######
# Atmosphere Plugin Settings
######
Expand Down
5 changes: 3 additions & 2 deletions cyverse_allocation/plugins/allocation_source.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import uuid

from django.conf import settings
from constance import config as constance_config
from django.core.exceptions import ObjectDoesNotExist
from threepio import logger

Expand Down Expand Up @@ -49,9 +50,9 @@ def _get_enforcement_override(allocation_source):
"""
assert isinstance(allocation_source, AllocationSource)
import core.plugins
if allocation_source.name in getattr(settings, 'ALLOCATION_OVERRIDES_NEVER_ENFORCE', []):
if allocation_source.name in getattr(constance_config, 'ALLOCATION_OVERRIDES_NEVER_ENFORCE', '').split(','):
return core.plugins.EnforcementOverrideChoice.NEVER_ENFORCE
if allocation_source.name in getattr(settings, 'ALLOCATION_OVERRIDES_ALWAYS_ENFORCE', []):
if allocation_source.name in getattr(constance_config, 'ALLOCATION_OVERRIDES_ALWAYS_ENFORCE', '').split(','):
return core.plugins.EnforcementOverrideChoice.ALWAYS_ENFORCE
return core.plugins.EnforcementOverrideChoice.NO_OVERRIDE

Expand Down
2 changes: 2 additions & 0 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ decorator==4.1.2 # via ipython, traitlets
defusedxml==0.5.0
deprecation==1.0.1
django-celery-beat==1.0.1
django-constance[database]==2.2.0
django-cors-headers==2.1.0
django-cyverse-auth==1.1.4
django-debug-toolbar==1.8
django-filter==1.0.4
django-jenkins==0.110.0
django-memoize==2.1.0
django-nose==1.4.4
django-picklefield==1.0.0
django-redis-cache==1.7.1
django-sslserver==0.20
django==1.11.4
Expand Down
6 changes: 3 additions & 3 deletions jetstream/plugins/allocation_source.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf import settings
from constance import config as constance_config

from core.models import AllocationSource

Expand Down Expand Up @@ -44,9 +44,9 @@ def _get_enforcement_override(allocation_source):
"""
assert isinstance(allocation_source, AllocationSource)
import core.plugins
if allocation_source.name in getattr(settings, 'ALLOCATION_OVERRIDES_NEVER_ENFORCE', []):
if allocation_source.name in getattr(constance_config, 'ALLOCATION_OVERRIDES_NEVER_ENFORCE', '').split(','):
return core.plugins.EnforcementOverrideChoice.NEVER_ENFORCE
if allocation_source.name in getattr(settings, 'ALLOCATION_OVERRIDES_ALWAYS_ENFORCE', []):
if allocation_source.name in getattr(constance_config, 'ALLOCATION_OVERRIDES_ALWAYS_ENFORCE', '').split(','):
return core.plugins.EnforcementOverrideChoice.ALWAYS_ENFORCE
return core.plugins.EnforcementOverrideChoice.NO_OVERRIDE

Expand Down
2 changes: 2 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ psycopg2
python-ldap
uWSGI

django-constance[database]

## ours
chromogenic
django-cyverse-auth
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ debtcollector==1.17.0 # via oslo.config, oslo.context, oslo.log, oslo.utils,
defusedxml==0.5.0 # via djangorestframework-xml
deprecation==1.0.1 # via openstacksdk
django-celery-beat==1.0.1
django-constance[database]==2.2.0
django-cors-headers==2.1.0
django-cyverse-auth==1.1.4
django-filter==1.0.4
django-memoize==2.1.0
django-picklefield==1.0.0 # via django-constance
django-redis-cache==1.7.1
django-sslserver==0.20
django==1.11.4
Expand Down

0 comments on commit f97780a

Please sign in to comment.