from serviceprofiles import profiles
import yaml
import jinja2
+import string
+from random import choice
CAAS_CONFIG_FILE_PATH = "/etc/cmframework/config/"
CAAS_CONFIG_FILE = "caas.yaml"
BM_SOFT_EVICTION_THRESHOLD = "4Gi"
VNF_EMBEDDED_HARD_EVICTION_THRESHOLD = "200Mi"
BM_HARD_EVICTION_THRESHOLD = "2Gi"
-DEFAULT_CAAS_INFRA_LOG_TYPE = 'remote_syslog'
+ADMIN_PWD_LENGTH = 20
+DEFAULT_CAAS_INFRA_LOG_TYPE = 'elasticsearch'
+AUDIT_DISK_LIMIT = 0.87
+CAAS_AUDIT_DISK_RATIO = 0.25
class Config(config.Config):
def init(self):
pass
- def validate(self):
+ @staticmethod
+ def validate():
print("validate")
def flavour_set(self):
for host in hostsconf.get_hosts():
if 'caas_master' in hostsconf.get_service_profiles(host):
caas_masters.append(host)
-
- if len(caas_masters) > 1:
- return "multi"
+ return "multi" if len(caas_masters) > 1 else "single"
+
+ def get_caas_max_audit_size(self):
+ if self.is_caas_deployment():
+ return self.get_audit_disk_limit()*self.get_audit_disk_ratio()
else:
- return "single"
+ return 0
def set_dynamic_config(self):
if utils.is_virtualized():
user_conf = self.confman.get_users_config_handler()
self.set_caas_parameter('helm_home', "/home/{}/.helm".format(user_conf.get_admin_user()))
self.set_caas_parameter('flavour', self.flavour_set())
+ self.config[self.ROOT]['caas_max_audit_size'] = self.get_caas_max_audit_size()
+ admin_pwd = self.get_caas_parameter('admin_password')
+ self.config[self.ROOT]['admin_password'] = \
+ admin_pwd if admin_pwd != '' else self.generate_pwd(ADMIN_PWD_LENGTH)
if not self.get_caas_parameter('dns_domain'):
self.set_caas_parameter('dns_domain', DEFAULT_CAAS_DNS_DOMAIN)
if not self.get_caas_parameter('infra_log_store'):
self.set_caas_parameter('infra_log_store', DEFAULT_CAAS_INFRA_LOG_TYPE)
if not self.get_caas_parameter('log_forwarding'):
self.set_caas_parameter('log_forwarding', [])
+ hostsconf = self.confman.get_hosts_config_handler()
+ hostsconf.set_nodeindex()
def set_static_config(self):
try:
except jinja2.exceptions.TemplateNotFound:
return
except Exception:
- raise configerror.ConfigError("Unexpected issue occured!")
+ raise configerror.ConfigError("Unexpected issue has occured!")
+
+ def set_post_config(self):
+ self.config[self.ROOT]['swift_credential'] = \
+ dict(
+ user=self.get_caas_parameter('swift_credential').get('user'),
+ tenant=self.get_caas_parameter('swift_credential').get('tenant'),
+ password=self.generate_pwd(ADMIN_PWD_LENGTH)
+ )
@staticmethod
def _template_config(template, base_config, initial_data):
return
self.set_dynamic_config()
self.set_static_config()
+ self.set_post_config()
def is_vnf_embedded_deployment(self):
return self.get_caas_only() and self.get_vnf_flag()
def set_caas_parameter(self, parameter, value):
self.config[self.ROOT][parameter] = value
+ def get_admin_password(self):
+ return self.config.get(self.ROOT, {}).get('admin_password')
+
+ @staticmethod
+ def generate_pwd(pwd_length):
+ character_pool = string.ascii_letters + string.digits
+ return ''.join(choice(character_pool) for i in range(pwd_length))
+
def get_kubernetes_domain(self):
return 'kubernetes.default.svc.{}'.format(
self.config.get(self.ROOT, {}).get('dns_domain', ''))
return VNF_EMBEDDED_HARD_EVICTION_THRESHOLD
else:
return BM_HARD_EVICTION_THRESHOLD
+
+ def get_audit_disk_ratio(self):
+ return CAAS_AUDIT_DISK_RATIO
+
+ def get_audit_disk_limit(self):
+ return AUDIT_DISK_LIMIT