1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
import logging
log = logging.getLogger(__name__)
from turbogears import controllers, expose, flash
from func.overlord.client import Client
class Root(controllers.RootController):
@expose(template="funcweb.templates.minions")
def minions(self):
""" Return a list of our minions """
fc = Client("*")
return dict(minions=fc.system.list_methods())
@expose(template="funcweb.templates.minion")
def minion(self, name, module=None, method=None):
""" Display module or method details for a specific minion.
If only the minion name is given, it will display a list of modules
for that minion. If a module is supplied, it will display a list of
methods. If a method is supplied, it will display a method execution
form.
"""
fc = Client(name)
if not module: # list all modules
modules = fc.system.list_modules()
return dict(modules=modules)
else: # a module is specified
if method: # minion.module.method specified; bring up execution form
return dict(minion=name, module=module, method=method,
tg_template="funcweb.templates.method")
else: # return a list of methods for specified module
modules = getattr(fc, module).list_methods()
return dict(modules=modules, module=module,
tg_template="funcweb.templates.module")
index = minions # start with our minion view, for now
@expose(template="funcweb.templates.run")
def run(self, minion="*", module=None, method=None, arguments=None):
fc = Client(minion)
if arguments:
results = getattr(getattr(fc, module), method)(*arguments.split())
else:
results = getattr(getattr(fc, module), method)()
cmd = "%s.%s.%s(%s)" % (minion, module, method, arguments)
return dict(cmd=cmd, results=results)
|