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 config
16 from cmdatahandlers.api import utils
17 from cmdatahandlers.api import configerror
18 from serviceprofiles import profiles
22 CAAS_CONFIG_FILE_PATH = "/etc/cmframework/config/"
23 CAAS_CONFIG_FILE = "caas.yaml"
26 class Config(config.Config):
27 valid_redundancy_models = ['non-redundant', 'active-cold-standby']
29 def __init__(self, confman):
30 super(Config, self).__init__(confman)
31 self.ROOT = 'cloud.caas'
40 def flavour_set(self):
41 hostsconf = self.confman.get_hosts_config_handler()
43 for host in hostsconf.get_hosts():
44 if 'caas_master' in hostsconf.get_service_profiles(host):
45 caas_masters.append(host)
47 if len(caas_masters) > 1:
52 def set_dynamic_config(self):
53 if utils.is_virtualized():
54 self.config[self.ROOT]['vnf_embedded_deployment'] = self.get_vnf_flag()
55 user_conf = self.confman.get_users_config_handler()
56 self.config[self.ROOT]['helm_home'] = "/home/" + user_conf.get_admin_user() + "/.helm"
57 self.config[self.ROOT]['flavour'] = self.flavour_set()
59 def set_static_config(self):
61 template = jinja2.Environment(
62 loader=jinja2.FileSystemLoader(
63 CAAS_CONFIG_FILE_PATH)).get_template(CAAS_CONFIG_FILE)
64 with open(CAAS_CONFIG_FILE_PATH + CAAS_CONFIG_FILE) as config_file:
65 data = yaml.load(config_file)
66 outputText = template.render(data)
67 config_data = yaml.load(outputText)
68 for key in config_data:
69 self.config[self.ROOT][key] = config_data[key]
70 except jinja2.exceptions.TemplateNotFound:
73 raise configerror.ConfigError("Unexpected issue occured!")
75 def add_defaults(self):
76 if not self.config.get('cloud.caas', ''):
78 self.set_dynamic_config()
79 self.set_static_config()
81 def is_vnf_embedded_deployment(self):
82 return (self.get_caas_only() and self.get_vnf_flag())
84 def get_vnf_flag(self):
85 return bool(self.config.get(self.ROOT, {}).get('vnf_embedded_deployment',
88 def get_caas_only(self):
89 return self.is_caas_deployment() and not self.is_openstack_deployment()
91 def is_openstack_deployment(self):
92 return bool(self.get_controller_hosts())
94 def is_caas_deployment(self):
95 return bool(self.get_caas_master_hosts())
97 def is_hybrid_deployment(self):
98 return self.is_caas_deployment() and self.is_openstack_deployment()
100 def get_caas_master_hosts(self):
101 service_profiles_lib = profiles.Profiles()
102 return self._get_hosts_for_service_profile(service_profiles_lib.get_caasmaster_service_profile())
104 def _get_hosts_for_service_profile(self, profile):
105 hostsconf = self.confman.get_hosts_config_handler()
106 return hostsconf.get_service_profile_hosts(profile)
108 def get_controller_hosts(self):
109 service_profiles_lib = profiles.Profiles()
110 return self._get_hosts_for_service_profile(service_profiles_lib.get_controller_service_profile())
112 def get_apiserver_in_hosts(self):
113 return self.config.get(self.ROOT, {}).get('apiserver_in_hosts', '')
115 def get_registry_url(self):
116 return self.config.get(self.ROOT, {}).get('registry_url', '')
118 def get_update_registry_url(self):
119 return self.config.get(self.ROOT, {}).get('update_registry_url', '')
121 def get_swift_url(self):
122 return self.config.get(self.ROOT, {}).get('swift_url', '')
124 def get_swift_update_url(self):
125 return self.config.get(self.ROOT, {}).get('swift_update_url', '')
127 def get_ldap_master_url(self):
128 return self.config.get(self.ROOT, {}).get('ldap_master_url', '')
130 def get_ldap_slave_url(self):
131 return self.config.get(self.ROOT, {}).get('ldap_slave_url', '')
133 def get_chart_repo_url(self):
134 return self.config.get(self.ROOT, {}).get('chart_repo_url', '')
136 def get_tiller_url(self):
137 return self.config.get(self.ROOT, {}).get('tiller_url', '')
139 def get_apiserver_svc_ip(self):
140 return self.config.get(self.ROOT, {}).get('apiserver_svc_ip', '')
142 def get_caas_parameter(self, parameter):
143 return self.config.get(self.ROOT, {}).get(parameter, '')