X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=ta%2Fconfig-manager.git;a=blobdiff_plain;f=cmdatahandlers%2Fsrc%2Fcmdatahandlers%2Fhosts%2Fconfig.py;h=7547dbe194ec542a38b2ed81d8d0453b09f5a129;hp=e8bc78b691c23ba2c7be2fcd2820d65fdbaedf47;hb=87d5aa1e6151010af819612a0a953ee90431607e;hpb=c389bdee7b3845b55f443dbf04c0ce4083a55886 diff --git a/cmdatahandlers/src/cmdatahandlers/hosts/config.py b/cmdatahandlers/src/cmdatahandlers/hosts/config.py index e8bc78b..7547dbe 100644 --- a/cmdatahandlers/src/cmdatahandlers/hosts/config.py +++ b/cmdatahandlers/src/cmdatahandlers/hosts/config.py @@ -19,6 +19,10 @@ from cmdatahandlers.api import config from cmdatahandlers.api import utils from serviceprofiles import profiles +VNF_EMBEDDED_RESERVED_MEMORY = "512Mi" +DUAL_VIM_CONTROLLER_RESERVED_MEMORY = "64Gi" +DUAL_VIM_DEFAULT_RESERVED_MEMORY = "32Gi" +MIDDLEWARE_RESERVED_MEMORY = "12Gi" class Config(config.Config): def __init__(self, confman): @@ -78,6 +82,28 @@ class Config(config.Config): cidr = netconf.get_network_cidr(hwmgmtnet, domain) utils.validate_ip_in_network(ip, cidr) + def get_hwmgmt_priv_level(self, hostname): + """get the hwmgmt IPMI privilege level. Defaults to ADMINISTRATOR + + Arguments: + + hostname: The name of the node + + Return: + + The prvilege level, or ADMINISTRATOR if unspecified + + Raise: + + ConfigError in-case of an error + """ + self._validate_hostname(hostname) + + if 'hwmgmt' not in self.config[self.ROOT][hostname]: + raise configerror.ConfigError('No hwmgmt info defined for host') + + return self.config[self.ROOT][hostname]['hwmgmt'].get('priv_level', 'ADMINISTRATOR') + def _validate_service_profiles(self, hostname): node_profiles = self.get_service_profiles(hostname) utils.validate_list_items_unique(node_profiles) @@ -142,18 +168,19 @@ class Config(config.Config): return sorted(self.config[self.ROOT].keys()) def get_labels(self, hostname): - noderole_label = "node-role.kubernetes.io/{}".format(self.get_noderole(hostname)) mandatory_labels = \ {"nodetype": self.get_nodetype(hostname), "nodeindex": self.get_nodeindex(hostname), - "nodename": self.get_nodename(hostname), - noderole_label: ""} + "nodename": self.get_nodename(hostname)} labels = self.config[self.ROOT][hostname].get('labels', {}).copy() labels.update(mandatory_labels) if self.is_sriov_enabled(hostname): labels.update({"sriov": "enabled"}) + if self.is_localstorage_used(hostname): + labels.update({"localstorage": "enabled"}) + black_list = ['name'] return {name: attributes for name, attributes in labels.iteritems() @@ -170,8 +197,29 @@ class Config(config.Config): return service_profiles[0] + def set_noderole(self): + hosts = self.get_hosts() + for host in hosts: + self.config[self.ROOT][host]['noderole'] = self.get_noderole(host) + + def set_nodeindex(self): + hostsconf = self.confman.get_hosts_config_handler() + install_host = utils.get_installation_host_name(hostsconf) + self.config[self.ROOT][install_host]['caas_nodeindex'] = 1 + + masters = self.get_service_profile_hosts('caas_master') + masters.remove(install_host) + self._set_nodeindexes(masters, 2) + self._set_nodeindexes(self.get_service_profile_hosts('caas_worker'), 1) + + def _set_nodeindexes(self, hosts, base_index): + index = base_index + for host in hosts: + self.config[self.ROOT][host]['caas_nodeindex'] = index + index += 1 + def get_nodeindex(self, hostname): - return re.search(r'[-_](\d+)$', hostname).group(1) + return self.config[self.ROOT][hostname]['caas_nodeindex'] def get_nodename(self, hostname): return "{}{}".format(self.get_nodetype(hostname), self.get_nodeindex(hostname)) @@ -192,6 +240,16 @@ class Config(config.Config): return True return False + def is_localstorage_used(self, hostname): + storageprofs = self.get_storage_profiles(hostname) + storageprofconf = self.confman.get_storage_profiles_config_handler() + for profile in storageprofs: + if "shared" in self.config[storageprofconf.ROOT][profile]: + for volume in self.config[storageprofconf.ROOT][profile]["shared"]["volumes"]: + if volume["name"] == 'caas_app': + return True + return False + def get_enabled_hosts(self): """ get the list of enabled hosts in the cloud @@ -808,8 +866,35 @@ class Config(config.Config): osd_disks = filter(lambda disk: disk.get('osd_disk', False), caas_disks) return map(lambda disk: _get_path_for_virtio_id(disk), osd_disks) + def get_system_reserved_memory(self, hostname): + caasconf = self.confman.get_caas_config_handler() + if caasconf.is_vnf_embedded_deployment(): + return VNF_EMBEDDED_RESERVED_MEMORY + + profiles = self.get_service_profiles(hostname) + if 'controller' in profiles: + return DUAL_VIM_CONTROLLER_RESERVED_MEMORY + if 'compute' in profiles: + return DUAL_VIM_DEFAULT_RESERVED_MEMORY + + return self.config.get(self.ROOT, {}).get('middleware_reserved_memory', + MIDDLEWARE_RESERVED_MEMORY) + + def set_default_reserved_memory_to_all_hosts(self, def_memory): + for host in self.get_hosts(): + self.config[self.ROOT][host]['middleware_reserved_memory'] = def_memory + + def set_default_ipmi_priv_level_to_all_hosts(self, def_priv): + for host in self.get_hosts(): + if 'hwmgmt' not in self.config[self.ROOT][host]: + self.config[self.ROOT][host]['hwmgmt'] = {'priv_level': def_priv} + elif 'priv_level' not in self.config[self.ROOT][host]['hwmgmt']: + self.config[self.ROOT][host]['hwmgmt']['priv_level'] = def_priv + def _get_path_for_virtio_id(disk): disk_id = disk.get('id', '') if disk_id: return "/dev/disk/by-id/virtio-{}".format(disk_id[:20]) + +