avoid annoying warnings from ssh when loopbacking towards liquid
authorthierry <thierry@41d37cc5-eb28-0410-a9bf-d37491348ade>
Tue, 26 Jan 2010 17:36:27 +0000 (17:36 +0000)
committerthierry <thierry@41d37cc5-eb28-0410-a9bf-d37491348ade>
Tue, 26 Jan 2010 17:36:27 +0000 (17:36 +0000)
scripts/manage-infrastructure.py

index ac8bd0f..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']
@@ -59,18 +68,18 @@ class BuildBoxes:
             self.reboot(box)
         else:
             command=['ssh',self.root(box),'uptime']
-            uptime=self.backquote(command).strip()
+            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 (%s)'%(box,uptime))
                 else:
                     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))
+                    self.run(command,"Active build processes on %s (%s)"%(box,uptime),True)
 
     vplc_matcher = re.compile(".*(vplc[0-9]+$)")
     def vplcname (self, vservername):