Skip to content

Commit

Permalink
Load in default plugins if there aren't any
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamgilbert committed Aug 11, 2015
1 parent 0e32607 commit 2e511a1
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
1 change: 0 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ ENV DOCKER_SAL_TZ Europe/London
ENV DOCKER_SAL_ADMINS Docker User, docker@localhost
ENV DOCKER_SAL_LANG en_GB
ENV DOCKER_SAL_DISPLAY_NAME Sal
ENV DOCKER_SAL_PLUGIN_ORDER Activity,Status,OperatingSystem,Uptime,Memory
ENV DOCKER_SAL_DEBUG false

RUN apt-get update && \
Expand Down
1 change: 0 additions & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Several options, such as the timezone and admin password are customizable using
* ``DOCKER_SAL_DISPLAY_NAME``: This sets the name that appears in the title bar of the window. Defaults to ``Sal``.
* ``DOCKER_SAL_TZ``: The desired [timezone](http://en.wikipedia.org/wiki/List_of_tz_database_time_zones). Defaults to ``Europe/London``.
* ``DOCKER_SAL_ADMINS``: The admin user's details. Defaults to ``Docker User, docker@localhost``.
* ``DOCKER_SAL_PLUGIN_ORDER``: The order plugins are displayed in. Defaults to ``Activity,Status,OperatingSystem,Uptime,Memory``.
* ``DOCKER_SAL_DEBUG``: Whether debug mode is enabled or not. Valid values are ``true`` and ``false``. Defaults to ``false``.

If you require more advanced settings, for example if you want to hide certain plugins from certain Business Units or if you have a plugin that needs settings, you can override ``settings.py`` with your own. A good starting place can be found on this image's [Github repository](https://github.com/salopensource/sal/blob/master/docker/settings.py).
Expand Down
2 changes: 1 addition & 1 deletion docker/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Django settings for sal project.
from system_settings import *
from settings_import import ADMINS, TIME_ZONE, LANGUAGE_CODE, ALLOWED_HOSTS, DISPLAY_NAME, PLUGIN_ORDER, DEBUG
from settings_import import ADMINS, TIME_ZONE, LANGUAGE_CODE, ALLOWED_HOSTS, DISPLAY_NAME, DEBUG
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
Expand Down
6 changes: 0 additions & 6 deletions docker/settings_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,3 @@
DISPLAY_NAME = getenv('DOCKER_SAL_DISPLAY_NAME')
else:
DISPLAY_NAME = 'Sal'

# The order plugins (if they're able to be shown on that particular page) will be displayed in. If not listed here, will be listed alphabetically after.
if getenv('DOCKER_SAL_PLUGIN_ORDER'):
PLUGIN_ORDER = getenv('DOCKER_SAL_PLUGIN_ORDER').split(',')
else:
PLUGIN_ORDER = ['Activity','Status', 'MunkiVersion','OperatingSystem','Uptime', 'Memory']
14 changes: 13 additions & 1 deletion server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@
from django.db.models import Max
import os

def loadDefaultPlugins():
# Are there any plugin objects? If not, add in the defaults
plugin_objects = Plugin.objects.all().count()
if plugin_objects == 0:
order = 0
PLUGIN_ORDER = ['Activity','Status','OperatingSystem', 'MunkiVersion', 'Uptime', 'Memory', 'DiskSpace', 'PendingAppleUpdates', 'Pending3rdPartyUpdates', 'PuppetStatus']
for item in PLUGIN_ORDER:
order = order + 1
plugin = Plugin(name=item, order=order)
plugin.save()

def reloadPluginsModel():
# Are there any plugin objects? If not, add in the defaults
plugin_objects = Plugin.objects.all().count()
if plugin_objects == 0:
order = 0
for item in settings.PLUGIN_ORDER:
PLUGIN_ORDER = ['Activity','Status','OperatingSystem', 'MunkiVersion', 'Uptime', 'Memory', 'DiskSpace', 'PendingAppleUpdates', 'Pending3rdPartyUpdates', 'PuppetStatus']
for item in PLUGIN_ORDER:
order = order + 1
plugin = Plugin(name=item, order=order)
plugin.save()
Expand Down
2 changes: 2 additions & 0 deletions server/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def index(request):
for group in business_unit.machinegroup_set.all():
machines = machines | group.machine_set.all()

# Load in the default plugins if needed
utils.loadDefaultPlugins()
# Build the manager
manager = PluginManager()
# Tell it the default place(s) where to find plugins
Expand Down

0 comments on commit 2e511a1

Please sign in to comment.