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 self.run(command,"Listing build processes on %s"%box)
61 def handle_plc_box (self,box):
62 if self.options.probe:
63 command=['ssh',self.root(box),'vserver-stat']
64 self.run(command,"Active vservers on %s"%box)
68 def handle_qemu_box (self,box):
69 if self.options.probe:
70 command=['ssh',self.root(box),'pgrep','qemu']
71 if self.options.dry_run:
72 self.run(command,None)
74 pids=self.backquote(command)
76 print 'No qemu process on',box
78 command=['ssh',self.root(box),'ps'] + [ pid for pid in pids.split("\n") if pid]
79 self.run(command,"Active qemu processes on %s"%box)
83 def handle_box(self,box):
84 if box in self.qemu_boxes:
85 self.handle_qemu_box(self.fqdn(box))
86 elif box in self.plc_boxes:
87 self.handle_plc_box(self.fqdn(box))
89 self.handle_build_box(self.fqdn(box))
92 usage="""%prog [options] [hostname..(s)]
93 Default is to act on test boxes only (with trackers clean)"""
94 parser = OptionParser (usage=usage)
95 parser.add_option ("-a","--all",action="store_true",dest="all_boxes",default=False,
96 help="Acts on build and test boxes")
97 parser.add_option ("-b","--build",action="store_true",dest="build_only",default=False,
98 help="Acts on build boxes only")
99 parser.add_option ("-t","--trackers",action="store_true",dest="trackers_only",default=False,
100 help="Only wipes trackers")
101 parser.add_option ("-n","--dry-run",action="store_true",dest="dry_run",default=False,
103 parser.add_option ("-r","--reboot", action="store_false",dest="probe",default=True,
104 help="Actually reset/reboot stuff instead of just probing it")
105 parser.add_option ("-p","--probe", action="store_true",dest="probe",
106 help="Probe stuff, no side effect")
108 (self.options,args) = parser.parse_args()
110 # use given hostnames if provided
113 # if hostnames are specified, let's stay on the safe side and don't reset trackers
114 self.do_tracker = False
115 elif self.options.all_boxes:
116 self.boxes=self.build_boxes + self.test_boxes
117 self.do_tracker = True
118 elif self.options.build_only:
119 self.boxes=self.build_boxes
120 self.do_tracker = False
121 elif self.options.trackers_only:
123 self.do_tracker = True
126 self.boxes = self.test_boxes
127 self.do_tracker = True
130 self.handle_trackers ()
131 for box in self.boxes:
132 self.handle_box (box)
135 if __name__ == "__main__":