针对大项目的配置文件使用!

针对大项目的配置文件使用!

项目配置文件使用:
1,由于项目不完全是web项目,因此配置文件只是在 config.py 之中就不合适
2,全局配置有一个 ini 文件,并且指定了各个模块对应的配置文件所在的位置
导入配置文件!
import sys

from django.core.management import execute_from_command_line
from paste.deploy import loadapp


def main():
    # 指定全局配置文件!
    loadapp(
        'config:lico.ini#django',
        relative_to='/etc/lico',
    )
    execute_from_command_line(sys.argv)
全局配置文件!
[DEFAULT]
debug = false
# 指定了django 配置文件的位置!web 使用默认的配置文件!
django_settings_module = antilles_web.settings

# common
allow_hosts = *
domain = hpc.com

# database
db_engine = django.db.backends.postgresql_psycopg2
db_host = 127.0.0.1
db_port = 5432
db_name = lico

# influxdb
influx_host = 127.0.0.1
influx_port = 8086
influx_database = lico

# login
login_fail_max_chance = 3

# sharedir
share_dir = /home

# user
use_libuser = false
user_share_dir =

# folder
# 日志文件的位置!
log_dir = /var/log/lico
script_dir = /var/run/lico/core/scripts
download_dir = /var/run/lico/core/download
upload_dir = /var/run/lico/core/upload
lock_dir = /var/run/lico/core/lock

# ai
ai_src_root = %(share_dir)s/lico/ai
ai_container_root = %(ai_src_root)s/container
ai_topology_root = %(ai_src_root)s/topology
ai_monitor_max_worker = 25

# scheduler
scheduler_software = slurm
scheduler_queues_auto_get = true
scheduler_queues =

#slurm
slurm_user = slurm

# alarm agent
wechat_agent_url = http://127.0.0.1:18090
wechat_template_id = <wechat_template_id>
mail_agent_url = http://127.0.0.1:18091
sms_agent_url = http://127.0.0.1:18092


# nodes file
nodes_file = %(here)s/nodes.csv
auto_sync_nodes = true

# confluent
confluent_port = 4005

# requests
requests_timeout = 30

# ===== WSGI =====

[server:main]
use = egg:Paste#http

[composite:main]
use = egg:Paste#urlmap
/api = django
/download = download

# ===== Django =====

[app:django]
use = hpc+ai

[app:hpc+ai]
# hpc 与 ai 的配置文件位置!
use = config:paste.d/django.ini#hpc+ai

[app:hpc]
use = config:paste.d/django.ini#hpc

[app:ai]
use = config:paste.d/django.ini#ai

[app:download]
use = egg:Paste#static
document_root = %(download_dir)s

# ===== Logger =====
# 配置全局的日志文件!
[loggers]
keys = root,django,requests

[handlers]
keys = console

[formatters]
keys = verbose

# Loggers

[logger_root]
level = DEBUG
handlers = console

[logger_django]
level = INFO
handlers = console
qualname = django
propagate = 0

[logger_requests]
level = INFO
handlers = console
qualname = requests
propagate = 0

[logger_urllib3]
level = INFO
handlers = console
qualname = urllib3
propagate = 0

# Handlers

[handler_console]
class = StreamHandler
level = DEBUG
formatter = verbose
args = (sys.stdout,)

[formatter_verbose]
format=%(levelname)s %(asctime)s %(name)s Line:%(lineno)d %(processName)s %(threadName)s %(message)s
View Code
web配置文件!
[app:base]
use = call:antilles_web.factory:make_application

ALLOWED_HOSTS = ["${allow_hosts}"]

LOG_DIR = "${log_dir}"
SCRIPTS_DIR = "${script_dir}"
DOWNLOAD_DIR = "${download_dir}"
UPLOAD_DIR = "${upload_dir}"
LOCK_DIR = "${lock_dir}"

DATABASES = {
        "default": {
            "ENGINE"   : "${db_engine}",
            "HOST"     : "${db_host}",
            "NAME"     : "${db_name}",
            "USER"     : "${db_user}",
            "PASSWORD" : "${db_pass}"
        }
    }

DOMAIN = "${domain}"
SHARE_DIR = "${share_dir}"
USER_SHARE_DIR = [${user_share_dir}]

USE_LIBUSER = ${use_libuser}
USER_BACKEND = "libuser"
DEFAULT_BILL_GROUP = "default_bill_group"
DEFAULT_CREDITS = 100

MIN_GID = 1000
MIN_UID = 1000

LOGIN_FAIL_MAX_CHANCE = ${login_fail_max_chance}

SCHEDULER_SOFTWARE = "${scheduler_software}"
SCHEDULER_QUEUE_AUTO_GET = ${scheduler_queues_auto_get}
SCHEDULER_QUEUES = [${scheduler_queues}]

SLURM_USER = "${slurm_user}"

BROKER_URL = "amqp://127.0.0.1:5672/"

WECHAT_AGENT_URL = "${wechat_agent_url}"
WECHAT_TEMPLATE_ID = "${wechat_template_id}"
SMS_AGENT_URL = "${sms_agent_url}"
MAIL_AGENT_URL = "${mail_agent_url}"

CONFLUENT_USER = "${confluent_user}"
CONFLUENT_PASS = "${confluent_pass}"
CONFLUENT_PORT = ${confluent_port}

NODES_FILE = "${nodes_file}"
AUTO_SYNC_NODES = ${auto_sync_nodes}

REQUESTS_TIMEOUT = ${requests_timeout}

INFLUXDB = {
        "host": "${influx_host}",
        "port": ${influx_port},
        "username": "${influx_username}",
        "password": "${influx_password}",
        "database": "${influx_database}"
    }

[app:ai_base]
use = base

AI_SRC_ROOT = "${ai_src_root}"
AI_CONTAINER_ROOT = "${ai_container_root}"
AI_TOPOLOGY_ROOT = "${ai_topology_root}"
AI_MONITOR_MAX_WORKER = "${ai_monitor_max_worker}"

[app:hpc+ai]
use = ai_base

INSTALLED_APPS = [
        "django.contrib.auth",
        "django.contrib.contenttypes",
        "rest_framework",
        "antilles.common",
        "antilles.user",
        "antilles.ai",
        "antilles.logs",
        "antilles.optlog",
        "antilles.report",
        "antilles.alarm",
        "antilles.hpc",
        "antilles.cluster",
        "antilles.scheduler",
        "webconsole",
        "django_celery_results"
                 ]

[app:ai]
use = ai_base

INSTALLED_APPS = [
        "django.contrib.auth",
        "django.contrib.contenttypes",
        "rest_framework",
        "antilles.common",
        "antilles.user",
        "antilles.ai",
        "antilles.logs",
        "antilles.optlog",
        "antilles.report",
        "antilles.alarm",
        "antilles.cluster",
        "antilles.scheduler",
        "webconsole",
        "django_celery_results"
                 ]

[app:hpc]
use = base

INSTALLED_APPS = [
        "django.contrib.auth",
        "django.contrib.contenttypes",
        "rest_framework",
        "antilles.common",
        "antilles.user",
        "antilles.logs",
        "antilles.optlog",
        "antilles.report",
        "antilles.alarm",
        "antilles.hpc",
        "antilles.cluster",
        "antilles.scheduler",
        "webconsole",
        "django_celery_results"
                 ]
View Code

 

posted @ 2018-11-08 19:53  十七楼的羊  阅读(245)  评论(0编辑  收藏  举报