Package buildbot :: Package status :: Package web :: Module slaves
[frames] | no frames]

Source Code for Module buildbot.status.web.slaves

  1  # This file is part of Buildbot.  Buildbot is free software: you can 
  2  # redistribute it and/or modify it under the terms of the GNU General Public 
  3  # License as published by the Free Software Foundation, version 2. 
  4  # 
  5  # This program is distributed in the hope that it will be useful, but WITHOUT 
  6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  8  # details. 
  9  # 
 10  # You should have received a copy of the GNU General Public License along with 
 11  # this program; if not, write to the Free Software Foundation, Inc., 51 
 12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
 13  # 
 14  # Copyright Buildbot Team Members 
 15   
 16   
 17  import time, urllib 
 18  from twisted.web import html 
 19  from twisted.web.util import Redirect 
 20  from twisted.web.error import NoResource 
 21  from twisted.internet import defer 
 22   
 23  from buildbot.status.web.base import HtmlResource, abbreviate_age, \ 
 24      BuildLineMixin, ActionResource, path_to_slave, path_to_authzfail 
 25  from buildbot import util 
26 27 -class ShutdownActionResource(ActionResource):
28
29 - def __init__(self, slave):
30 self.slave = slave 31 self.action = "gracefulShutdown"
32 33 @defer.deferredGenerator
34 - def performAction(self, request):
35 d = self.getAuthz(request).actionAllowed(self.action, 36 request, 37 self.slave) 38 wfd = defer.waitForDeferred(d) 39 yield wfd 40 res = wfd.getResult() 41 42 url = None 43 if res: 44 self.slave.setGraceful(True) 45 url = path_to_slave(request, self.slave) 46 else: 47 url = path_to_authzfail(request) 48 yield url
49
50 # /buildslaves/$slavename 51 -class OneBuildSlaveResource(HtmlResource, BuildLineMixin):
52 addSlash = False
53 - def __init__(self, slavename):
56
57 - def getPageTitle(self, req):
58 return "Buildbot: %s" % self.slavename
59
60 - def getChild(self, path, req):
61 s = self.getStatus(req) 62 slave = s.getSlave(self.slavename) 63 if path == "shutdown": 64 return ShutdownActionResource(slave) 65 return Redirect(path_to_slave(req, slave))
66
67 - def content(self, request, ctx):
68 s = self.getStatus(request) 69 slave = s.getSlave(self.slavename) 70 71 my_builders = [] 72 for bname in s.getBuilderNames(): 73 b = s.getBuilder(bname) 74 for bs in b.getSlaves(): 75 if bs.getName() == self.slavename: 76 my_builders.append(b) 77 78 # Current builds 79 current_builds = [] 80 for b in my_builders: 81 for cb in b.getCurrentBuilds(): 82 if cb.getSlavename() == self.slavename: 83 current_builds.append(self.get_line_values(request, cb)) 84 85 try: 86 max_builds = int(request.args.get('numbuilds')[0]) 87 except: 88 max_builds = 10 89 90 recent_builds = [] 91 n = 0 92 for rb in s.generateFinishedBuilds(builders=[b.getName() for b in my_builders]): 93 if rb.getSlavename() == self.slavename: 94 n += 1 95 recent_builds.append(self.get_line_values(request, rb)) 96 if n > max_builds: 97 break 98 99 # connects over the last hour 100 slave = s.getSlave(self.slavename) 101 connect_count = slave.getConnectCount() 102 103 ctx.update(dict(slave=slave, 104 slavename = self.slavename, 105 current = current_builds, 106 recent = recent_builds, 107 shutdown_url = request.childLink("shutdown"), 108 authz = self.getAuthz(request), 109 this_url = "../../../" + path_to_slave(request, slave), 110 access_uri = slave.getAccessURI()), 111 admin = unicode(slave.getAdmin() or '', 'utf-8'), 112 host = unicode(slave.getHost() or '', 'utf-8'), 113 slave_version = slave.getVersion(), 114 show_builder_column = True, 115 connect_count = connect_count) 116 template = request.site.buildbot_service.templates.get_template("buildslave.html") 117 data = template.render(**ctx) 118 return data
119
120 # /buildslaves 121 -class BuildSlavesResource(HtmlResource):
122 pageTitle = "BuildSlaves" 123 addSlash = True 124
125 - def content(self, request, ctx):
126 s = self.getStatus(request) 127 128 #?no_builders=1 disables build column 129 show_builder_column = not (request.args.get('no_builders', '0')[0])=='1' 130 ctx['show_builder_column'] = show_builder_column 131 132 used_by_builder = {} 133 for bname in s.getBuilderNames(): 134 b = s.getBuilder(bname) 135 for bs in b.getSlaves(): 136 slavename = bs.getName() 137 if slavename not in used_by_builder: 138 used_by_builder[slavename] = [] 139 used_by_builder[slavename].append(bname) 140 141 slaves = ctx['slaves'] = [] 142 for name in util.naturalSort(s.getSlaveNames()): 143 info = {} 144 slaves.append(info) 145 slave = s.getSlave(name) 146 slave_status = s.botmaster.slaves[name].slave_status 147 info['running_builds'] = len(slave_status.getRunningBuilds()) 148 info['link'] = request.childLink(urllib.quote(name,'')) 149 info['name'] = name 150 151 if show_builder_column: 152 info['builders'] = [] 153 for b in used_by_builder.get(name, []): 154 info['builders'].append(dict(link=request.childLink("../builders/%s" % b), name=b)) 155 156 info['version'] = slave.getVersion() 157 info['connected'] = slave.isConnected() 158 info['connectCount'] = slave.getConnectCount() 159 160 info['admin'] = unicode(slave.getAdmin() or '', 'utf-8') 161 last = slave.lastMessageReceived() 162 if last: 163 info['last_heard_from_age'] = abbreviate_age(time.time() - last) 164 info['last_heard_from_time'] = time.strftime("%Y-%b-%d %H:%M:%S", 165 time.localtime(last)) 166 167 template = request.site.buildbot_service.templates.get_template("buildslaves.html") 168 data = template.render(**ctx) 169 return data
170
171 - def getChild(self, path, req):
172 try: 173 self.getStatus(req).getSlave(path) 174 return OneBuildSlaveResource(path) 175 except KeyError: 176 return NoResource("No such slave '%s'" % html.escape(path))
177