Newer
Older
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
"""Plugins helpers for Cloud Control node."""
from itertools import chain, imap
class Base(object):
"""Example skeleton plugin for cc-node.
If you want to create your own plugin for the `cc-node` you may create an
object that would quack just like this one or just inherit from this class.
"""
def __init__(self, *args, **kwargs):
"""
:param loop: pyev loop instance
"""
self.loop = kwargs.pop('loop')
# plugins may define tags (see :mod:`ccnode.tags`)
self.tag_db = dict(
__main__=dict(),
# subobjects tags go here
)
# plugins may define handler functions that would be called by the
# server
self.rpc_handler = dict()
# tag_db and rpc_handler can be implemented as properties if more logic
# is needed
def __hash__(self):
"""This method is used when registering a plugin in the main loop.
By default, only one instance is allowed. Subclasses can overide this
method to change this behaviour.
"""
return hash(self.__class__.__name__)
def start(self):
"""Used to start pyev watchers."""
# start tags
for tag in chain.from_iterable(
imap(lambda d: d.itervalues(), self.tag_db.itervalues()),
):
tag.start(self.loop)
def stop(self):
"""Cleanup for plugins, can be used to clean pyev watchers."""
self.loop = None
# TODO dependencies