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