/
settings.py
445 lines (380 loc) · 14.7 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
"""
Copyright (c) 2012 RockStor, Inc. <http://rockstor.com>
This file is part of RockStor.
RockStor is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.
RockStor is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
# Django settings for Rockstor project.
import os
import subprocess, distro
from huey import SqliteHuey
DEBUG = False
ALLOWED_HOSTS = [ '*', ]
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'storageadmin', # Or path to database file if using sqlite3.
'USER': 'rocky', # Not used with sqlite3.
'PASSWORD': 'rocky', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
},
'smart_manager': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'smartdb',
'USER': 'rocky',
'PASSWORD': 'rocky',
'HOST': '',
'PORT': '',
},
}
DATABASE_ROUTERS = ['smart_manager.db_router.SmartManagerDBRouter',]
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'Europe/London'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = 'static'
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = '/media/'
# Establish BASE_DIR from ourselves (./src/rockstor/settings.py)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# print "BASE_DIR={}".format(BASE_DIR) # "/opt/rockstor" via 'django-admin runserver'
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, 'static')
# Absolute filesystem path where config backups are stored by default
DEFAULT_CB_DIR = os.path.join(MEDIA_ROOT, 'config-backups')
# Additional locations of static files
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "jslibs"),
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.FileSystemFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'odk7(t)1y$ls)euj3$2xs7e^i=a9b&xtf&z=-2bz$687&^q0+3'
# New in Django 1.8 to cover all prior TEMPLATE_* settings.
# https://docs.djangoproject.com/en/1.11/ref/templates/upgrading/
# "All existing template related settings were deprecated."
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# insert your TEMPLATE_DIRS here
'{}/src/rockstor/storageadmin/templates/storageadmin'.format(BASE_DIR),
'{}/src/rockstor/templates/admin'.format(BASE_DIR),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request',
],
},
},
]
MIDDLEWARE_CLASSES = (
# New in 1.8, 1.11 newly sets Content-Length header.
# 'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'storageadmin.middleware.ProdExceptionMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
# Relates to django.middleware.common.CommonMiddleware
# https://docs.djangoproject.com/en/3.2/ref/middleware/#module-django.middleware.common
# Default changed to True between 1.8 and 1.11, breaking may POST urls we have in play.
# APPEND_SLASH = False
ROOT_URLCONF = 'urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'wsgi.application'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'storageadmin',
'pipeline',
'rest_framework',
'smart_manager',
'oauth2_provider',
'huey.contrib.djhuey',
)
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
# Have django-pipeline collate storageadmin js/jst files into one storageadmin.js file
# which is then referenced in setup.html and base.html templates.
PIPELINE = {
'DISABLE_WRAPPER': True,
'JS_COMPRESSOR': None,
'CSS_COMPRESSOR': None,
'TEMPLATE_FUNC': 'Handlebars.compile',
'JAVASCRIPT': {
'storageadmin': {
'source_filenames': (
'storageadmin/js/license.js',
'storageadmin/js/templates/**/*.jst',
'storageadmin/js/templates/**/**/*.jst',
'storageadmin/js/socket_listen.js',
'storageadmin/js/rockstor.js',
'storageadmin/js/rockstor_widgets.js',
'storageadmin/js/rockstor_logger.js',
'storageadmin/js/paginated_collection.js',
'storageadmin/js/router.js',
'storageadmin/js/graph.js',
'storageadmin/js/d3.slider2.js',
'storageadmin/js/models/models.js',
'storageadmin/js/views/common/*.js',
'storageadmin/js/views/*.js',
'storageadmin/js/views/pool/**/*.js',
'storageadmin/js/views/dashboard/*.js',
),
'output_filename': 'storageadmin/js/storageadmin.js'
},
}
}
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOG_LEVEL = 'DEBUG' if DEBUG else 'INFO'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'formatters': {
'standard': {
'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt': "%d/%b/%Y %H:%M:%S"
},
},
'handlers': {
'mail_admins': {
'level': 'DEBUG',
#'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'file': {
'level': LOG_LEVEL,
'class': 'logging.handlers.RotatingFileHandler',
'filename': '{}/var/log/rockstor.log'.format(BASE_DIR),
'maxBytes': 1000000,
'backupCount': 3,
'formatter': 'standard',
},
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
'storageadmin': {
'handlers': ['file'],
'level': LOG_LEVEL,
'propagate': True,
},
'smart_manager': {
'handlers': ['file'],
'level': LOG_LEVEL,
'propagate': True,
},
'system': {
'handlers': ['file'],
'level': LOG_LEVEL,
'propagate': True,
},
'scripts': {
'handlers': ['file'],
'level': LOG_LEVEL,
'propagate': True,
},
'fs': {
'handlers': ['file'],
'level': LOG_LEVEL,
'propagate': True,
},
}
}
MNT_PT = '/mnt2/'
NFS_EXPORT_ROOT = '/export/'
SFTP_MNT_ROOT = '/mnt3/'
# System volume label when no btrfs volume label is set as per default openSUSE
# install: ie 'btrfs fi show' gives 'Label: none'
SYS_VOL_LABEL = 'ROOT'
TAP_DIR = '{}/src/rockstor/smart_manager/taplib'.format(BASE_DIR)
TAP_SERVER = ('127.0.0.1', 10000)
MAX_TAP_WORKERS = 10
SPROBE_SINK = ('127.0.0.1', 10001)
SUPPORT = {
'email': 'suman@rockstor.com',
'log_loc': '{}/var/log'.format(BASE_DIR),
}
"""
Maximum number of seconds to keep data collected by smart probes. The logic
behind this needs to evolve quite a bit.
"""
PROBE_DATA_INTERVAL = 600
"""
Minimum share size allowed is 100KB. This is purely arbitrary. 4K is what is
strictly required by btrfs. Similarly the maximum is 2^64 bytes which is more than
enough for all practical purposes and also is the max allowed in btrfs.
"""
MIN_SHARE_SIZE = 100
MAX_SHARE_SIZE = 18014398509481984L
START_UID = 5000
END_UID = 6000
VALID_SHELLS = ('{}/bin/rcli'.format(BASE_DIR), '/bin/bash', '/sbin/nologin',)
SCHEDULER = ('127.0.0.1', 10001)
REPLICATION = {
'ipc_socket': '/var/run/replication.sock',
'max_send_attempts': 10,
'max_snap_retain': 2,
'listener_port': 10002,
}
SHARE_REGEX = r'[A-Za-z0-9_.-]+'
POOL_REGEX = SHARE_REGEX
USERNAME_REGEX = r'[A-Za-z][-a-zA-Z0-9_]*$'
ROOT_DIR = BASE_DIR + "/"
#things get purged when they are > MAX_TS_RECORDS x MAX_TS_MULTIPLIER of if the service just
#starts and they are > MAX_TS_RECORDS.
MAX_TS_RECORDS = 40000
MAX_TS_MULTIPLIER = 3
#various system binaries used by lower level code.
COMMANDS = {
'ntpdate': '/usr/sbin/ntpdate',
'systemctl': '/usr/bin/systemctl',
}
SYSCONFIG = {
'ntp': '/etc/ntp.conf',
}
SOUTH_TESTS_MIGRATE = False
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework_custom.custom_pagination.CustomPagination',
'TEST_REQUEST_DEFAULT_FORMAT': 'json',
'PAGE_SIZE': 15,
'MAX_LIMIT': 10000,
}
CONFROOT = '{}/conf'.format(BASE_DIR)
CERTDIR = '{}/certs'.format(BASE_DIR)
COMPRESSION_TYPES = ('lzo', 'zlib', 'no',)
SNAP_TS_FORMAT = '%Y%m%d%H%M'
MODEL_DEFS = {
'pqgroup': '-1/-1',
}
OAUTH_INTERNAL_APP = 'cliapp'
# Header string to separate auto config options from rest of config file.
# this could be generalized across all Rockstor config files, problems during
# upgrades though
NUT_HEADER = '###BEGIN: Rockstor NUT Config. DO NOT EDIT BELOW THIS LINE###'
# The ip address for the LISTEN directive in upsd.conf when in netserver mode
# when set to 0.0.0.0 it will accept connections from any machine.
# default port is 3493
# Note this might later be tied into multi lan configs ie ups monitoring on
# admin interface for example.
NUT_LISTEN_ON_IP = '0.0.0.0'
# The command that the root part of upsmon uses to shutdown the system.
NUT_SYSTEM_SHUTDOWNCMD = '/sbin/shutdown -h +0'
# Shell In A Box base settings
if distro.id() == 'rockstor':
SHELLINABOX = {
'user': 'shellinabox',
'group': 'shellinabox',
'port': '4200',
'certs': '/var/lib/shellinabox'
}
else:
SHELLINABOX = {
'user': 'shellinabox',
'group': 'shellinabox',
'port': '4200',
'certs': '/etc/shellinabox/certs'
}
UPDATE_CHANNELS = {
'stable': {
'name': 'Stable',
'description': 'Subscription channel for stable updates',
'url': 'updates.rockstor.com:8999/rockstor-stable',
},
'testing': {
'name': 'Testing',
'description': 'Subscription channel for testing updates',
'url': 'updates.rockstor.com:8999/rockstor-testing',
},
}
HUEY = SqliteHuey(filename='{}/rockstor-tasks-huey.db'.format(BASE_DIR))
TASK_SCHEDULER = {
'max_log': 100 #max number of task log entries to keep
}
OAUTH2_PROVIDER_APPLICATION_MODEL = 'oauth2_provider.Application'
# Setup OS specific command paths via 'which cmd' calls
# N.B. this method will not work with an alias, ie in CentOS
# which ls
# alias ls='ls --color=auto'
# /usr/bin/ls
# The following have been tested in CentOS, openSUSE Leap15, and Tumbleweed
UDEVADM = subprocess.check_output(["which", "udevadm"]).rstrip()
SHUTDOWN = subprocess.check_output(["which", "shutdown"]).rstrip()
# Establish our OS base id, name, and version:
# Use id for code path decisions. Others are for Web-UI display purposes.
# Examples given are for CentOS Rockstor variant, Leap 15, and Tumblweed.
OS_DISTRO_ID = distro.id() # rockstor, opensuse-leap/opensuse, opensuse-tumbleweed
OS_DISTRO_NAME = distro.name() # Rockstor, openSUSE Leap, openSUSE Tumbleweed
# Note that the following will capture the build os version.
# For live updates (running system) we call distro.version() directly in code.
OS_DISTRO_VERSION = distro.version() # 3, 15.0 ,20181107