5
from twisted.web import resource
7
from pydirector import Version
8
from pydirector.web import template
10
class BasePage(resource.Resource):
14
def __init__(self, parent):
15
resource.Resource.__init__(self)
18
def getHeader(self, refreshURL=''):
24
# XXX add an admin configuration option for setting the refresh
27
refresh = template.refresh % (refreshRate, refreshURL)
28
return template.header % (
29
refresh, self.parent.serverVersion, socket.gethostname())
33
Subclasses must override this.
37
def getFooter(self, message=''):
41
# XXX put the project URL in the admin config
42
projectURL ='http://pythondirector.sf.net'
44
message = template.message % urllib.unquote(message)
45
return template.footer % (projectURL, message)
52
return self.getHeader() + self.getBody() + self.getFooter()
54
def render_GET(self, request):
60
class RunningPage(BasePage):
71
content = self.getHeader(refreshURL='/running?refresh=1&ignore=%s' % time.time())
73
stopStart = template.stopRefresh % time.time()
75
stopStart = template.startRefresh % time.time()
76
content += template.refreshButtons % (
77
time.ctime(time.time()), time.time(), stopStart)
78
for service in self.parent.director.conf.getServices():
79
content += template.serviceName % service.name
80
for l in service.listen:
81
content += template.listeningService % l
82
eg = service.getEnabledGroup()
83
groups = service.getGroups()
85
sch = self.parent.director.getScheduler(service.name, group.name)
86
stats = sch.getStats(verbose=verbose)
87
hdict = sch.getHostNames()
90
desc = template.groupDescEnabled
93
desc = template.groupDescDisabled % (
94
service.name, group.name)
95
content += template.groupName % (klass, group.name)
97
content += template.groupHeaderForm % (
98
service.name, group.name, klass)
99
counts = stats['open']
100
totals = stats['totals']
104
if counts.has_key(h):
108
if totals.has_key(h):
112
content += template.hostInfo % (
113
klass, hdict[h], h, oc, tc, urllib.quote(service.name),
114
urllib.quote(group.name), urllib.quote(h))
117
content += template.badHostGroup % klass
121
content += template.badHostInfo % (
122
klass, hdict[host], host, what)
123
content += template.serviceClose
124
content += self.getFooter(resultMessage)
127
class AdminServer(resource.Resource):
131
def __init__(self, director):
132
resource.Resource.__init__(self)
133
self.director = director
134
self.config = director.conf.admin
135
self.starttime = time.time()
136
self.serverVersion = "pythondirector/%s"%Version
138
def getChild(self, name, request):
142
if name == 'running':
143
return RunningPage(self)
144
return resource.Resource.getChild(self, name, request)
146
def render_GET(self, request):