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

Source Code for Module buildbot.status.web.slaves

  1   
  2  import time, urllib 
  3  from twisted.web import html 
  4  from twisted.web.util import Redirect 
  5  from twisted.web.error import NoResource 
  6   
  7  from buildbot.status.web.base import HtmlResource, abbreviate_age, \ 
  8      BuildLineMixin, path_to_slave, path_to_authfail 
  9  from buildbot import util 
 10   
 11  # /buildslaves/$slavename 
12 -class OneBuildSlaveResource(HtmlResource, BuildLineMixin):
13 addSlash = False
14 - def __init__(self, slavename):
17
18 - def getTitle(self, req):
19 return "Buildbot: %s" % self.slavename
20
21 - def getChild(self, path, req):
22 s = self.getStatus(req) 23 slave = s.getSlave(self.slavename) 24 if path == "shutdown": 25 if self.getAuthz(req).actionAllowed("gracefulShutdown", req, slave): 26 slave.setGraceful(True) 27 else: 28 return Redirect(path_to_authfail(req)) 29 return Redirect(path_to_slave(req, slave))
30
31 - def content(self, request, ctx):
32 s = self.getStatus(request) 33 slave = s.getSlave(self.slavename) 34 35 my_builders = [] 36 for bname in s.getBuilderNames(): 37 b = s.getBuilder(bname) 38 for bs in b.getSlaves(): 39 if bs.getName() == self.slavename: 40 my_builders.append(b) 41 42 # Current builds 43 current_builds = [] 44 for b in my_builders: 45 for cb in b.getCurrentBuilds(): 46 if cb.getSlavename() == self.slavename: 47 current_builds.append(self.get_line_values(request, cb)) 48 49 try: 50 max_builds = int(request.args.get('numbuilds')[0]) 51 except: 52 max_builds = 10 53 54 recent_builds = [] 55 n = 0 56 for rb in s.generateFinishedBuilds(builders=[b.getName() for b in my_builders]): 57 if rb.getSlavename() == self.slavename: 58 n += 1 59 recent_builds.append(self.get_line_values(request, rb)) 60 if n > max_builds: 61 break 62 63 # connects over the last hour 64 slave = s.getSlave(self.slavename) 65 connect_count = slave.getConnectCount() 66 67 ctx.update(dict(slave=slave, 68 slavename = self.slavename, 69 current = current_builds, 70 recent = recent_builds, 71 shutdown_url = request.childLink("shutdown"), 72 authz = self.getAuthz(request), 73 this_url = "../../../" + path_to_slave(request, slave), 74 access_uri = slave.getAccessURI()), 75 admin = unicode(slave.getAdmin() or '', 'utf-8'), 76 host = unicode(slave.getHost() or '', 'utf-8'), 77 version = slave.getVersion(), 78 show_builder_column = True, 79 connect_count = connect_count) 80 template = request.site.buildbot_service.templates.get_template("buildslave.html") 81 data = template.render(**ctx) 82 return data
83 84 # /buildslaves
85 -class BuildSlavesResource(HtmlResource):
86 title = "BuildSlaves" 87 addSlash = True 88
89 - def content(self, request, ctx):
90 s = self.getStatus(request) 91 92 #?no_builders=1 disables build column 93 show_builder_column = not (request.args.get('no_builders', '0')[0])=='1' 94 ctx['show_builder_column'] = show_builder_column 95 96 used_by_builder = {} 97 for bname in s.getBuilderNames(): 98 b = s.getBuilder(bname) 99 for bs in b.getSlaves(): 100 slavename = bs.getName() 101 if slavename not in used_by_builder: 102 used_by_builder[slavename] = [] 103 used_by_builder[slavename].append(bname) 104 105 slaves = ctx['slaves'] = [] 106 for name in util.naturalSort(s.getSlaveNames()): 107 info = {} 108 slaves.append(info) 109 slave = s.getSlave(name) 110 slave_status = s.botmaster.slaves[name].slave_status 111 info['running_builds'] = len(slave_status.getRunningBuilds()) 112 info['link'] = request.childLink(urllib.quote(name,'')) 113 info['name'] = name 114 115 if show_builder_column: 116 info['builders'] = [] 117 for b in used_by_builder.get(name, []): 118 info['builders'].append(dict(link=request.childLink("../builders/%s" % b), name=b)) 119 120 info['version'] = slave.getVersion() 121 info['connected'] = slave.isConnected() 122 info['connectCount'] = slave.getConnectCount() 123 124 if slave.isConnected(): 125 info['admin'] = unicode(slave.getAdmin() or '', 'utf-8') 126 last = slave.lastMessageReceived() 127 if last: 128 info['last_heard_from_age'] = abbreviate_age(time.time() - last) 129 info['last_heard_from_time'] = time.strftime("%Y-%b-%d %H:%M:%S", 130 time.localtime(last)) 131 132 template = request.site.buildbot_service.templates.get_template("buildslaves.html") 133 data = template.render(**ctx) 134 return data
135
136 - def getChild(self, path, req):
137 try: 138 self.getStatus(req).getSlave(path) 139 return OneBuildSlaveResource(path) 140 except KeyError: 141 return NoResource("No such slave '%s'" % html.escape(path))
142