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 from __future__ import print_function
16 from cmframework.apis import cmerror
19 class CMBackendHandler(object):
20 def __init__(self, plugin_path, **kw):
22 logging.debug('Loading backend plugin from %s', plugin_path)
23 # Separate class path and module name
24 parts = plugin_path.rsplit('.', 1)
25 self.plugin_path = parts[0]
27 logging.debug('Importing %s from %s', class_name, self.plugin_path)
28 module = __import__(self.plugin_path, fromlist=[self.plugin_path])
29 classobj = getattr(module, class_name)
30 logging.debug('Constructing backend handler with args %r', kw)
31 self.plugin = classobj(**kw)
32 except ImportError as exp1:
33 raise cmerror.CMError(str(exp1))
34 except Exception as exp2:
35 raise cmerror.CMError(str(exp2))
37 def get_property(self, prop_name):
38 logging.debug('get_property called for %s', prop_name)
39 return self.plugin.get_property(prop_name)
41 def get_properties(self, prop_filter):
42 logging.debug('get_properties called with filter %s', prop_filter)
43 return self.plugin.get_properties(prop_filter)
45 def set_property(self, prop_name, prop_value):
46 logging.debug('set_property called for setting %s=%s', prop_name, prop_value)
47 return self.plugin.set_property(prop_name, prop_value)
49 def set_properties(self, props):
50 logging.debug('set_properties called for properties %s', str(props))
51 return self.plugin.set_properties(props)
53 def delete_property(self, prop_name):
54 logging.debug('delete_property called for %s', prop_name)
55 return self.plugin.delete_property(prop_name)
57 def delete_properties(self, prop_filter):
58 logging.debug('delete_properties called with filter %s', prop_filter)
59 return self.plugin.delete_properties(prop_filter)