-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.py
59 lines (52 loc) · 1.84 KB
/
client.py
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
#!/usr/bin/env python2.7
#Jack Dwyer 12-12-2012
from urlparse import urlparse
import xmlrpclib
import socket
from xmlrpclib import ResponseError
import utils
class SupervisorClient(object):
def __init__(self, uri, clientID, name=None, description=None, group=None):
#uri is urlparse object
self.URI = uri
self.id = clientID
self.name = name
self.description = description
self.group = group
self.server = xmlrpclib.ServerProxy(self.URI.geturl())
def get_details(self):
details = self.get_process_info()
try:
totalProcesses = len(details)
totalRunning = 0
for service in details:
if service['state'] == 20:
totalRunning += 1
except TypeError:
totalProcesses = 0
totalRunning = 0
return {"name": self.name, "ip":self.URI.netloc, "port":self.URI.port,
"href":self.URI.geturl(), "details":details,
"id":self.id, "totalClientProcesses":totalProcesses ,
"totalClientRunning":totalRunning, "description":self.description}
def get_process_info(self):
try:
return self.server.supervisor.getAllProcessInfo()
except IOError:
return None
def __repr__(self):
return self.__class__.__name__ + '(%s)' % (', '.join(map(repr, [self.name, self.URI.geturl()])))
if __name__ == '__main__':
clientDetails = utils.parse_settings("../settings.conf")
clients = []
#Generate Supervisor clients
for detail in clientDetails:
if (len(detail) == 2):
print detail
continue
if (len(detail) == 1):
print detail
continue
else:
print "Parsing Error in Settings, please check"
sys.exit(1)