Setup micro-service of multivim broker
[multicloud/framework.git] / multivimbroker / multivimbroker / settings.py
1 # Copyright (c) 2017 Wind River Systems, Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
6 #       http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12 import os
13 import sys
14
15 import redisco
16
17 from multivimbroker.pub.config.config import REDIS_HOST, REDIS_PORT, REDIS_PASSWD
18 from multivimbroker.pub.config.config import DB_NAME, DB_IP, DB_USER, DB_PASSWD, DB_PORT
19
20 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
21 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
22
23 # Quick-start development settings - unsuitable for production
24 # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
25
26 # SECURITY WARNING: keep the secret key used in production secret!
27 SECRET_KEY = '3o-wney!99y)^h3v)0$j16l9=fdjxcb+a8g+q3tfbahcnu2b0o'
28
29 # SECURITY WARNING: don't run with debug turned on in production!
30 DEBUG = True
31
32 ALLOWED_HOSTS = []
33
34 # Application definition
35
36 INSTALLED_APPS = [
37     'django.contrib.auth',
38     'django.contrib.contenttypes',
39     'django.contrib.sessions',
40     'django.contrib.messages',
41     'django.contrib.staticfiles',
42     'rest_framework',
43     'multivimbroker.pub.database',
44 ]
45
46 MIDDLEWARE_CLASSES = [
47     'django.middleware.security.SecurityMiddleware',
48     'django.contrib.sessions.middleware.SessionMiddleware',
49     'django.middleware.common.CommonMiddleware',
50     'django.middleware.csrf.CsrfViewMiddleware',
51     'django.contrib.auth.middleware.AuthenticationMiddleware',
52     'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
53     'django.contrib.messages.middleware.MessageMiddleware',
54     'django.middleware.clickjacking.XFrameOptionsMiddleware',
55 ]
56
57 ROOT_URLCONF = 'multivimbroker.urls'
58
59 WSGI_APPLICATION = 'multivimbroker.wsgi.application'
60
61 REST_FRAMEWORK = {
62     'DEFAULT_RENDERER_CLASSES': (
63         'rest_framework.renderers.JSONRenderer',
64     ),
65
66     'DEFAULT_PARSER_CLASSES': (
67         'rest_framework.parsers.JSONParser',
68         'rest_framework.parsers.MultiPartParser',
69         # 'rest_framework.parsers.FormParser',
70         # 'rest_framework.parsers.FileUploadParser',
71     )
72 }
73
74 DATABASES = {
75     'default': {
76         'ENGINE': 'django.db.backends.mysql',
77         'NAME': DB_NAME,
78         'HOST': DB_IP,
79         'PORT': DB_PORT,
80         'USER': DB_USER,
81         'PASSWORD': DB_PASSWD,
82     },
83 }
84
85 redisco.connection_setup(host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASSWD, db=0)
86 # CACHE_BACKEND = 'redis_cache.cache://%s@%s:%s' % (REDIS_PASSWD, REDIS_HOST, REDIS_PORT)
87
88 TIME_ZONE = 'UTC'
89
90 # Static files (CSS, JavaScript, Images)
91 # https://docs.djangoproject.com/en/1.6/howto/static-files/
92
93 STATIC_URL = '/static/'
94
95 LOGGING = {
96     'version': 1,
97     'disable_existing_loggers': True,
98     'formatters': {
99         'standard': {
100             'format': '%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s',
101         },
102     },
103     'filters': {
104     },
105     'handlers': {
106         'multivimbroker_handler': {
107             'level': 'DEBUG',
108             'class': 'logging.handlers.RotatingFileHandler',
109             'filename': os.path.join(BASE_DIR, 'logs/runtime_multivimbroker.log'),
110             'formatter': 'standard',
111             'maxBytes': 1024 * 1024 * 50,
112             'backupCount': 5,
113         },
114     },
115
116     'loggers': {
117         'multivimbroker': {
118             'handlers': ['multivimbroker_handler'],
119             'level': 'DEBUG',
120             'propagate': False
121         },
122     }
123 }
124
125 if 'test' in sys.argv:
126     from multivimbroker.pub.config import config
127     config.REG_TO_MSB_WHEN_START = False
128     DATABASES = {}
129     DATABASES['default'] = {
130         'ENGINE': 'django.db.backends.sqlite3',
131         'NAME': ':memory:',
132     }
133     REST_FRAMEWORK = {}
134     import platform
135
136     if platform.system() == 'Linux':
137         TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner'
138         TEST_OUTPUT_VERBOSE = True
139         TEST_OUTPUT_DESCRIPTIONS = True
140         TEST_OUTPUT_DIR = 'test-reports'