source: trunk/sara_cmt/sara_cmt/settings.py @ 14194

Last change on this file since 14194 was 14194, checked in by sil, 12 years ago

Merged branch 1.0 (until tag 1.0.0) back to trunk

File size: 9.1 KB
Line 
1#    This file is part of CMT, a Cluster Management Tool made at SARA.
2#    Copyright (C) 2012  Sil Westerveld
3#
4#    This program is free software; you can redistribute it and/or modify
5#    it under the terms of the GNU General Public License as published by
6#    the Free Software Foundation; either version 2 of the License, or
7#    (at your option) any later version.
8#
9#    This program is distributed in the hope that it will be useful,
10#    but WITHOUT ANY WARRANTY; without even the implied warranty of
11#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12#    GNU General Public License for more details.
13#
14#    You should have received a copy of the GNU General Public License
15#    along with this program; if not, write to the Free Software
16#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18import os, os.path, sys, ConfigParser, site, string, time
19
20from socket import gethostbyname_ex
21
22if site.sys.prefix in [ '/usr', '/' ]:
23    ETC_PREPEND = ''
24else:
25    ETC_PREPEND = site.sys.prefix
26
27# Path's customizable through virtualenv
28sample_configfile = '%s/etc/cmt/cmt.conf.sample' % ETC_PREPEND
29configfile = '%s/etc/cmt/cmt.conf' % ETC_PREPEND
30
31def count_configlines( filename ):
32
33        line_count      = 0
34        cfg_fp          = open( filename )
35
36        for line in cfg_fp.readlines():
37
38                line = line.strip()
39
40                if len( line ) == 0:
41                        continue
42
43                # RB: ConfigParser considers lines starting with # or ; as comments
44                if line[0] == '#' or line[0] == ';':
45                        continue
46
47                line_count += 1
48
49        cfg_fp.close()
50
51        return line_count
52
53if not os.path.exists( configfile ):
54
55        print 'Unable to find config file: %s' %configfile
56
57        if os.path.exists( sample_configfile ):
58
59                print ''
60                print 'Please modify the sample config file: %s to reflect your settings' %sample_configfile
61                print 'and then rename it to: %s' %configfile
62
63        else:
64
65                print ''
66                print 'Also no sample config file was found: %s' %sample_configfile
67                print 'Something is terribly wrong here ;)'
68
69        print ''
70        print 'Fatal: Giving up and exiting now..'
71
72        sys.exit(1)
73
74# We are still here: both configfile AND sample_configfile found
75if os.path.exists( sample_configfile ):
76
77        # Is the sample configfile newer?
78        if os.path.getmtime( sample_configfile ) > os.path.getmtime( configfile ):
79
80                # Well this is weird, but not fatal
81                print 'Warning: sample config file(%s) is newer than original config(%s)' %(sample_configfile, configfile)
82
83                # Does the sample config file contain more options?
84                if count_configlines( sample_configfile ) > count_configlines( configfile ):
85
86                        print 'Warning: sample config file contains MORE OPTIONS than original config!'
87                        print ''
88                        print 'This happens for example if you upgraded CMT and the new release incorporates new configuration options!'
89                        print ''
90                        print 'Please update your original config(%s) to incorporate the new config options from sample config(%s)' %( configfile, sample_configfile )
91                        print ''
92
93                # Give them some time to think about warnings and generally annoy them just enough to fix it
94                time.sleep(2)
95
96                # Moving right along; print empty line for cosmetic reasons
97                print ''
98
99config = ConfigParser.RawConfigParser()
100config.read( configfile )
101
102try:
103        DATABASE_USER           = config.get('database', 'USER')
104        DATABASE_PASSWORD       = config.get('database', 'PASSWORD')
105        DATABASE_HOST           = config.get('database', 'HOST')
106        DATABASE_ENGINE         = config.get('database', 'ENGINE')
107        DATABASE_NAME           = config.get('database', 'NAME')
108
109except (ConfigParser.NoOptionError, ConfigParser.NoSectionError), details:
110
111        print 'Config file error: %s' %str(details)
112        print ''
113        print 'Giving up and exiting now..'
114        sys.exit(1)
115
116try: # Optional
117        DATABASE_PORT = config.get('database', 'PORT')
118
119except ConfigParser.NoOptionError, details:
120
121        pass
122
123try: # Optional
124        TEST_DATABASE_NAME = config.get('database', 'TEST_NAME')
125
126except ConfigParser.NoOptionError, details:
127
128        pass
129
130try:
131        gethostbyname_ex( DATABASE_HOST )
132
133except socket.gaierror, details:
134
135        print 'Unable to resolve database host: %s' %DATABASE_HOST
136        print ''
137        print 'Giving up and exiting now..'
138        sys.exit(1)
139
140# Documentation of settings can be found on:
141#
142#   http://docs.djangoproject.com/en/dev/ref/settings/
143
144# Only set CLIENT_ONLY to False on the central CMT-server
145CLIENT_ONLY = True
146
147DEBUG = True
148
149ADMINS = (
150    ('Sil Westerveld', 'sil.westerveld@sara.nl'),
151    #('Your Name', 'your_email@domain.com'),
152)
153
154MANAGERS = ADMINS
155
156#####
157#
158# <AUTH AGAINST LDAP> (based on http://packages.python.org/django-auth-ldap/)
159#
160if not CLIENT_ONLY:
161    import ldap
162    from django_auth_ldap.config import LDAPSearch, PosixGroupType
163
164
165    # Baseline configuration.
166    AUTH_LDAP_SERVER_URI = "ldaps://ldap.cua.sara.nl"
167
168    # Set AUTH_LDAP_USER_DN_TEMPLATE to a template that will produce the
169    # authenticating user's DN directly. This template should have one
170    # placeholder, %(user)s.
171    AUTH_LDAP_USER_DN_TEMPLATE = 'uid=%(user)s,ou=Users,dc=hpcv,dc=sara,dc=nl'
172
173    # Set up the basic group parameters.
174    AUTH_LDAP_GROUP_SEARCH = LDAPSearch('ou=Groups,dc=hpcv,dc=sara,dc=nl',
175        ldap.SCOPE_SUBTREE, '(objectClass=posixGroup)',
176    )
177    AUTH_LDAP_GROUP_TYPE = PosixGroupType()
178
179    ## Only users in this group can log in.
180    AUTH_LDAP_REQUIRE_GROUP = 'cn=cmt,ou=Groups,dc=hpcv,dc=sara,dc=nl'
181
182    # Populate the Django user from the LDAP directory.
183    AUTH_LDAP_USER_ATTR_MAP = {
184        'first_name': 'givenName',
185        'last_name': 'sn',
186        'email': 'mail',
187    }
188
189    AUTH_LDAP_USER_FLAGS_BY_GROUP = {
190        'is_active': 'cn=cmt,ou=Groups,dc=hpcv,dc=sara,dc=nl',
191        'is_staff': 'cn=cmt,ou=Groups,dc=hpcv,dc=sara,dc=nl',
192        'is_superuser': 'cn=cmt,ou=Groups,dc=hpcv,dc=sara,dc=nl',
193    }
194
195    # This is the default, but I like to be explicit.
196    AUTH_LDAP_ALWAYS_UPDATE_USER = True
197
198    # Cache group memberships for an hour to minimize LDAP traffic
199    AUTH_LDAP_CACHE_GROUPS = True
200    AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600
201
202    # Keep ModelBackend around for per-user permissions and maybe a local
203    # superuser.
204    AUTHENTICATION_BACKENDS = (
205        'django_auth_ldap.backend.LDAPBackend',
206        'django.contrib.auth.backends.ModelBackend',
207    )
208#
209# </AUTH AGAINST LDAP>
210#
211#####
212
213
214
215
216
217# Local time zone for this installation. Choices can be found here:
218# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
219# although not all choices may be available on all operating systems.
220# If running in a Windows environment this must be set to the same as your
221# system time zone.
222TIME_ZONE = 'Europe/Amsterdam'
223
224# Language code for this installation. All choices can be found here:
225# http://www.i18nguy.com/unicode/language-identifiers.html
226LANGUAGE_CODE = 'en-us'
227
228SITE_ID = 1
229
230# If you set this to False, Django will make some optimizations so as not
231# to load the internationalization machinery.
232USE_I18N = True
233
234# Absolute path to the directory that holds media.
235# Example: "/home/media/media.lawrence.com/"
236MEDIA_ROOT = ''
237
238# URL that handles the media served from MEDIA_ROOT. Make sure to use a
239# trailing slash if there is a path component (optional in other cases).
240# Examples: "http://media.lawrence.com", "http://example.com/media/"
241MEDIA_URL = ''
242
243# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
244# trailing slash.
245# Examples: "http://foo.com/media/", "/media/".
246ADMIN_MEDIA_PREFIX = '/admin_media/'
247
248# Make this unique, and don't share it with anybody.
249SECRET_KEY = 'uygv6wrel4o2%x8s4dk2%i6=dp!2bt32$0ne-%_7&j=ez*u$1b'
250
251# List of callables that know how to import templates from various sources.
252TEMPLATE_LOADERS = (
253    'django.template.loaders.filesystem.load_template_source',
254    'django.template.loaders.app_directories.load_template_source',
255    #'django.template.loaders.eggs.load_template_source',
256)
257
258MIDDLEWARE_CLASSES = (
259    'django.middleware.common.CommonMiddleware',
260    'django.contrib.sessions.middleware.SessionMiddleware',
261    'django.contrib.auth.middleware.AuthenticationMiddleware',
262    'debug_toolbar.middleware.DebugToolbarMiddleware',
263)
264
265ROOT_URLCONF = 'sara_cmt.urls'
266
267# Templates for the CMT command line interface.
268# (thus, the templates for our configfiles, etc)
269#TODO: think about a (better) way to make this dynamic:
270#TODO: get this out of the settings.py, since it should be in the client config
271CMT_TEMPLATES_DIR = '%s/etc/cmt/templates' % ETC_PREPEND
272
273# Templates for the CMT web-frontend.
274TEMPLATE_DIRS = (
275    # Put strings here, like "/home/html/django_templates"
276    # or "C:/www/django/templates".
277    # Always use forward slashes, even on Windows.
278    # Don't forget to use absolute paths, not relative paths.
279    os.path.normpath(os.path.join(os.path.dirname(__file__), 'cluster/templates')),
280    CMT_TEMPLATES_DIR,
281)
282
283FIXTURE_DIRS = (
284    # A fixture is a collection of files that contain serialized contents of
285    # the database. (can be used for testing)
286    os.path.normpath(os.path.join(os.path.dirname(__file__), 'fixtures')),
287)
288
289
290INSTALLED_APPS = (
291    'django.contrib.auth',
292    'django.contrib.contenttypes',
293    'django.contrib.sessions',
294    'django.contrib.admin',
295    'django.contrib.databrowse',
296    'django.contrib.webdesign',
297    'sara_cmt.cluster',
298    'django_extensions',
299    'tagging',
300
301    # Only serverside:
302    #'debug_toolbar',
303    #'south',
304)
305
306# Append your IP to use the debug_toolbar
307INTERNAL_IPS = (
308    #'145.100.6.163', # saralt0115
309    '127.0.0.1',
310)
Note: See TracBrowser for help on using the repository browser.