1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """
17 Builtin plugin.
18 """
19 import os
20 import socket
21 import inspect
22 from uuid import uuid4
23 from gofer.decorators import *
24 from gofer.rmi.tracker import Tracker
25 from gofer.rmi.criteria import Builder
26 from gofer.agent.plugin import Plugin
27 from gofer.agent.action import Actions
28 from gofer.agent.config import Config
29
30 from logging import getLogger
31
32 log = getLogger(__name__)
33 plugin = Plugin.find(__name__)
37 s = []
38 for n in range(0,n):
39 s.append(' ')
40 s.append(str(v) % args)
41 return ''.join(s)
42
50
53
54 @remote
55 - def cancel(self, sn=None, criteria=None):
56 """
57 Cancel by serial number or user defined property.
58 @param sn: An RMI serial number.
59 @type sn: str
60 @param criteria: The criteria used to match the
61 I{any} property on an RMI request.
62 @type criteria: str
63 @return: The list of cancelled serial numbers.
64 @rtype: list
65 @raise Exception, on (sn) not found.
66 @see: L{gofer.rmi.criteria}
67 """
68 sn_list = []
69 cancelled = []
70 tracker = Tracker()
71 if sn:
72 sn_list = [sn]
73 if criteria:
74 b = Builder()
75 criteria = b.build(criteria)
76 sn_list = tracker.find(criteria)
77 for sn in sn_list:
78 _sn = tracker.cancel(sn)
79 if _sn:
80 cancelled.append(_sn)
81 return cancelled
82
83 @remote
85 s = []
86 cfg = Config()
87 s.append('Hello, I am gofer agent "%s"' % plugin.getuuid())
88 s.append('Here is my configuration:\n%s' % cfg)
89 s.append('Status: ready')
90 return '\n'.join(s)
91
92 @remote
94 s = []
95 s.append('Plugins:')
96 for p in Plugin.all():
97 if not p.enabled():
98 continue
99
100 s.append('')
101 if p.synonyms:
102 s.append(indent('<plugin> %s %s', 2, p.name, p.synonyms))
103 else:
104 s.append(indent('<plugin> %s', 2, p.name))
105
106 s.append(indent('Classes:', 4))
107 for n,v in p.dispatcher.catalog.items():
108 if inspect.ismodule(v):
109 continue
110 s.append(indent('<class> %s', 6, n))
111 s.append(indent('methods:', 8))
112 for n,v in inspect.getmembers(v, inspect.ismethod):
113 fn = v.im_func
114 if not hasattr(fn, 'gofer'):
115 continue
116 s.append(indent(self.__signature(n, fn), 10))
117
118 s.append(indent('Functions:', 4))
119 for n,v in p.dispatcher.catalog.items():
120 if not inspect.ismodule(v):
121 continue
122 for n,v in inspect.getmembers(v, inspect.isfunction):
123 fn = v
124 if not hasattr(fn, 'gofer'):
125 continue
126 s.append(indent(self.__signature(n, fn), 6))
127 s.append('')
128 s.append('Actions:')
129 for a in self.__actions():
130 s.append(' %s %s' % a)
131 return '\n'.join(s)
132
134 actions = []
135 for a in Actions().collated():
136 actions.append((a.name(), a.interval))
137 return actions
138
140 s = []
141 s.append(n)
142 s.append('(')
143 spec = inspect.getargspec(fn)
144 if 'self' in spec[0]:
145 spec[0].remove('self')
146 if spec[1]:
147 spec[0].append('*%s' % spec[1])
148 if spec[2]:
149 spec[0].append('**%s' % spec[2])
150 s.append(', '.join(spec[0]))
151 s.append(')')
152 return ''.join(s)
153
154
155 @remote
156 -def echo(something):
158
159
160
161
162
163 if not plugin.getuuid():
164 hostname = socket.gethostname()
165 uuid = str(uuid4())
166 if not hostname.startswith('localhost'):
167 uuid = 'admin@%s' % hostname
168 plugin.setuuid(uuid)
169