Revision 8d76ded8
[#1510] Chargement plus générique de l'application
Rend plus générique le chargement des IHMs :
- Le dossier de surcharge (public/) est pris à partir de l'emplacement
du fichier settings.ini plutôt que hard-codé.
- Idem pour le fichier app_cfg.py.
Ces modifications permettent d'héberger plusieurs instances de VigiMap
conjointement sur la même machine (par exemple, pour PreludeMap).
Change-Id: I251a7374a0930244ea3aad1f73d2204d63bd27fa
Refs: #1510.
Reviewed-on: https://vigilo-dev.si.c-s.fr/review/1924
Tested-by: Build system <qa@vigilo-dev.si.c-s.fr>
Reviewed-by: Francois POIROTTE <francois.poirotte@c-s.fr>
MANIFEST.in | ||
---|---|---|
13 | 13 |
include *.ini |
14 | 14 |
include jsl.cfg |
15 | 15 |
include babeljs.py |
16 |
include app_cfg.py |
Makefile | ||
---|---|---|
41 | 41 |
mkdir -p $(DESTDIR)$(LOCALSTATEDIR)/log/vigilo/$(NAME) |
42 | 42 |
[ `id -u` -ne 0 ] || chown $(HTTPD_USER): $(DESTDIR)$(LOCALSTATEDIR)/log/vigilo/$(NAME) |
43 | 43 |
install -m 644 -p -D deployment/logrotate.conf $(DESTDIR)/etc/logrotate.d/$(PKGNAME) |
44 |
# Déplacement du app_cfg.py |
|
45 |
mv $(DESTDIR)`grep '$(NAME)/config/app_cfg.py$$' INSTALLED_FILES` $(DESTDIR)$(SYSCONFDIR)/vigilo/$(NAME)/ |
|
46 |
ln -s $(SYSCONFDIR)/vigilo/$(NAME)/app_cfg.py $(DESTDIR)`grep '$(NAME)/config/app_cfg.py$$' INSTALLED_FILES` |
|
47 |
echo $(SYSCONFDIR)/vigilo/$(NAME)/app_cfg.py >> INSTALLED_FILES |
|
44 |
# Installation du app_cfg.py |
|
45 |
install -m 644 -p app_cfg.py $(DESTDIR)$(SYSCONFDIR)/vigilo/$(NAME)/ |
|
48 | 46 |
# Cache |
49 | 47 |
mkdir -p $(DESTDIR)$(LOCALSTATEDIR)/cache/vigilo/sessions |
50 | 48 |
chmod 750 $(DESTDIR)$(LOCALSTATEDIR)/cache/vigilo/sessions |
app_cfg.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# vim: set fileencoding=utf-8 sw=4 ts=4 et : |
|
3 |
# Copyright (C) 2011-2015 CS-SI |
|
4 |
# License: GNU GPL v2 <http://www.gnu.org/licenses/gpl-2.0.html> |
|
5 |
|
|
6 |
""" |
|
7 |
Global configuration file for TG2-specific settings in vigigraph. |
|
8 |
|
|
9 |
This file complements development/deployment.ini. |
|
10 |
|
|
11 |
Please note that **all the argument values are strings**. If you want to |
|
12 |
convert them into boolean, for example, you should use the |
|
13 |
:func:`paste.deploy.converters.asbool` function, as in:: |
|
14 |
|
|
15 |
from paste.deploy.converters import asbool |
|
16 |
setting = asbool(global_conf.get('the_setting')) |
|
17 |
|
|
18 |
""" |
|
19 |
|
|
20 |
|
|
21 |
import vigigraph |
|
22 |
from vigilo.turbogears import VigiloAppConfig |
|
23 |
from vigigraph.lib import app_globals, helpers # pylint: disable-msg=W0611 |
|
24 |
# W0611: Unused import: imports nécessaires pour le fonctionnement |
|
25 |
|
|
26 |
base_config = VigiloAppConfig('VigiGraph') |
|
27 |
base_config.package = vigigraph |
|
28 |
|
|
29 |
base_config["external_links"] = [ |
|
30 |
{ |
|
31 |
'label': 'Nagios page', |
|
32 |
'image': 'images/nagios-16.png', |
|
33 |
'tooltip': 'Display Nagios page for the selected host', |
|
34 |
'uri': 'nagios/{host}/cgi-bin/status.cgi?host={host}&style=detail&supNav=1', |
|
35 |
'sameWindow': True, |
|
36 |
}, |
|
37 |
{ |
|
38 |
'label': 'Metrology page', |
|
39 |
'image': 'images/preferences-system-windows.png', |
|
40 |
'tooltip': 'Display a page with all the graphs for the selected host', |
|
41 |
'uri': 'rpc/fullHostPage?host={host}', |
|
42 |
'sameWindow': True, |
|
43 |
}, |
|
44 |
] |
|
45 |
|
|
46 |
# Extensions (Entreprise ou spécifique projet) |
|
47 |
base_config["extensions"] = () |
vigigraph/config/app_cfg.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# vim: set fileencoding=utf-8 sw=4 ts=4 et : |
|
3 |
# Copyright (C) 2011-2015 CS-SI |
|
4 |
# License: GNU GPL v2 <http://www.gnu.org/licenses/gpl-2.0.html> |
|
5 |
|
|
6 |
""" |
|
7 |
Global configuration file for TG2-specific settings in vigigraph. |
|
8 |
|
|
9 |
This file complements development/deployment.ini. |
|
10 |
|
|
11 |
Please note that **all the argument values are strings**. If you want to |
|
12 |
convert them into boolean, for example, you should use the |
|
13 |
:func:`paste.deploy.converters.asbool` function, as in:: |
|
14 |
|
|
15 |
from paste.deploy.converters import asbool |
|
16 |
setting = asbool(global_conf.get('the_setting')) |
|
17 |
|
|
18 |
""" |
|
19 |
|
|
20 |
|
|
21 |
import vigigraph |
|
22 |
from vigilo.turbogears import VigiloAppConfig |
|
23 |
from vigigraph.lib import app_globals, helpers # pylint: disable-msg=W0611 |
|
24 |
# W0611: Unused import: imports nécessaires pour le fonctionnement |
|
25 |
|
|
26 |
base_config = VigiloAppConfig('VigiGraph') |
|
27 |
base_config.package = vigigraph |
|
28 |
|
|
29 |
base_config["external_links"] = [ |
|
30 |
{ |
|
31 |
'label': 'Nagios page', |
|
32 |
'image': 'images/nagios-16.png', |
|
33 |
'tooltip': 'Display Nagios page for the selected host', |
|
34 |
'uri': 'nagios/{host}/cgi-bin/status.cgi?host={host}&style=detail&supNav=1', |
|
35 |
'sameWindow': True, |
|
36 |
}, |
|
37 |
{ |
|
38 |
'label': 'Metrology page', |
|
39 |
'image': 'images/preferences-system-windows.png', |
|
40 |
'tooltip': 'Display a page with all the graphs for the selected host', |
|
41 |
'uri': 'rpc/fullHostPage?host={host}', |
|
42 |
'sameWindow': True, |
|
43 |
}, |
|
44 |
] |
|
45 |
|
|
46 |
# Extensions (Entreprise ou spécifique projet) |
|
47 |
base_config["extensions"] = () |
vigigraph/config/deployment.ini_tmpl | ||
---|---|---|
1 |
# |
|
2 |
# vigigraph - TurboGears configuration |
|
3 |
# |
|
4 |
# The %(here)s variable will be replaced with the parent directory of this file |
|
5 |
# |
|
6 |
# Copyright (C) 2006-2011 CS-SI |
|
7 |
# License: GNU GPL v2 <http://www.gnu.org/licenses/gpl-2.0.html> |
|
8 |
|
|
9 |
[DEFAULT] |
|
10 |
# WARGING == If debug is not set to false, you'll get the interactive |
|
11 |
# debugger on production, which is a huge security hole. |
|
12 |
|
|
13 |
debug = false |
|
14 |
email_to = you@yourdomain.com |
|
15 |
smtp_server = localhost |
|
16 |
error_email_from = paste@localhost |
|
17 |
|
|
18 |
[server:main] |
|
19 |
use = egg:Paste#http |
|
20 |
host = 0.0.0.0 |
|
21 |
port = 8080 |
|
22 |
|
|
23 |
[app:main] |
|
24 |
use = egg:vigigraph |
|
25 |
full_stack = true |
|
26 |
cache_dir = %(here)s/data |
|
27 |
beaker.session.key = vigigraph |
|
28 |
beaker.session.secret = ${app_instance_secret} |
|
29 |
app_instance_uuid = ${app_instance_uuid} |
|
30 |
|
|
31 |
# If you'd like to fine-tune the individual locations of the cache data dirs |
|
32 |
# for the Cache data, or the Session saves, un-comment the desired settings |
|
33 |
# here: |
|
34 |
#beaker.cache.data_dir = %(here)s/data/cache |
|
35 |
#beaker.session.data_dir = %(here)s/data/sessions |
|
36 |
# Specify the database for SQLAlchemy to use via |
|
37 |
# turbogears.database |
|
38 |
# %(here) may include a ':' character on Windows environments; this can |
|
39 |
# invalidate the URI when specifying a SQLite db via path name |
|
40 |
sqlalchemy.url = sqlite:///%(here)s/somedb.db |
|
41 |
sqlalchemy.echo = False |
|
42 |
|
|
43 |
# WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* |
|
44 |
# Debug mode will enable the interactive debugging tool, allowing ANYONE to |
|
45 |
# execute malicious code after an exception is raised. |
|
46 |
#set debug = false |
|
47 |
|
|
48 |
# Logging configuration |
|
49 |
# Add additional loggers, handlers, formatters here |
|
50 |
# Uses python's logging config file format |
|
51 |
# http://docs.python.org/lib/logging-config-fileformat.html |
|
52 |
|
|
53 |
[loggers] |
|
54 |
keys = root, vigigraph, sqlalchemy, auth |
|
55 |
|
|
56 |
[handlers] |
|
57 |
keys = console |
|
58 |
|
|
59 |
[formatters] |
|
60 |
keys = generic |
|
61 |
|
|
62 |
# If you create additional loggers, add them as a key to [loggers] |
|
63 |
[logger_root] |
|
64 |
level = INFO |
|
65 |
handlers = console |
|
66 |
|
|
67 |
[logger_vigigraph] |
|
68 |
level = INFO |
|
69 |
handlers = |
|
70 |
qualname = vigigraph |
|
71 |
|
|
72 |
[logger_sqlalchemy] |
|
73 |
level = WARN |
|
74 |
handlers = |
|
75 |
qualname = sqlalchemy.engine |
|
76 |
# "level = INFO" logs SQL queries. |
|
77 |
# "level = DEBUG" logs SQL queries and results. |
|
78 |
# "level = WARN" logs neither. (Recommended for production systems.) |
|
79 |
|
|
80 |
|
|
81 |
# A logger for authentication, identification and authorization -- this is |
|
82 |
# repoze.who and repoze.what: |
|
83 |
[logger_auth] |
|
84 |
level = WARN |
|
85 |
handlers = |
|
86 |
qualname = auth |
|
87 |
|
|
88 |
# If you create additional handlers, add them as a key to [handlers] |
|
89 |
[handler_console] |
|
90 |
class = StreamHandler |
|
91 |
args = (sys.stderr,) |
|
92 |
level = NOTSET |
|
93 |
formatter = generic |
|
94 |
|
|
95 |
# If you create additional formatters, add them as a key to [formatters] |
|
96 |
[formatter_generic] |
|
97 |
format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s |
|
98 |
datefmt = %H:%M:%S |
vigigraph/config/environment.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Copyright (C) 2011-2015 CS-SI |
|
3 |
# License: GNU GPL v2 <http://www.gnu.org/licenses/gpl-2.0.html> |
|
4 |
|
|
5 |
"""WSGI environment setup for vigigraph.""" |
|
6 |
|
|
7 |
from vigigraph.config.app_cfg import base_config |
|
8 |
|
|
9 |
__all__ = ['load_environment'] |
|
10 |
|
|
11 |
#Use base_config to setup the environment loader function |
|
12 |
load_environment = base_config.make_load_environment() |
vigigraph/config/middleware.py | ||
---|---|---|
5 | 5 |
|
6 | 6 |
"""WSGI middleware initialization for the vigigraph application.""" |
7 | 7 |
|
8 |
from vigigraph.config.app_cfg import base_config |
|
9 |
from vigigraph.config.environment import load_environment |
|
10 |
|
|
8 |
import imp |
|
9 |
import os.path |
|
11 | 10 |
from pkg_resources import resource_filename, working_set |
12 | 11 |
from paste.cascade import Cascade |
13 | 12 |
from paste.urlparser import StaticURLParser |
... | ... | |
15 | 14 |
|
16 | 15 |
__all__ = ['make_app'] |
17 | 16 |
|
18 |
# Use base_config to setup the necessary PasteDeploy application factory. |
|
19 |
# make_base_app will wrap the TG2 app with all the middleware it needs. |
|
20 |
make_base_app = base_config.setup_tg_wsgi_app(load_environment) |
|
21 |
|
|
22 | 17 |
|
23 | 18 |
def make_app(global_conf, full_stack=True, **app_conf): |
24 | 19 |
""" |
... | ... | |
38 | 33 |
@return: The vigigraph application with all the relevant middleware |
39 | 34 |
loaded. |
40 | 35 |
""" |
41 |
app = make_base_app(global_conf, full_stack=full_stack, **app_conf) |
|
36 |
# Charge le fichier "app_cfg.py" se trouvant aux côtés de "settings.ini". |
|
37 |
mod_info = imp.find_module('app_cfg', [ global_conf['here'] ]) |
|
38 |
app_cfg = imp.load_module('vigigraph.config.app_cfg', *mod_info) |
|
39 |
base_config = app_cfg.base_config |
|
40 |
|
|
41 |
# Initialisation de l'application et de son environnement d'exécution. |
|
42 |
load_environment = base_config.make_load_environment() |
|
43 |
make_base_app = base_config.setup_tg_wsgi_app(load_environment) |
|
44 |
app = make_base_app(global_conf, full_stack=True, **app_conf) |
|
42 | 45 |
|
43 | 46 |
max_age = app_conf.get("cache_max_age") |
44 | 47 |
try: |
... | ... | |
46 | 49 |
except (ValueError, TypeError): |
47 | 50 |
max_age = None |
48 | 51 |
|
49 |
# Personalisation des fichiers statiques via /etc/vigilo/vigigraph/public/. |
|
50 |
custom_static = StaticURLParser('/etc/vigilo/vigigraph/public/', |
|
52 |
# Personalisation des fichiers statiques via un dossier public/ |
|
53 |
# dans le répertoire contenant le fichier settings.ini chargé. |
|
54 |
custom_static = StaticURLParser(os.path.join(global_conf['here'], 'public'), |
|
51 | 55 |
cache_max_age=max_age) |
52 | 56 |
|
53 | 57 |
# On définit 2 middlewares pour fichiers statiques qui cherchent |
vigigraph/websetup.py | ||
---|---|---|
7 | 7 |
# pylint: disable-msg=W0613 |
8 | 8 |
# W0613: Unused argument |
9 | 9 |
|
10 |
import imp |
|
11 |
|
|
10 | 12 |
__all__ = ['setup_app', 'populate_db'] |
11 | 13 |
|
12 | 14 |
def setup_app(command, conf, variables): |
13 | 15 |
"""Place any commands to setup vigigraph here""" |
14 | 16 |
from vigilo.turbogears import populate_db as tg_pop_db |
15 |
from vigigraph.config.environment import load_environment |
|
16 | 17 |
|
18 |
# Charge le fichier "app_cfg.py" se trouvant aux côtés de "settings.ini". |
|
19 |
mod_info = imp.find_module('app_cfg', [ conf.global_conf['here'] ]) |
|
20 |
app_cfg = imp.load_module('vigigraph.config.app_cfg', *mod_info) |
|
21 |
|
|
22 |
# Initialisation de l'environnement d'exécution. |
|
23 |
load_environment = app_cfg.base_config.make_load_environment() |
|
17 | 24 |
load_environment(conf.global_conf, conf.local_conf) |
18 | 25 |
tg_pop_db() |
19 | 26 |
|
Also available in: Unified diff