Add vfc-vnflcm log integration config
[vfc/gvnfm/vnflcm.git] / lcm / lcm / settings.py
1 # Copyright 2017 ZTE Corporation.
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 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import os
16 import sys
17
18 import redisco
19
20 from lcm.pub.config.config import REDIS_HOST, REDIS_PORT, REDIS_PASSWD
21 from lcm.pub.config.config import DB_NAME, DB_IP, DB_USER, DB_PASSWD, DB_PORT
22 from logging import config
23 from onaplogging import monkey
24 monkey.patch_all()
25
26 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
27 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
28
29 # Quick-start development settings - unsuitable for production
30 # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
31
32 # SECURITY WARNING: keep the secret key used in production secret!
33 SECRET_KEY = '3o-wney!99y)^h3v)0$j16l9=fdjxcb+a8g+q3tfbahcnu2b0o'
34
35 # SECURITY WARNING: don't run with debug turned on in production!
36 DEBUG = True
37
38 ALLOWED_HOSTS = ['*']
39
40 # Application definition
41
42 INSTALLED_APPS = [
43     'django.contrib.auth',
44     'django.contrib.contenttypes',
45     'django.contrib.sessions',
46     'django.contrib.messages',
47     'django.contrib.staticfiles',
48     'rest_framework',
49     'lcm.pub.database',
50     'lcm.samples',
51     'drf_yasg',
52 ]
53
54 MIDDLEWARE_CLASSES = [
55     'django.middleware.security.SecurityMiddleware',
56     'django.contrib.sessions.middleware.SessionMiddleware',
57     'django.middleware.common.CommonMiddleware',
58     'django.middleware.csrf.CsrfViewMiddleware',
59     'django.contrib.auth.middleware.AuthenticationMiddleware',
60     'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
61     'django.contrib.messages.middleware.MessageMiddleware',
62     'django.middleware.clickjacking.XFrameOptionsMiddleware',
63     'lcm.middleware.LogContextMiddleware',
64 ]
65
66 ROOT_URLCONF = 'lcm.urls'
67
68 WSGI_APPLICATION = 'lcm.wsgi.application'
69
70 REST_FRAMEWORK = {
71     'DEFAULT_RENDERER_CLASSES': (
72         'rest_framework.renderers.JSONRenderer',
73     ),
74
75     'DEFAULT_PARSER_CLASSES': (
76         'rest_framework.parsers.JSONParser',
77         'rest_framework.parsers.MultiPartParser',
78     )
79 }
80
81 # drf-yasg
82 TEMPLATES = [
83     {
84         'BACKEND': 'django.template.backends.django.DjangoTemplates',
85         'DIRS': [],
86         'APP_DIRS': True,
87         'OPTIONS': {
88             'context_processors': [
89                 'django.template.context_processors.debug',
90                 'django.template.context_processors.request',
91                 'django.contrib.auth.context_processors.auth',
92                 'django.contrib.messages.context_processors.messages',
93             ],
94         },
95     },
96 ]
97
98 SWAGGER_SETTINGS = {
99     'LOGIN_URL': '/admin/login',
100     'LOGOUT_URL': '/admin/logout',
101
102     'DEFAULT_INFO': 'lcm.swagger.urls.swagger_info'
103 }
104
105 DATABASES = {
106     'default': {
107         'ENGINE': 'django.db.backends.mysql',
108         'NAME': DB_NAME,
109         'HOST': DB_IP,
110         'PORT': DB_PORT,
111         'USER': DB_USER,
112         'PASSWORD': DB_PASSWD,
113     },
114 }
115
116 redisco.connection_setup(host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASSWD, db=0)
117 # CACHE_BACKEND = 'redis_cache.cache://%s@%s:%s' % (REDIS_PASSWD, REDIS_HOST, REDIS_PORT)
118
119 TIME_ZONE = 'UTC'
120
121 # Static files (CSS, JavaScript, Images)
122 # https://docs.djangoproject.com/en/1.6/howto/static-files/
123
124 STATIC_URL = '/static/'
125 #
126 # LOGGING = {
127 #     'version': 1,
128 #     'disable_existing_loggers': True,
129 #     'formatters': {
130 #         'standard': {
131 #             'format': '%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s',
132 #         },
133 #     },
134 #     'filters': {
135 #     },
136 #     'handlers': {
137 #         'lcm_handler': {
138 #             'level': 'DEBUG',
139 #             'class': 'logging.handlers.RotatingFileHandler',
140 #             'filename': os.path.join(BASE_DIR, 'logs/runtime_lcm.log'),
141 #             'formatter': 'standard',
142 #             'maxBytes': 1024 * 1024 * 50,
143 #             'backupCount': 5,
144 #         },
145 #     },
146 #
147 #     'loggers': {
148 #         'lcm': {
149 #             'handlers': ['lcm_handler'],
150 #             'level': 'DEBUG',
151 #             'propagate': False
152 #         },
153 #     }
154 # }
155 LOGGING_CONFIG = None
156 # yaml configuration of logging
157 LOGGING_FILE = os.path.join(BASE_DIR, 'lcm/log.yml')
158 config.yamlConfig(filepath=LOGGING_FILE, watchDog=True)
159
160
161 if 'test' in sys.argv:
162     from lcm.pub.config import config
163     config.REG_TO_MSB_WHEN_START = False
164
165     DATABASES = {}
166     DATABASES['default'] = {
167         'ENGINE': 'django.db.backends.sqlite3',
168         'NAME': ':memory:',
169     }
170     REST_FRAMEWORK = {}
171     import platform
172
173     if platform.system() == 'Linux':
174         TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner'
175         TEST_OUTPUT_VERBOSE = True
176         TEST_OUTPUT_DESCRIPTIONS = True
177         TEST_OUTPUT_DIR = 'test-reports'