summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Eckersberg <jeckersb@redhat.com>2009-02-20 11:55:05 -0500
committerJohn Eckersberg <jeckersb@redhat.com>2009-02-20 11:55:05 -0500
commitb607a0938d2fcdda80bfd5ca63312f571c607b40 (patch)
treeb1959a7174be1ab469c73467a9aaa50bd1a8dc11
parentd67b7853c512d8f302523c05b10d0503686313bd (diff)
downloadfunc-httpd.zip
func-httpd.tar.gz
func-httpd.tar.xz
Add httpd module. Can return information from mod_status and do graceful service restart.HEADhttpd
-rw-r--r--func/minion/modules/httpd.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/func/minion/modules/httpd.py b/func/minion/modules/httpd.py
new file mode 100644
index 0000000..2579ae8
--- /dev/null
+++ b/func/minion/modules/httpd.py
@@ -0,0 +1,67 @@
+#
+# Copyright 2009
+# John Eckersberg <jeckersb@redhat.com>
+#
+# This software may be freely redistributed under the terms of the GNU
+# general public license.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+import func_module
+
+class ServerStatusUnavailable(Exception):
+ pass
+
+class MalformedServerStatus(Exception):
+ pass
+
+class Httpd(func_module.FuncModule):
+
+ # Update these if need be.
+ version = "0.0.1"
+ api_version = "0.0.1"
+ description = "Gather information from and manipulate Apache HTTPD"
+
+ import service
+ import urllib2
+
+ HTTPD_SERVICE_NAME = 'httpd'
+
+ def server_status(self, host="localhost", request="server-status", ssl=False):
+ """
+ Returns a dictionary representing output from mod_status.
+
+ :Parameters:
+ - `host`: the hostname to query against.
+ - `request`: the location of the mod_status handler.
+ - `ssl`: whether or not to use HTTPS.
+ """
+ if ssl:
+ proto = "https"
+ else:
+ proto = "http"
+
+ try:
+ status = self.urllib2.urlopen("%s://%s/%s?auto" % (proto, host, request)).read()
+ except Exception, e:
+ raise ServerStatusUnavailable, e
+
+ result = {}
+ for line in status.split('\n'):
+ if not line:
+ continue
+ try:
+ k,v = [foo.strip() for foo in line.split(':')]
+ except ValueError:
+ raise MalformedServerStatus
+ result[k] = v
+
+ return result
+
+ def graceful(self):
+ """
+ Issue a graceful restart to the httpd service.
+ """
+ return self.service.Service()._Service__command(Httpd.HTTPD_SERVICE_NAME, 'graceful')