4 from optparse import OptionParser
8 # everything in the onelab.eu domain
10 testmaster = 'testmaster'
13 [ "build%d"%i for i in range (1,4) ]
14 plc_boxes = [ "testplc" ]
16 [ "testqemu%d"%i for i in range (1,4) ] + \
17 [ "testqemu32-%d"%i for i in range (1,6) ]
18 test_boxes = plc_boxes + qemu_boxes
23 self.do_tracker = False
26 return "%s.%s"%(box,self.domain)
28 def root (box): return "root@%s"%box
30 def header (self,message):
31 print "===============",message
33 def run (self,argv,message):
34 if self.options.dry_run:
38 if message: self.header(message)
41 def backquote (self, argv):
42 return subprocess.Popen(argv,stdout=subprocess.PIPE).communicate()[0]
44 def reboot (self,box):
45 command=['ssh',self.root(box),'shutdown','-r','now']
46 self.run (command,"Rebooting %s"%box)
48 def handle_trackers (self):
49 box = self.fqdn (self.testmaster)
50 if self.options.probe:
51 command=['ssh',self.root(box),"head","-100","tracker*"]
52 self.run(command,"Inspecting trackers on %s"%box)
54 command=['ssh',self.root(box),"rm","-rf","tracker*"]
55 self.run(command,"Cleaning up trackers on %s"%box)
57 def handle_build_box (self,box):
58 if self.options.probe:
59 command=['ssh',self.root(box),'pgrep','build']
60 if self.options.dry_run:
61 self.run(command,None)
63 pids=self.backquote(command)
65 self.header ('No build process on %s'%box)
67 command=['ssh',self.root(box),'ps'] + [ pid for pid in pids.split("\n") if pid]
68 self.run(command,"Active build processes on %s"%box)
72 def handle_plc_box (self,box):
73 if self.options.probe:
74 command=['ssh',self.root(box),'vserver-stat']
75 self.run(command,"Active vservers on %s"%box)
79 def handle_qemu_box (self,box):
80 if self.options.probe:
81 command=['ssh',self.root(box),'pgrep','qemu']
82 if self.options.dry_run:
83 self.run(command,None)
85 pids=self.backquote(command)
87 self.header ('No qemu process on %s'%box)
89 command=['ssh',self.root(box),'ps'] + [ pid for pid in pids.split("\n") if pid]
90 self.run(command,"Active qemu processes on %s"%box)
94 def handle_box(self,box):
95 if box in self.qemu_boxes:
96 self.handle_qemu_box(self.fqdn(box))
97 elif box in self.plc_boxes:
98 self.handle_plc_box(self.fqdn(box))
100 self.handle_build_box(self.fqdn(box))
103 usage="""%prog [options] [hostname..(s)]
104 Default is to act on test boxes only (with trackers clean)"""
105 parser = OptionParser (usage=usage)
106 parser.add_option ("-a","--all",action="store_true",dest="all_boxes",default=False,
107 help="Acts on build and test boxes")
108 parser.add_option ("-b","--build",action="store_true",dest="build_only",default=False,
109 help="Acts on build boxes only")
110 parser.add_option ("-t","--trackers",action="store_true",dest="trackers_only",default=False,
111 help="Only wipes trackers")
112 parser.add_option ("-n","--dry-run",action="store_true",dest="dry_run",default=False,
114 parser.add_option ("-r","--reboot", action="store_false",dest="probe",default=True,
115 help="Actually reset/reboot stuff instead of just probing it")
116 parser.add_option ("-p","--probe", action="store_true",dest="probe",
117 help="Probe stuff, no side effect")
119 (self.options,args) = parser.parse_args()
121 # use given hostnames if provided
124 # if hostnames are specified, let's stay on the safe side and don't reset trackers
125 self.do_tracker = False
126 elif self.options.all_boxes:
127 self.boxes=self.build_boxes + self.test_boxes
128 self.do_tracker = True
129 elif self.options.build_only:
130 self.boxes=self.build_boxes
131 self.do_tracker = False
132 elif self.options.trackers_only:
134 self.do_tracker = True
137 self.boxes = self.test_boxes
138 self.do_tracker = True
141 self.handle_trackers ()
142 for box in self.boxes:
143 self.handle_box (box)
146 if __name__ == "__main__":