~oubiwann/pydirector/1.1.1

« back to all changes in this revision

Viewing changes to pydirector/web/admin.py

  • Committer: Duncan McGreggor
  • Date: 2008-06-21 07:28:04 UTC
  • Revision ID: oubiwann@lorien-20080621072804-jap8w00h8qvouvo2
Added support for render running XML config in twisted web ui.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import time
2
2
import urllib
3
3
import socket
 
4
from xml.dom import minidom
4
5
 
5
6
from twisted.web import resource
6
7
 
66
67
        """
67
68
 
68
69
        """
69
 
        return self.getPage(request)
 
70
        return str(self.getPage(request))
70
71
 
71
72
class RunningPage(BasePage):
72
73
    """
137
138
                        klass, hdict[host], host, what)
138
139
            content += template.serviceClose
139
140
        content += self.getFooter(resultMessage)
140
 
        return str(content)
 
141
        return content
141
142
 
142
143
class RunningConfig(BasePage):
143
144
    """
144
145
 
145
146
    """
 
147
    def getPage(self, request):
 
148
        """
 
149
 
 
150
        """
 
151
        request.setHeader('Content-type', 'text/plain')
 
152
        verbose = False
 
153
        conf = self.parent.director.conf
 
154
        doc = minidom.Document()
 
155
        top = doc.createElement("pdconfig")
 
156
        doc.appendChild(top)
 
157
        for service in conf.getServices():
 
158
            top.appendChild(doc.createTextNode("\n    "))
 
159
            serv = doc.createElement("service")
 
160
            serv.setAttribute('name', service.name)
 
161
            top.appendChild(serv)
 
162
            for l in service.listen:
 
163
                serv.appendChild(doc.createTextNode("\n        "))
 
164
                lobj = doc.createElement("listen")
 
165
                lobj.setAttribute('ip', l)
 
166
                serv.appendChild(lobj)
 
167
            groups = service.getGroups()
 
168
            for group in groups:
 
169
                serv.appendChild(doc.createTextNode("\n        "))
 
170
                sch = self.parent.director.getScheduler(service.name, group.name)
 
171
                xg = doc.createElement("group")
 
172
                xg.setAttribute('name', group.name)
 
173
                xg.setAttribute('scheduler', sch.schedulerName)
 
174
                serv.appendChild(xg)
 
175
                stats = sch.getStats(verbose=verbose)
 
176
                hosts = group.getHosts()
 
177
                hdict = sch.getHostNames()
 
178
                counts = stats['open']
 
179
                ahosts = counts.keys() # ahosts is now a list of active hosts
 
180
                # now add disabled hosts.
 
181
                for k in stats['bad'].keys():
 
182
                    ahosts.append('%s:%s'%k)
 
183
                ahosts.sort()
 
184
                for h in ahosts:
 
185
                    xg.appendChild(doc.createTextNode("\n            "))
 
186
                    xh = doc.createElement("host")
 
187
                    xh.setAttribute('name', hdict[h])
 
188
                    xh.setAttribute('ip', h)
 
189
                    xg.appendChild(xh)
 
190
                xg.appendChild(doc.createTextNode("\n        "))
 
191
            serv.appendChild(doc.createTextNode("\n        "))
 
192
            eg = service.getEnabledGroup()
 
193
            xeg = doc.createElement("enable")
 
194
            xeg.setAttribute("group", eg.name)
 
195
            serv.appendChild(xeg)
 
196
            serv.appendChild(doc.createTextNode("\n    "))
 
197
        top.appendChild(doc.createTextNode("\n    "))
 
198
        # now the admin block
 
199
        admin = self.parent.director.conf.admin
 
200
        if admin is not None:
 
201
            xa = doc.createElement("admin")
 
202
            xa.setAttribute("listen", "%s:%s"%admin.listen)
 
203
            top.appendChild(xa)
 
204
            for user in admin.getUsers():
 
205
                xa.appendChild(doc.createTextNode("\n        "))
 
206
                xu = doc.createElement("user")
 
207
                xu.setAttribute("name", user.name)
 
208
                xu.setAttribute("password", user.password)
 
209
                xu.setAttribute("access", user.access)
 
210
                xa.appendChild(xu)
 
211
            xa.appendChild(doc.createTextNode("\n    "))
 
212
            top.appendChild(doc.createTextNode("\n    "))
 
213
        # finally, the logging section (if set)
 
214
        #if logger.logfile is not None:
 
215
        #    xl = doc.createElement("logging")
 
216
        #    xl.setAttribute("file", logger.logfile)
 
217
        #    top.appendChild(xl)
 
218
        # final newline
 
219
        top.appendChild(doc.createTextNode("\n"))
 
220
        # and spit out the XML
 
221
        return doc.toxml()
146
222
 
147
223
class StoredConfig(BasePage):
148
224
    """