1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__ = """PythonClient
15 Python performance data collector client
16 """
17
18 import logging
19 log = logging.getLogger("zen.PythonClient")
20
21 import Globals
22
23 from BaseClient import BaseClient
24 from twisted.internet.defer import Deferred, DeferredList
25 from twisted.python.failure import Failure
26
28 """
29 Implement the DataCollector Client interface for Python
30 """
31
32
33 - def __init__(self, device=None, datacollector=None, plugins=[]):
34 """
35 Initializer
36
37 @param device: remote device to use the datacollector
38 @type device: device object
39 @param datacollector: performance data collector object
40 @type datacollector: datacollector object
41 @param plugins: Python-based performance data collector plugin
42 @type plugins: list of plugin objects
43 """
44 BaseClient.__init__(self, device, datacollector)
45 self.hostname = device.id
46 self.plugins = plugins
47 self.results = []
48
49
67
68
70 """
71 Twisted deferred error callback used to store the
72 results of the collection run
73
74 @param r: result from the collection run
75 @type r: result or Exception
76 @param plugin: Python-based performance data collector plugin
77 @type plugin: plugin object
78 """
79 if plugin is None:
80 self.clientFinished()
81 return
82
83 if isinstance(r, Failure):
84 log.warn("Error in %s: %s", plugin.name(), r.getErrorMessage())
85 else:
86 log.debug("Results for %s: %s", plugin.name(), str(r))
87 self.results.append((plugin, r))
88
89
91 """
92 Stop the collection of performance data
93 """
94 log.info("Python client finished collection for %s" % self.device.id)
95 if self.datacollector:
96 self.datacollector.clientFinished(self)
97
98
100 """
101 Return the results of the data collection.
102 To be implemented by child classes
103
104 @return: list of results
105 @rtype: list of results
106 """
107 return self.results
108