avoid annoying warnings from ssh when loopbacking towards liquid
[infrastructure.git] / scripts / manage-infrastructure.py
index a994aef..f9983ec 100755 (executable)
@@ -30,16 +30,25 @@ class BuildBoxes:
     def header (self,message):
         print "===============",message
 
-    def run (self,argv,message):
+    def run (self,argv,message, trash_err=False):
         if self.options.dry_run:
             print 'DRY_RUN:',
             print " ".join(argv)
         else:
             if message: self.header(message)
-            subprocess.call(argv)
+            if not trash_err:
+                subprocess.call(argv)
+            else:
+                subprocess.call(argv,stderr=file('/dev/null','w'))
                 
-    def backquote (self, argv):
-        return subprocess.Popen(argv,stdout=subprocess.PIPE).communicate()[0]
+    def backquote (self, argv, trash_err=False):
+        if not trash_err:
+            return subprocess.Popen(argv,stdout=subprocess.PIPE).communicate()[0]
+        else:
+            null = open('/dev/null','w')
+            result = subprocess.Popen(argv,stdout=subprocess.PIPE,stderr=null).communicate()[0]
+            null.close()
+            return result
 
     def reboot (self,box):
         command=['ssh',self.root(box),'shutdown','-r','now']
@@ -58,16 +67,19 @@ class BuildBoxes:
         if not self.options.probe:
             self.reboot(box)
         else:
+            command=['ssh',self.root(box),'uptime']
+            uptime=self.backquote(command,True).strip()
+
             command=['ssh',self.root(box),'pgrep','build']
             if self.options.dry_run:
                 self.run(command,None)
             else:
-                pids=self.backquote(command)
+                pids=self.backquote(command,True)
                 if not pids:
-                    self.header ('No build process on %s'%box)
+                    self.header ('No build process on %s (%s)'%(box,uptime))
                 else:
-                    command=['ssh',self.root(box),'ps'] + [ pid for pid in pids.split("\n") if pid]
-                    self.run(command,"Active build processes on %s"%box)
+                    command=['ssh',self.root(box),'ps','-o','pid,command'] + [ pid for pid in pids.split("\n") if pid]
+                    self.run(command,"Active build processes on %s (%s)"%(box,uptime),True)
 
     vplc_matcher = re.compile(".*(vplc[0-9]+$)")
     def vplcname (self, vservername):
@@ -132,7 +144,7 @@ class BuildBoxes:
                     self.header ('No qemu process on %s'%box)
                 else:
                     self.header ("Active qemu processes on %s"%box)
-                    command=['ssh',self.root(box),'ps'] + [ pid for pid in pids.split("\n") if pid]
+                    command=['ssh',self.root(box),'ps','-o','pid,command'] + [ pid for pid in pids.split("\n") if pid]
                     ps_lines = self.backquote (command).split("\n")
                     for ps_line in ps_lines:
                         if not ps_line or ps_line.find('PID') >=0 : continue