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"
24 DEFAULT_CAAS_DNS_DOMAIN = "rec.io"
27 class Config(config.Config):
28 valid_redundancy_models = ['non-redundant', 'active-cold-standby']
30 def __init__(self, confman):
31 super(Config, self).__init__(confman)
32 self.ROOT = 'cloud.caas'
41 def flavour_set(self):
42 hostsconf = self.confman.get_hosts_config_handler()
44 for host in hostsconf.get_hosts():
45 if 'caas_master' in hostsconf.get_service_profiles(host):
46 caas_masters.append(host)
48 if len(caas_masters) > 1:
53 def set_dynamic_config(self):
54 if utils.is_virtualized():
55 self.config[self.ROOT]['vnf_embedded_deployment'] = self.get_vnf_flag()
56 user_conf = self.confman.get_users_config_handler()
57 self.config[self.ROOT]['helm_home'] = "/home/" + user_conf.get_admin_user() + "/.helm"
58 self.config[self.ROOT]['flavour'] = self.flavour_set()
59 if not self.config[self.ROOT].get('dns_domain', ""):
60 self.config[self.ROOT]['dns_domain'] = DEFAULT_CAAS_DNS_DOMAIN
62 def set_static_config(self):
64 template = jinja2.Environment(
65 loader=jinja2.FileSystemLoader(
66 CAAS_CONFIG_FILE_PATH)).get_template(CAAS_CONFIG_FILE)
67 with open(CAAS_CONFIG_FILE_PATH + CAAS_CONFIG_FILE) as config_file:
68 data = yaml.load(config_file)
69 self.config[self.ROOT].update(
70 self._template_config(template, self.config[self.ROOT], data))
71 except jinja2.exceptions.TemplateNotFound:
74 raise configerror.ConfigError("Unexpected issue occured!")
76 def _template_config(self, template, base_config, initial_data):
77 config_data = initial_data.copy()
78 config_data.update(base_config)
79 outputText = template.render(config_data)
80 previousOutputText = ""
81 while outputText != previousOutputText:
82 config_data = yaml.load(outputText)
83 config_data.update(base_config)
84 outputText = template.render(config_data)
85 previousOutputText = outputText
86 return yaml.load(outputText)
88 def add_defaults(self):
89 if not self.config.get('cloud.caas', ''):
91 self.set_dynamic_config()
92 self.set_static_config()
94 def is_vnf_embedded_deployment(self):
95 return (self.get_caas_only() and self.get_vnf_flag())
97 def get_vnf_flag(self):
98 return bool(self.config.get(self.ROOT, {}).get('vnf_embedded_deployment',
101 def get_caas_only(self):
102 return self.is_caas_deployment() and not self.is_openstack_deployment()
104 def is_openstack_deployment(self):
105 return bool(self.get_controller_hosts())
107 def is_caas_deployment(self):
108 return bool(self.get_caas_master_hosts())
110 def is_hybrid_deployment(self):
111 return self.is_caas_deployment() and self.is_openstack_deployment()
113 def get_caas_master_hosts(self):
114 service_profiles_lib = profiles.Profiles()
115 return self._get_hosts_for_service_profile(service_profiles_lib.get_caasmaster_service_profile())
117 def _get_hosts_for_service_profile(self, profile):
118 hostsconf = self.confman.get_hosts_config_handler()
119 return hostsconf.get_service_profile_hosts(profile)
121 def get_controller_hosts(self):
122 service_profiles_lib = profiles.Profiles()
123 return self._get_hosts_for_service_profile(service_profiles_lib.get_controller_service_profile())
125 def get_apiserver_in_hosts(self):
126 return self.config.get(self.ROOT, {}).get('apiserver_in_hosts', '')
128 def get_registry_url(self):
129 return self.config.get(self.ROOT, {}).get('registry_url', '')
131 def get_update_registry_url(self):
132 return self.config.get(self.ROOT, {}).get('update_registry_url', '')
134 def get_swift_url(self):
135 return self.config.get(self.ROOT, {}).get('swift_url', '')
137 def get_swift_update_url(self):
138 return self.config.get(self.ROOT, {}).get('swift_update_url', '')
140 def get_ldap_master_url(self):
141 return self.config.get(self.ROOT, {}).get('ldap_master_url', '')
143 def get_ldap_slave_url(self):
144 return self.config.get(self.ROOT, {}).get('ldap_slave_url', '')
146 def get_chart_repo_url(self):
147 return self.config.get(self.ROOT, {}).get('chart_repo_url', '')
149 def get_tiller_url(self):
150 return self.config.get(self.ROOT, {}).get('tiller_url', '')
152 def get_apiserver_svc_ip(self):
153 return self.config.get(self.ROOT, {}).get('apiserver_svc_ip', '')
155 def get_caas_parameter(self, parameter):
156 return self.config.get(self.ROOT, {}).get(parameter, '')
158 def get_kubernetes_domain(self):
159 return 'kubernetes.default.svc.{}'.format(
160 self.config.get(self.ROOT, {}).get('dns_domain', ''))