4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 from cmframework.apis import cmuserconfig
17 from cmframework.apis import cmerror
18 from cmdatahandlers.api import configerror
21 class storagehandler(cmuserconfig.CMUserConfigPlugin):
24 super(storagehandler, self).__init__()
25 self.hosts_config_handler = None
26 self.storage_config_handler = None
27 self.openstack_config_handler = None
30 def _managements(self):
31 return self.hosts_config_handler.get_service_profile_hosts('management')
35 return self.hosts_config_handler.get_service_profile_hosts('storage')
39 return self.openstack_config_handler.get_storage_backend()
42 def _storage_backends(self):
43 return self.storage_config_handler.get_storage_backends()
45 def _set_handlers(self, confman):
46 self.storage_config_handler = confman.get_storage_config_handler()
47 self.hosts_config_handler = confman.get_hosts_config_handler()
48 self.openstack_config_handler = confman.get_openstack_config_handler()
50 def handle(self, confman):
51 """TODO: Set these dynamically according to user configuration instead."""
53 self._set_handlers(confman)
54 if (self._backend == 'ceph') and ('ceph' in self._storage_backends):
55 if self.storage_config_handler.is_ceph_enabled():
56 self.storage_config_handler.set_mons(self._managements)
57 self.storage_config_handler.set_ceph_mons(self._managements)
58 self.storage_config_handler.set_osds(self._storages)
61 except configerror.ConfigError as exp:
62 raise cmerror.CMError(str(exp))