2020-02-20 15:52:50 +00:00
|
|
|
"""
|
|
|
|
Django settings for uncloud project.
|
|
|
|
|
|
|
|
Generated by 'django-admin startproject' using Django 3.0.3.
|
|
|
|
|
|
|
|
For more information on this file, see
|
|
|
|
https://docs.djangoproject.com/en/3.0/topics/settings/
|
|
|
|
|
|
|
|
For the full list of settings and their values, see
|
|
|
|
https://docs.djangoproject.com/en/3.0/ref/settings/
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
2020-12-20 11:20:54 +00:00
|
|
|
import re
|
2020-02-22 10:49:00 +00:00
|
|
|
import ldap
|
|
|
|
|
2020-05-01 22:16:29 +00:00
|
|
|
from django.core.management.utils import get_random_secret_key
|
2020-02-25 18:23:39 +00:00
|
|
|
from django_auth_ldap.config import LDAPSearch, LDAPSearchUnion
|
2020-02-22 10:49:00 +00:00
|
|
|
|
2020-05-01 22:16:29 +00:00
|
|
|
|
|
|
|
LOGGING = {}
|
|
|
|
|
2020-02-20 15:52:50 +00:00
|
|
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
2020-05-01 22:16:29 +00:00
|
|
|
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
|
|
|
DATABASES = {
|
|
|
|
'default': {
|
|
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
|
|
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 15:52:50 +00:00
|
|
|
|
|
|
|
# Quick-start development settings - unsuitable for production
|
|
|
|
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
|
|
|
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
|
|
DEBUG = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Application definition
|
|
|
|
|
|
|
|
INSTALLED_APPS = [
|
|
|
|
'django.contrib.admin',
|
|
|
|
'django.contrib.auth',
|
|
|
|
'django.contrib.contenttypes',
|
|
|
|
'django.contrib.sessions',
|
|
|
|
'django.contrib.messages',
|
|
|
|
'django.contrib.staticfiles',
|
2020-03-17 12:30:48 +00:00
|
|
|
'django_extensions',
|
2020-02-21 09:41:22 +00:00
|
|
|
'rest_framework',
|
2020-03-22 19:55:11 +00:00
|
|
|
'uncloud',
|
2020-02-27 10:59:28 +00:00
|
|
|
'uncloud_pay',
|
2020-02-21 15:33:37 +00:00
|
|
|
'uncloud_auth',
|
2020-04-03 17:27:49 +00:00
|
|
|
'uncloud_net',
|
2020-02-28 13:48:01 +00:00
|
|
|
'uncloud_storage',
|
2020-02-25 19:53:12 +00:00
|
|
|
'uncloud_vm',
|
2020-04-13 09:39:49 +00:00
|
|
|
'uncloud_service',
|
2020-02-21 15:33:37 +00:00
|
|
|
'opennebula'
|
2020-02-20 15:52:50 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
MIDDLEWARE = [
|
|
|
|
'django.middleware.security.SecurityMiddleware',
|
|
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
|
|
|
'django.middleware.common.CommonMiddleware',
|
|
|
|
'django.middleware.csrf.CsrfViewMiddleware',
|
|
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
|
|
'django.contrib.messages.middleware.MessageMiddleware',
|
|
|
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
|
|
|
]
|
|
|
|
|
|
|
|
ROOT_URLCONF = 'uncloud.urls'
|
|
|
|
|
|
|
|
TEMPLATES = [
|
|
|
|
{
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
|
|
'DIRS': [],
|
|
|
|
'APP_DIRS': True,
|
|
|
|
'OPTIONS': {
|
|
|
|
'context_processors': [
|
|
|
|
'django.template.context_processors.debug',
|
|
|
|
'django.template.context_processors.request',
|
|
|
|
'django.contrib.auth.context_processors.auth',
|
|
|
|
'django.contrib.messages.context_processors.messages',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
WSGI_APPLICATION = 'uncloud.wsgi.application'
|
|
|
|
|
|
|
|
|
|
|
|
# Password validation
|
|
|
|
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
|
|
|
|
|
|
|
|
AUTH_PASSWORD_VALIDATORS = [
|
|
|
|
{
|
|
|
|
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2020-02-21 10:32:41 +00:00
|
|
|
################################################################################
|
|
|
|
# AUTH/LDAP
|
|
|
|
|
2020-05-01 22:16:29 +00:00
|
|
|
AUTH_LDAP_SERVER_URI = ""
|
|
|
|
AUTH_LDAP_BIND_DN = ""
|
|
|
|
AUTH_LDAP_BIND_PASSWORD = ""
|
|
|
|
AUTH_LDAP_USER_SEARCH = LDAPSearch("dc=example,dc=com",
|
|
|
|
ldap.SCOPE_SUBTREE,
|
|
|
|
"(uid=%(user)s)")
|
2020-02-21 10:32:41 +00:00
|
|
|
|
2020-02-23 15:52:30 +00:00
|
|
|
AUTH_LDAP_USER_ATTR_MAP = {
|
|
|
|
"first_name": "givenName",
|
|
|
|
"last_name": "sn",
|
|
|
|
"email": "mail"
|
|
|
|
}
|
2020-02-20 17:58:07 +00:00
|
|
|
|
2020-02-21 10:32:41 +00:00
|
|
|
################################################################################
|
|
|
|
# AUTH/Django
|
|
|
|
AUTHENTICATION_BACKENDS = [
|
|
|
|
"django_auth_ldap.backend.LDAPBackend",
|
|
|
|
"django.contrib.auth.backends.ModelBackend"
|
|
|
|
]
|
|
|
|
|
|
|
|
AUTH_USER_MODEL = 'uncloud_auth.User'
|
|
|
|
|
|
|
|
|
2020-02-20 17:58:07 +00:00
|
|
|
################################################################################
|
|
|
|
# AUTH/REST
|
|
|
|
REST_FRAMEWORK = {
|
|
|
|
'DEFAULT_AUTHENTICATION_CLASSES': [
|
2020-02-25 17:15:22 +00:00
|
|
|
'rest_framework.authentication.BasicAuthentication',
|
2020-02-20 17:58:07 +00:00
|
|
|
'rest_framework.authentication.SessionAuthentication',
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-20 15:52:50 +00:00
|
|
|
# Internationalization
|
|
|
|
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
|
|
|
|
|
|
|
LANGUAGE_CODE = 'en-us'
|
|
|
|
|
|
|
|
TIME_ZONE = 'UTC'
|
|
|
|
|
|
|
|
USE_I18N = True
|
|
|
|
|
|
|
|
USE_L10N = True
|
|
|
|
|
|
|
|
USE_TZ = True
|
|
|
|
|
|
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
|
|
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
|
|
|
STATIC_URL = '/static/'
|
2020-04-03 16:41:17 +00:00
|
|
|
STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static") ]
|
2020-05-01 22:16:29 +00:00
|
|
|
|
|
|
|
# XML-RPC interface of opennebula
|
|
|
|
OPENNEBULA_URL = 'https://opennebula.example.com:2634/RPC2'
|
|
|
|
|
|
|
|
# user:pass for accessing opennebula
|
|
|
|
OPENNEBULA_USER_PASS = 'user:password'
|
|
|
|
|
|
|
|
# Stripe (Credit Card payments)
|
|
|
|
STRIPE_KEY=""
|
|
|
|
STRIPE_PUBLIC_KEY=""
|
|
|
|
|
|
|
|
# The django secret key
|
|
|
|
SECRET_KEY=get_random_secret_key()
|
|
|
|
|
2020-05-02 17:15:48 +00:00
|
|
|
ALLOWED_HOSTS = []
|
2020-05-01 22:16:29 +00:00
|
|
|
|
2020-05-17 21:34:13 +00:00
|
|
|
# required for hardcopy / pdf rendering: https://github.com/loftylabs/django-hardcopy
|
|
|
|
CHROME_PATH = '/usr/bin/chromium-browser'
|
|
|
|
|
2020-10-08 17:54:04 +00:00
|
|
|
# Username that is created by default and owns the configuration objects
|
|
|
|
UNCLOUD_ADMIN_NAME = "uncloud-admin"
|
2020-05-17 21:34:13 +00:00
|
|
|
|
2020-12-09 19:22:33 +00:00
|
|
|
LOGIN_REDIRECT_URL = '/'
|
|
|
|
LOGOUT_REDIRECT_URL = '/'
|
|
|
|
|
2020-12-13 18:06:22 +00:00
|
|
|
# replace these in local_settings.py
|
|
|
|
AUTH_LDAP_SERVER_URI = "ldaps://ldap1.example.com,ldaps://ldap2.example.com"
|
|
|
|
AUTH_LDAP_BIND_DN="uid=django,ou=system,dc=example,dc=com"
|
|
|
|
AUTH_LDAP_BIND_PASSWORD="a very secure ldap password"
|
|
|
|
AUTH_LDAP_USER_SEARCH = LDAPSearch("dc=example,dc=com",
|
|
|
|
ldap.SCOPE_SUBTREE,
|
|
|
|
"(uid=%(user)s)")
|
|
|
|
|
|
|
|
# where to create customers
|
|
|
|
LDAP_CUSTOMER_DN="ou=customer,dc=example,dc=com"
|
|
|
|
|
2020-12-20 11:54:02 +00:00
|
|
|
# def route_task(name, args, kwargs, options, task=None, **kw):
|
|
|
|
# print(f"{name} - {args} - {kwargs}")
|
|
|
|
# # if name == 'myapp.tasks.compress_video':
|
|
|
|
# return {'queue': 'vpn1' }
|
|
|
|
# # 'exchange_type': 'topic',
|
|
|
|
# # 'routing_key': 'video.compress'}
|
2020-12-20 11:20:54 +00:00
|
|
|
|
|
|
|
|
2020-12-20 11:54:02 +00:00
|
|
|
# CELERY_TASK_ROUTES = (route_task,)
|
2020-12-13 18:50:36 +00:00
|
|
|
|
2020-12-20 11:20:54 +00:00
|
|
|
# CELERY_TASK_ROUTES = {
|
|
|
|
# '*': {
|
|
|
|
# 'queue': 'vpn1'
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
|
|
CELERY_BROKER_URL = 'redis://:uncloud.example.com:6379/0'
|
|
|
|
CELERY_RESULT_BACKEND = 'redis://:uncloud.example.com:6379/0'
|
|
|
|
|
2020-12-20 11:54:02 +00:00
|
|
|
CELERY_TASK_ROUTES = {
|
2020-12-20 12:00:36 +00:00
|
|
|
re.compile(r'.*.tasks.cdist.*'): { 'queue': 'cdist' } # cdist tasks go into cdist queue
|
2020-12-20 11:54:02 +00:00
|
|
|
}
|
2020-12-13 18:50:36 +00:00
|
|
|
|
test cleaning tasks in a task fails:
[2020-12-20 18:01:50,264: WARNING/ForkPoolWorker-7] Pruning UncloudTask object (571ffc76-8b40-4cb6-9658-87030834bc6c)...
[2020-12-20 18:01:50,265: ERROR/ForkPoolWorker-7] Task uncloud.tasks.cleanup_tasks[f9fb1480-f122-41c9-bec1-3d6d0f92a22e] raised unexpected: RuntimeError('Never call result.get() within a task!\nSee http://docs.celeryq.org/en/latest/userguide/tasks.html#task-synchronous-subtasks\n')
Traceback (most recent call last):
File "/home/nico/vcs/uncloud/venv/lib/python3.8/site-packages/celery/app/trace.py", line 405, in trace_task
R = retval = fun(*args, **kwargs)
File "/home/nico/vcs/uncloud/venv/lib/python3.8/site-packages/celery/app/trace.py", line 697, in __protected_call__
return self.run(*args, **kwargs)
File "/home/nico/vcs/uncloud/uncloud/tasks.py", line 13, in cleanup_tasks
print(res.get())
File "/home/nico/vcs/uncloud/venv/lib/python3.8/site-packages/celery/result.py", line 209, in get
assert_will_not_block()
File "/home/nico/vcs/uncloud/venv/lib/python3.8/site-packages/celery/result.py", line 37, in assert_will_not_block
raise RuntimeError(E_WOULDBLOCK)
RuntimeError: Never call result.get() within a task!
See http://docs.celeryq.org/en/latest/userguide/tasks.html#task-synchronous-subtasks
2020-12-20 18:01:37 +00:00
|
|
|
CELERY_BEAT_SCHEDULE = {
|
|
|
|
'cleanup_tasks': {
|
|
|
|
'task': 'uncloud.tasks.cleanup_tasks',
|
|
|
|
'schedule': 10
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-13 18:50:36 +00:00
|
|
|
# CELERY_TASK_CREATE_MISSING_QUEUES = False
|
2020-12-13 18:06:22 +00:00
|
|
|
|
2020-05-01 22:16:29 +00:00
|
|
|
# Overwrite settings with local settings, if existing
|
|
|
|
try:
|
|
|
|
from uncloud.local_settings import *
|
|
|
|
except (ModuleNotFoundError, ImportError):
|
|
|
|
pass
|