1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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')
|