From 0380c94c9af6d8b4923a84e75f06ffc2ff982ded Mon Sep 17 00:00:00 2001 From: thierry Date: Mon, 25 Jan 2010 12:27:47 +0000 Subject: [PATCH] retrieve vserver fullname and outline attached vplc --- scripts/manage-infrastructure.py | 63 ++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/scripts/manage-infrastructure.py b/scripts/manage-infrastructure.py index 84ad9c1..8b41286 100755 --- a/scripts/manage-infrastructure.py +++ b/scripts/manage-infrastructure.py @@ -1,5 +1,7 @@ #!/usr/bin/python +import os.path +import re import subprocess from optparse import OptionParser @@ -69,10 +71,47 @@ class BuildBoxes: else: self.reboot(box) + vplc_matcher = re.compile(".*(vplc[0-9]+$)") + def vplcname (self, vservername): + match = self.vplc_matcher.match(vservername) + if match: return match.groups(0) + else: return "" + def handle_plc_box (self,box): if self.options.probe: command=['ssh',self.root(box),'vserver-stat'] - self.run(command,"Active vservers on %s"%box) + if self.options.dry_run: + self.run(command,"Active vservers on %s"%box) + else: + # try to find fullname (vserver_stat truncates to a ridiculously short name) + try: + self.header ("vserver map on %s"%box) + # fetch the contexts for all vservers on that box + map_command=['ssh',self.root(box),'grep','.','/etc/vservers/*/context','/dev/null',] + context_map=self.backquote (map_command) + # at this point we have a set of lines like + # /etc/vservers/2010.01.20--k27-f12-32-vplc03/context:40144 + ctx_dict={} + for map_line in context_map.split("\n"): + if not map_line: continue + [path,xid] = map_line.split(':') + ctx_dict[xid]=os.path.basename(os.path.dirname(path)) + # at this point ctx_id maps context id to vservername + + vserver_stat = self.backquote (command) + for vserver_line in vserver_stat.split("\n"): + if not vserver_line: continue + context=vserver_line.split()[0] + if context=="CTX": + print vserver_line + continue + longname=ctx_dict[context] + plcname=self.vplcname(longname) + if plcname: print "== %s =="%plcname + print "%(vserver_line)s [=%(longname)s]"%locals() + except: + self.run(command,"Fine-grained method failed - fallback to plain vserver-stat") + else: self.reboot(box) @@ -103,18 +142,22 @@ class BuildBoxes: usage="""%prog [options] [hostname..(s)] Default is to act on test boxes only (with trackers clean)""" parser = OptionParser (usage=usage) + parser.add_option ("-n","--dry-run",action="store_true",dest="dry_run",default=False, + help="Dry run") + parser.add_option ("-r","--reboot", action="store_false",dest="probe",default=True, + help="Actually reset/reboot stuff instead of just probing it") + # no need for -p = probe, as this is the default + parser.add_option ("-p","--plc", action="store_true",dest="plc_only",default=False, + help="Acts on the plc box only") + parser.add_option ("-a","--all",action="store_true",dest="all_boxes",default=False, help="Acts on build and test boxes") parser.add_option ("-b","--build",action="store_true",dest="build_only",default=False, help="Acts on build boxes only") + parser.add_option ("-q","--qemu",action="store_true",dest="qemu_only",default=False, + help="Only acts on the qemu boxes") parser.add_option ("-t","--trackers",action="store_true",dest="trackers_only",default=False, help="Only wipes trackers") - parser.add_option ("-n","--dry-run",action="store_true",dest="dry_run",default=False, - help="Dry run") - parser.add_option ("-r","--reboot", action="store_false",dest="probe",default=True, - help="Actually reset/reboot stuff instead of just probing it") - parser.add_option ("-p","--probe", action="store_true",dest="probe", - help="Probe stuff, no side effect") (self.options,args) = parser.parse_args() @@ -129,6 +172,12 @@ Default is to act on test boxes only (with trackers clean)""" elif self.options.build_only: self.boxes=self.build_boxes self.do_tracker = False + elif self.options.qemu_only: + self.boxes=self.qemu_boxes + self.do_tracker = False + elif self.options.plc_only: + self.boxes=self.plc_boxes + self.do_tracker = False elif self.options.trackers_only: self.boxes = [] self.do_tracker = True -- 2.47.0