From f4d351fb9d08667995254d2431a39e7d136e404c Mon Sep 17 00:00:00 2001
From: "Bryn M. Reeves" <bmr@redhat.com>
Date: Mon, 17 Dec 2012 19:55:24 +0000
Subject: [PATCH] Add 'gear' option to OpenShift module

Add an option to allow the user to specify an optional gear UUID.
---
 sos/plugins/openshift.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/sos/plugins/openshift.py b/sos/plugins/openshift.py
index b1ca611..4d8dac6 100755
--- a/sos/plugins/openshift.py
+++ b/sos/plugins/openshift.py
@@ -15,11 +15,15 @@
 ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
 import sos.plugintools
+import glob
 
 class openshift(sos.plugintools.PluginBase):
     """OpenShift related information
     """
 
+    optionList = [('gear', 'Collect information about a specific gear',
+                        'fast', False)]
+
     broker_pkg = 'openshift-origin-broker'
     node_pkg = 'rubygem-openshift-origin-node'
 
@@ -33,6 +37,8 @@ class openshift(sos.plugintools.PluginBase):
     def setup(self):
         self.broker = self.isInstalled(self.broker_pkg)
         self.node = self.isInstalled(self.node_pkg)
+        self.gear = self.getOption('gear')
+
         self.addCopySpec("/etc/openshift")
         self.addForbiddenPath("/etc/openshift/rsync_id_rsa")
 
@@ -58,6 +64,10 @@ class openshift(sos.plugintools.PluginBase):
             self.collectExtOutput("/usr/sbin/oo-accept-node")
             self.collectExtOutput("/usr/sbin/oo-admin-ctl-gears list")
             self.collectExtOutput("/bin/ls /var/lib/openshift")
+            if self.gear:
+                gear_path = glob.glob("/var/lib/openshift/%s*" % self.gear)[0]
+                self.collectExtOutput("/bin/ls %s" % gear_path)
+                self.addCopySpec(gear_path + "/*/log*")
         try:
             status, output, runtime = self.callExtProg("/bin/hostname")
             if status != 0:
-- 
1.9.3