3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
17 from cmframework.utils.cmpluginloader import CMPluginLoader
18 from cmframework.utils.cmpluginmanager import CMPluginManager
21 class CMValidator(CMPluginManager):
22 def __init__(self, plugins_path, plugin_client):
23 logging.info('Validator constructor, plugins_path is %s', plugins_path)
24 CMPluginManager.__init__(self, plugins_path)
26 self.plugin_client = plugin_client
28 def load_plugin(self):
29 pl = CMPluginLoader(self.plugins_path)
30 self.pluginlist, self.filterdict = pl.load()
31 logging.info('Plugin(s): %r', self.pluginlist)
32 logging.info('Subscription(s): %r', self.filterdict)
34 def validate_delete(self, indata):
35 self.validate_plugins(indata, 'validate_delete')
37 def validate_set(self, indata):
38 self.validate_plugins(indata, 'validate_set')
40 def validate_plugins(self, indata, operation):
41 # import pdb; pdb.set_trace()
42 logging.debug('validate_plugins called with data %s', indata)
43 for plugin, objectname in self.pluginlist.iteritems():
44 filtername = self.filterdict[plugin]
45 inputdata = self.build_input(indata, filtername)
47 logging.debug('Calling validation plugin %s with %s', plugin, inputdata)
48 class_name = getattr(objectname, plugin)
49 instance = class_name()
50 instance.plugin_client = self.plugin_client
52 func = getattr(instance, operation)
54 except AttributeError:
55 logging.info('Plugin %s does have function %s implemented', plugin, operation)