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 run (self,argv,message):
31 if self.options.dry_run:
35 if message: print "===============",message
38 def backquote (self, argv):
39 return subprocess.Popen(argv,stdout=subprocess.PIPE).communicate()[0]
41 def reboot (self,box):
42 command=['ssh',self.root(box),'shutdown','-r','now']
43 self.run (command,"Rebooting %s"%box)
45 def handle_trackers (self):
46 box = self.fqdn (self.testmaster)
47 if self.options.probe:
48 command=['ssh',self.root(box),"head","-100","'trackers*'"]
49 self.run(command,"========== Inspecting trackers on %s"%box)
51 command=['ssh',self.root(box),"rm","-rf","'trackers*'"]
52 self.run(command,"========== Cleaning up trackers on %s"%box)
54 def handle_build_box (self,box):
55 if self.options.probe:
56 command=['ssh',self.root(box),'pgrep','build']
57 if self.options.dry_run:
58 self.run(command,None)
60 pids=self.backquote(command)
62 print 'No build process on',box
64 command=['ssh',self.root(box),'ps'] + [ pid for pid in pids.split("\n") if pid]
65 self.run(command,"Active build processes on %s"%box)
69 def handle_plc_box (self,box):
70 if self.options.probe:
71 command=['ssh',self.root(box),'vserver-stat']
72 self.run(command,"Active vservers on %s"%box)
76 def handle_qemu_box (self,box):
77 if self.options.probe:
78 command=['ssh',self.root(box),'pgrep','qemu']
79 if self.options.dry_run:
80 self.run(command,None)
82 pids=self.backquote(command)
84 print 'No qemu process on',box
86 command=['ssh',self.root(box),'ps'] + [ pid for pid in pids.split("\n") if pid]
87 self.run(command,"Active qemu processes on %s"%box)
91 def handle_box(self,box):
92 if box in self.qemu_boxes:
93 self.handle_qemu_box(self.fqdn(box))
94 elif box in self.plc_boxes:
95 self.handle_plc_box(self.fqdn(box))
97 self.handle_build_box(self.fqdn(box))
100 usage="""%prog [options] [hostname..(s)]
101 Default is to act on test boxes only (with trackers clean)"""
102 parser = OptionParser (usage=usage)
103 parser.add_option ("-a","--all",action="store_true",dest="all_boxes",default=False,
104 help="Acts on build and test boxes")
105 parser.add_option ("-b","--build",action="store_true",dest="build_only",default=False,
106 help="Acts on build boxes only")
107 parser.add_option ("-t","--trackers",action="store_true",dest="trackers_only",default=False,
108 help="Only wipes trackers")
109 parser.add_option ("-n","--dry-run",action="store_true",dest="dry_run",default=False,
111 parser.add_option ("-r","--reboot", action="store_false",dest="probe",default=True,
112 help="Actually reset/reboot stuff instead of just probing it")
113 parser.add_option ("-p","--probe", action="store_true",dest="probe",
114 help="Probe stuff, no side effect")
116 (self.options,args) = parser.parse_args()
118 # use given hostnames if provided
121 # if hostnames are specified, let's stay on the safe side and don't reset trackers
122 self.do_tracker = False
123 elif self.options.all_boxes:
124 self.boxes=self.build_boxes + self.test_boxes
125 self.do_tracker = True
126 elif self.options.build_only:
127 self.boxes=self.build_boxes
128 self.do_tracker = False
129 elif self.options.trackers_only:
131 self.do_tracker = True
134 self.boxes = self.test_boxes
135 self.do_tracker = True
138 self.handle_trackers ()
139 for box in self.boxes:
140 self.handle_box (box)
143 if __name__ == "__main__":