Revision d1850fc4
Suppression du "TemplateController" dans vigiboard & vigigraph (créé par défaut par TG2 mais jamais utilisé).
Améliorations pylint dans VigiGraph + correction d'une typo dans le !RPCController.
Ajout de docstrings.
git-svn-id: https://vigilo-dev.si.c-s.fr/svn@2841 b22e2e97-25c9-44ff-b637-2e5ceca36478
vigigraph/controllers/rpc.py | ||
---|---|---|
2 | 2 |
"""RPC controller for the combobox of vigigraph""" |
3 | 3 |
|
4 | 4 |
import time, urlparse |
5 |
import urllib |
|
6 |
import urllib2 |
|
7 | 5 |
import logging |
8 | 6 |
|
9 | 7 |
# La fonction parse_qsl a été déplacée dans Python 2.6. |
... | ... | |
13 | 11 |
from cgi import parse_qsl |
14 | 12 |
|
15 | 13 |
from pylons.i18n import ugettext as _, lazy_ugettext as l_ |
16 |
from tg import expose, response, request, redirect, tmpl_context, \
|
|
17 |
config, url, exceptions, validate, flash
|
|
14 |
from tg import expose, request, redirect, tmpl_context, \ |
|
15 |
config, validate, flash |
|
18 | 16 |
from tg.decorators import paginate |
19 | 17 |
from repoze.what.predicates import not_anonymous |
20 | 18 |
from formencode import validators, schema |
21 |
|
|
22 |
from sqlalchemy.orm import aliased |
|
23 | 19 |
from sqlalchemy import or_ |
24 | 20 |
|
25 | 21 |
from vigilo.turbogears.controllers import BaseController |
26 | 22 |
from vigilo.turbogears.helpers import get_current_user |
27 | 23 |
|
28 | 24 |
from vigilo.models.session import DBSession |
29 |
from vigilo.models.tables import LowLevelService, Host, User
|
|
25 |
from vigilo.models.tables import LowLevelService, Host |
|
30 | 26 |
from vigilo.models.tables import SupItemGroup |
31 | 27 |
from vigilo.models.tables import PerfDataSource |
32 | 28 |
from vigilo.models.tables import Graph, GraphGroup |
33 |
from vigilo.models.tables import Ventilation, VigiloServer, Application |
|
34 | 29 |
from vigilo.models.tables.grouphierarchy import GroupHierarchy |
35 | 30 |
|
36 | 31 |
from vigilo.models.tables.secondary_tables import SUPITEM_GROUP_TABLE |
... | ... | |
113 | 108 |
return dict(items=topgroups) |
114 | 109 |
|
115 | 110 |
class HostgroupsSchema(schema.Schema): |
111 |
"""Schéma de validation pour la méthode L{hostgroups}.""" |
|
116 | 112 |
maingroupid = validators.Int(not_empty=True) |
117 | 113 |
nocache = validators.String(if_missing=None) |
118 | 114 |
|
119 | 115 |
# @TODO définir un error_handler différent pour remonter l'erreur via JS. |
120 | 116 |
@validate( |
121 |
validators=HostgroupsSchema(),
|
|
122 |
error_handler=process_form_errors)
|
|
117 |
validators = HostgroupsSchema(),
|
|
118 |
error_handler = process_form_errors)
|
|
123 | 119 |
@expose('json') |
124 | 120 |
def hostgroups(self, maingroupid, nocache): |
125 | 121 |
""" |
... | ... | |
158 | 154 |
return dict(items=hostgroups) |
159 | 155 |
|
160 | 156 |
class HostsSchema(schema.Schema): |
157 |
"""Schéma de validation pour la méthode L{hosts}.""" |
|
161 | 158 |
othergroupid = validators.Int(not_empty=True) |
162 | 159 |
nocache = validators.String(if_missing=None) |
163 | 160 |
|
164 | 161 |
# @TODO définir un error_handler différent pour remonter l'erreur via JS. |
165 | 162 |
@validate( |
166 |
validators=HostsSchema(),
|
|
167 |
error_handler=process_form_errors)
|
|
163 |
validators = HostsSchema(),
|
|
164 |
error_handler = process_form_errors)
|
|
168 | 165 |
@expose('json') |
169 | 166 |
def hosts(self, othergroupid, nocache): |
170 | 167 |
""" |
... | ... | |
211 | 208 |
return dict(items=hosts) |
212 | 209 |
|
213 | 210 |
class GraphGroupsSchema(schema.Schema): |
211 |
"""Schéma de validation pour la méthode L{graphgroups}.""" |
|
214 | 212 |
idhost = validators.Int(not_empty=True) |
215 | 213 |
nocache = validators.String(if_missing=None) |
216 | 214 |
|
217 | 215 |
# @TODO définir un error_handler différent pour remonter l'erreur via JS. |
218 | 216 |
@validate( |
219 |
validators=GraphGroupsSchema(),
|
|
220 |
error_handler=process_form_errors)
|
|
217 |
validators = GraphGroupsSchema(),
|
|
218 |
error_handler = process_form_errors)
|
|
221 | 219 |
@expose('json') |
222 | 220 |
def graphgroups(self, idhost, nocache): |
223 | 221 |
""" |
... | ... | |
264 | 262 |
return dict(items=graphgroups) |
265 | 263 |
|
266 | 264 |
class GraphsSchema(schema.Schema): |
265 |
"""Schéma de validation pour la méthode L{graphs}.""" |
|
267 | 266 |
idgraphgroup = validators.Int(not_empty=True) |
268 | 267 |
idhost = validators.Int(not_empty=True) |
269 | 268 |
nocache = validators.String(if_missing=None) |
270 | 269 |
|
271 | 270 |
# @TODO définir un error_handler différent pour remonter l'erreur via JS. |
272 | 271 |
@validate( |
273 |
validators=GraphsSchema(),
|
|
274 |
error_handler=process_form_errors)
|
|
272 |
validators = GraphsSchema(),
|
|
273 |
error_handler = process_form_errors)
|
|
275 | 274 |
@expose('json') |
276 | 275 |
def graphs(self, idgraphgroup, idhost, nocache): |
277 | 276 |
""" |
... | ... | |
319 | 318 |
return dict(items=graphs) |
320 | 319 |
|
321 | 320 |
class SearchHostAndGraphSchema(schema.Schema): |
321 |
"""Schéma de validation pour la méthode L{searchHostAndGraph}.""" |
|
322 | 322 |
host = validators.String(if_missing=None) |
323 | 323 |
graph = validators.String(if_missing=None) |
324 | 324 |
nocache = validators.String(if_missing=None) |
325 | 325 |
|
326 | 326 |
# @TODO définir un error_handler différent pour remonter l'erreur via JS. |
327 | 327 |
@validate( |
328 |
validators=SearchHostAndGraphSchema(),
|
|
329 |
error_handler=process_form_errors)
|
|
328 |
validators = SearchHostAndGraphSchema(),
|
|
329 |
error_handler = process_form_errors)
|
|
330 | 330 |
@expose('json') |
331 | 331 |
def searchHostAndGraph(self, host, graph, nocache): |
332 | 332 |
""" |
... | ... | |
412 | 412 |
return dict(items=items) |
413 | 413 |
|
414 | 414 |
class SelectHostAndGraphSchema(schema.Schema): |
415 |
"""Schéma de validation pour la méthode L{selectHostAndGraph}.""" |
|
415 | 416 |
host = validators.String(if_missing=None) |
416 | 417 |
graph = validators.String(if_missing=None) |
417 | 418 |
nocache = validators.String(if_missing=None) |
418 | 419 |
|
419 | 420 |
# @TODO définir un error_handler différent pour remonter l'erreur via JS. |
420 | 421 |
@validate( |
421 |
validators=SelectHostAndGraphSchema(),
|
|
422 |
error_handler=process_form_errors)
|
|
422 |
validators = SelectHostAndGraphSchema(),
|
|
423 |
error_handler = process_form_errors)
|
|
423 | 424 |
@expose('json') |
424 | 425 |
def selectHostAndGraph(self, host, graph, nocache): |
425 | 426 |
""" |
... | ... | |
443 | 444 |
if (not host) and (not graph): |
444 | 445 |
return dict(items=[[], []]) |
445 | 446 |
|
446 |
# Groupe principal de l'hôte. |
|
447 |
mhg = aliased(SupItemGroup) |
|
448 |
# Groupe secondaire de l'hôte. |
|
449 |
shg = aliased(SupItemGroup) |
|
450 |
|
|
451 | 447 |
selected_hostgroups = [] |
452 | 448 |
selected_graphgroups = [] |
453 | 449 |
|
... | ... | |
556 | 552 |
|
557 | 553 |
try: |
558 | 554 |
delay = int(config['delay_refresh']) |
559 |
except ValueError, KeyError:
|
|
555 |
except (ValueError, KeyError):
|
|
560 | 556 |
delay = 36000 |
561 | 557 |
return str(delay) |
562 | 558 |
|
563 | 559 |
class GetIndicatorsSchema(schema.Schema): |
560 |
"""Schéma de validation pour la méthode L{getIndicators}.""" |
|
564 | 561 |
graph = validators.String(not_empty=True) |
565 | 562 |
nocache = validators.String(if_missing=None) |
566 | 563 |
|
567 | 564 |
# @TODO définir un error_handler différent pour remonter l'erreur via JS. |
568 | 565 |
@validate( |
569 |
validators=GetIndicatorsSchema(),
|
|
570 |
error_handler=process_form_errors)
|
|
566 |
validators = GetIndicatorsSchema(),
|
|
567 |
error_handler = process_form_errors)
|
|
571 | 568 |
@expose('json') |
572 | 569 |
def getIndicators(self, graph, nocache): |
573 | 570 |
""" |
... | ... | |
586 | 583 |
|
587 | 584 |
|
588 | 585 |
class FullHostPageSchema(schema.Schema): |
586 |
"""Schéma de validation pour la méthode L{fullHostPage}.""" |
|
589 | 587 |
host = validators.String(not_empty=True) |
590 | 588 |
start = validators.Int(if_missing=None) |
591 | 589 |
duration = validators.Int(if_missing=86400) |
592 | 590 |
|
593 | 591 |
# VIGILO_EXIG_VIGILO_PERF_0010:Visualisation globale des graphes |
594 | 592 |
@validate( |
595 |
validators=FullHostPageSchema(),
|
|
596 |
error_handler=process_form_errors)
|
|
593 |
validators = FullHostPageSchema(),
|
|
594 |
error_handler = process_form_errors)
|
|
597 | 595 |
@expose('fullhostpage.html') |
598 | 596 |
def fullHostPage(self, host, start=None, duration=86400): |
599 | 597 |
""" |
... | ... | |
654 | 652 |
|
655 | 653 |
|
656 | 654 |
class SingleGraphSchema(schema.Schema): |
655 |
"""Schéma de validation pour la méthode L{singleGraph}.""" |
|
657 | 656 |
host = validators.String(not_empty=True) |
658 | 657 |
graph = validators.String(not_empty=True) |
659 | 658 |
start = validators.Int(if_missing=None) |
... | ... | |
661 | 660 |
|
662 | 661 |
# VIGILO_EXIG_VIGILO_PERF_0020:Visualisation unitaire des graphes |
663 | 662 |
@validate( |
664 |
validators=SingleGraphSchema(),
|
|
665 |
error_handler=process_form_errors)
|
|
663 |
validators = SingleGraphSchema(),
|
|
664 |
error_handler = process_form_errors)
|
|
666 | 665 |
@expose('singlegraph.html') |
667 | 666 |
def singleGraph(self, host, graph, start, duration): |
668 | 667 |
""" |
vigigraph/controllers/template.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
"""Fallback controller.""" |
|
3 |
|
|
4 |
from vigilo.turbogears.controllers import BaseController |
|
5 |
|
|
6 |
__all__ = ['TemplateController'] |
|
7 |
|
|
8 |
|
|
9 |
class TemplateController(BaseController): |
|
10 |
""" |
|
11 |
The fallback controller for vigigraph. |
|
12 |
|
|
13 |
By default, the final controller tried to fulfill the request |
|
14 |
when no other routes match. It may be used to display a template |
|
15 |
when all else fails, e.g.:: |
|
16 |
|
|
17 |
def view(self, url): |
|
18 |
return render('/%s' % url) |
|
19 |
|
|
20 |
Or if you're using Mako and want to explicitly send a 404 (Not |
|
21 |
Found) response code when the requested template doesn't exist:: |
|
22 |
|
|
23 |
import mako.exceptions |
|
24 |
|
|
25 |
def view(self, url): |
|
26 |
try: |
|
27 |
return render('/%s' % url) |
|
28 |
except mako.exceptions.TopLevelLookupException: |
|
29 |
abort(404) |
|
30 |
|
|
31 |
""" |
|
32 |
|
|
33 |
def view(self, url): |
|
34 |
"""Abort the request with a 404 HTTP status code.""" |
|
35 |
abort(404) |
Also available in: Unified diff