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"
25 VNF_EMBEDDED_SOFT_EVICTION_THRESHOLD = "300Mi"
26 BM_SOFT_EVICTION_THRESHOLD = "4Gi"
27 VNF_EMBEDDED_HARD_EVICTION_THRESHOLD = "200Mi"
28 BM_HARD_EVICTION_THRESHOLD = "2Gi"
29 DEFAULT_CAAS_INFRA_LOG_TYPE = 'remote_syslog'
32 class Config(config.Config):
33 valid_redundancy_models = ['non-redundant', 'active-cold-standby']
35 def __init__(self, confman):
36 super(Config, self).__init__(confman)
37 self.ROOT = 'cloud.caas'
46 def flavour_set(self):
47 hostsconf = self.confman.get_hosts_config_handler()
49 for host in hostsconf.get_hosts():
50 if 'caas_master' in hostsconf.get_service_profiles(host):
51 caas_masters.append(host)
53 if len(caas_masters) > 1:
58 def set_dynamic_config(self):
59 if utils.is_virtualized():
60 self.config[self.ROOT]['vnf_embedded_deployment'] = self.get_vnf_flag()
61 user_conf = self.confman.get_users_config_handler()
62 self.set_caas_parameter('helm_home', "/home/{}/.helm".format(user_conf.get_admin_user()))
63 self.set_caas_parameter('flavour', self.flavour_set())
64 if not self.get_caas_parameter('dns_domain'):
65 self.set_caas_parameter('dns_domain', DEFAULT_CAAS_DNS_DOMAIN)
66 if not self.get_caas_parameter('infra_log_store'):
67 self.set_caas_parameter('infra_log_store', DEFAULT_CAAS_INFRA_LOG_TYPE)
68 if not self.get_caas_parameter('log_forwarding'):
69 self.set_caas_parameter('log_forwarding', [])
71 def set_static_config(self):
73 template = jinja2.Environment(
74 loader=jinja2.FileSystemLoader(
75 CAAS_CONFIG_FILE_PATH)).get_template(CAAS_CONFIG_FILE)
76 with open(CAAS_CONFIG_FILE_PATH + CAAS_CONFIG_FILE) as config_file:
77 data = yaml.load(config_file)
78 self.config[self.ROOT].update(
79 self._template_config(template, self.config[self.ROOT], data))
80 except jinja2.exceptions.TemplateNotFound:
83 raise configerror.ConfigError("Unexpected issue occured!")
86 def _template_config(template, base_config, initial_data):
87 config_data = initial_data.copy()
88 config_data.update(base_config)
89 output_text = template.render(config_data)
90 previous_output_text = ""
91 while output_text != previous_output_text:
92 config_data = yaml.load(output_text)
93 config_data.update(base_config)
94 output_text = template.render(config_data)
95 previous_output_text = output_text
96 return yaml.load(output_text)
98 def add_defaults(self):
99 if not self.config.get('cloud.caas', ''):
101 self.set_dynamic_config()
102 self.set_static_config()
104 def is_vnf_embedded_deployment(self):
105 return self.get_caas_only() and self.get_vnf_flag()
107 def get_vnf_flag(self):
108 return bool(self.config.get(self.ROOT, {}).get('vnf_embedded_deployment',
111 def get_caas_only(self):
112 return self.is_caas_deployment() and not self.is_openstack_deployment()
114 def is_openstack_deployment(self):
115 return bool(self.get_controller_hosts())
117 def is_caas_deployment(self):
118 return bool(self.get_caas_master_hosts())
120 def is_hybrid_deployment(self):
121 return self.is_caas_deployment() and self.is_openstack_deployment()
123 def get_caas_master_hosts(self):
124 service_profiles_lib = profiles.Profiles()
125 return self._get_hosts_for_service_profile(service_profiles_lib.get_caasmaster_service_profile())
127 def _get_hosts_for_service_profile(self, profile):
128 hostsconf = self.confman.get_hosts_config_handler()
129 return hostsconf.get_service_profile_hosts(profile)
131 def get_controller_hosts(self):
132 service_profiles_lib = profiles.Profiles()
133 return self._get_hosts_for_service_profile(service_profiles_lib.get_controller_service_profile())
135 def get_apiserver_in_hosts(self):
136 return self.config.get(self.ROOT, {}).get('apiserver_in_hosts', '')
138 def get_registry_url(self):
139 return self.config.get(self.ROOT, {}).get('registry_url', '')
141 def get_update_registry_url(self):
142 return self.config.get(self.ROOT, {}).get('update_registry_url', '')
144 def get_swift_url(self):
145 return self.config.get(self.ROOT, {}).get('swift_url', '')
147 def get_swift_update_url(self):
148 return self.config.get(self.ROOT, {}).get('swift_update_url', '')
150 def get_ldap_master_url(self):
151 return self.config.get(self.ROOT, {}).get('ldap_master_url', '')
153 def get_ldap_slave_url(self):
154 return self.config.get(self.ROOT, {}).get('ldap_slave_url', '')
156 def get_chart_repo_url(self):
157 return self.config.get(self.ROOT, {}).get('chart_repo_url', '')
159 def get_tiller_url(self):
160 return self.config.get(self.ROOT, {}).get('tiller_url', '')
162 def get_apiserver_svc_ip(self):
163 return self.config.get(self.ROOT, {}).get('apiserver_svc_ip', '')
165 def get_caas_parameter(self, parameter):
166 return self.config.get(self.ROOT, {}).get(parameter, '')
168 def set_caas_parameter(self, parameter, value):
169 self.config[self.ROOT][parameter] = value
171 def get_kubernetes_domain(self):
172 return 'kubernetes.default.svc.{}'.format(
173 self.config.get(self.ROOT, {}).get('dns_domain', ''))
175 def get_caas_soft_eviction_threshold(self):
176 if self.is_vnf_embedded_deployment():
177 return VNF_EMBEDDED_SOFT_EVICTION_THRESHOLD
179 return BM_SOFT_EVICTION_THRESHOLD
181 def get_caas_hard_eviction_threshold(self):
182 if self.is_vnf_embedded_deployment():
183 return VNF_EMBEDDED_HARD_EVICTION_THRESHOLD
185 return BM_HARD_EVICTION_THRESHOLD