openstack storage backend check removed
[ta/cm-plugins.git] / userconfighandlers / storagehandler / storagehandler.py
1 #! /usr/bin/python
2 # Copyright 2019 Nokia
3 #
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
7 #
8 #    http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15
16 from cmframework.apis import cmuserconfig
17 from cmframework.apis import cmerror
18 from cmdatahandlers.api import configerror
19
20
21 class storagehandler(cmuserconfig.CMUserConfigPlugin):
22
23     def __init__(self):
24         super(storagehandler, self).__init__()
25         self.hosts_config_handler = None
26         self.storage_config_handler = None
27         self.openstack_config_handler = None
28
29     @property
30     def _managements(self):
31         return self.hosts_config_handler.get_service_profile_hosts('management')
32
33     @property
34     def _storages(self):
35         return self.hosts_config_handler.get_service_profile_hosts('storage')
36
37     @property
38     def _backend(self):
39         return self.openstack_config_handler.get_storage_backend()
40
41     @property
42     def _storage_backends(self):
43         return self.storage_config_handler.get_storage_backends()
44
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()
49
50     def handle(self, confman):
51         """TODO: Set these dynamically according to user configuration instead."""
52         try:
53             self._set_handlers(confman)
54             if ('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)
59
60
61         except configerror.ConfigError as exp:
62             raise cmerror.CMError(str(exp))