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.
15 from cmdatahandlers.api import configerror
16 from cmdatahandlers.api import config
18 class Config(config.Config):
19 def __init__(self, confman):
20 super(Config, self).__init__(confman)
21 self.ROOT = 'cloud.openstack'
22 self.DOMAIN = 'openstack'
27 def _getopenstack(self):
28 hostsconf = self.confman.get_hosts_config_handler()
29 return hostsconf.get_service_profile_hosts('controller')
32 if self._getopenstack():
34 self._validate_storage_backend()
35 self.get_admin_password()
37 def _validate_storage_backend(self):
38 backend = self.get_storage_backend()
39 storageconf = self.confman.get_storage_config_handler()
40 backends = storageconf.get_storage_backends()
41 if backend not in backends:
42 raise configerror.ConfigError('Invalid storage backend %s' % backend)
44 def get_admin_password(self):
45 """ get the admin password
53 ConfigError in-case of an error
55 if not self._getopenstack():
60 if 'admin_password' not in self.config[self.ROOT]:
61 raise configerror.ConfigError('No admin_password specified')
63 return self.config[self.ROOT]['admin_password']
65 def get_storage_backend(self):
66 """ get the openstack storage backend
70 The openstack storage backend name
74 ConfigError in-case of an error
76 if not self._getopenstack():
77 storageconf = self.confman.get_storage_config_handler()
78 enabled_backends = storageconf.get_enabled_backends()
80 return enabled_backends[0]
85 if 'storage_backend' not in self.config[self.ROOT]:
86 raise configerror.ConfigError('No storage backend configured')
88 return self.config[self.ROOT]['storage_backend']
90 def get_instance_default_backend(self):
91 """ get the openstack instance backend
95 The openstack instance backend name
99 ConfigError in-case of an error
101 if not self._getopenstack():
106 if 'instance_default_backend' not in self.config[self.ROOT]:
109 return self.config[self.ROOT]['instance_default_backend']
111 def mask_sensitive_data(self):
112 self.config[self.ROOT]['admin_password'] = self.MASK