Node index refactor 13/1213/1
authorBalint Varga <balint.varga@nokia.com>
Wed, 17 Jul 2019 08:52:19 +0000 (10:52 +0200)
committerBalint Varga <balint.varga@nokia.com>
Wed, 17 Jul 2019 08:52:19 +0000 (10:52 +0200)
In case of node indexing started from contorller-0,
caas node indexing failed.
Correction: new indexing method

Signed-off-by: Balint Varga <balint.varga@nokia.com>
Change-Id: I4bbdf8600c8edc95492af2df2098493a48c5bfb9

cmdatahandlers/src/cmdatahandlers/api/utils.py
cmdatahandlers/src/cmdatahandlers/caas/config.py
cmdatahandlers/src/cmdatahandlers/hosts/config.py

index 5e15a46..590d3e3 100644 (file)
@@ -133,6 +133,13 @@ def is_virtualized():
             return True
     return False
 
+def get_installation_host_name(hostsconf):
+    hostname = 'controller-1'
+    if not is_virtualized():
+        ownip = get_own_hwmgmt_ip()
+        hostname = hostsconf.get_host_having_hwmgmt_address(ownip)
+    return hostname
+
 def flatten_config_data(jsondata):
     result = {}
     for key, value in jsondata.iteritems():
index ed5c236..e5275c5 100644 (file)
@@ -67,6 +67,8 @@ class Config(config.Config):
             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:
index a9a445e..4d46459 100644 (file)
@@ -196,8 +196,24 @@ class Config(config.Config):
 
         return service_profiles[0]
 
+    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))