Reformat files according to new black validation
[osm/LCM.git] / osm_lcm / lcm.py
index 9f0e310..723ca7a 100644 (file)
@@ -28,7 +28,6 @@ import logging
 import logging.handlers
 import getopt
 import sys
-import configparser
 
 from osm_lcm import ns, vim_sdn, netslice
 from osm_lcm.ng_ro import NgRoException, NgRoClient
@@ -64,7 +63,6 @@ min_common_version = "0.1.19"
 
 
 class Lcm:
-
     ping_interval_pace = (
         120  # how many time ping is send once is confirmed all is running
     )
@@ -349,6 +347,13 @@ class Lcm:
                     "k8scluster", k8scluster_id, order_id, "k8scluster_create", task
                 )
                 return
+            elif command == "edit" or command == "edited":
+                k8scluster_id = params.get("_id")
+                task = asyncio.ensure_future(self.k8scluster.edit(params, order_id))
+                self.lcm_tasks.register(
+                    "k8scluster", k8scluster_id, order_id, "k8scluster_edit", task
+                )
+                return
             elif command == "delete" or command == "deleted":
                 k8scluster_id = params.get("_id")
                 task = asyncio.ensure_future(self.k8scluster.delete(params, order_id))
@@ -362,6 +367,11 @@ class Lcm:
                 task = asyncio.ensure_future(self.vca.create(params, order_id))
                 self.lcm_tasks.register("vca", vca_id, order_id, "vca_create", task)
                 return
+            elif command == "edit" or command == "edited":
+                vca_id = params.get("_id")
+                task = asyncio.ensure_future(self.vca.edit(params, order_id))
+                self.lcm_tasks.register("vca", vca_id, order_id, "vca_edit", task)
+                return
             elif command == "delete" or command == "deleted":
                 vca_id = params.get("_id")
                 task = asyncio.ensure_future(self.vca.delete(params, order_id))
@@ -481,7 +491,7 @@ class Lcm:
                             db_nsr["config-status"],
                             db_nsr["detailed-status"],
                             db_nsr["_admin"]["deployed"],
-                            self.lcm_ns_tasks.get(nsr_id),
+                            self.lcm_tasks.task_registry["ns"].get(nsr_id, ""),
                         )
                     )
                 except Exception as e:
@@ -543,7 +553,7 @@ class Lcm:
                             db_nsir["config-status"],
                             db_nsir["detailed-status"],
                             db_nsir["_admin"]["deployed"],
-                            self.lcm_netslice_tasks.get(nsir_id),
+                            self.lcm_tasks.task_registry["nsi"].get(nsir_id, ""),
                         )
                     )
                 except Exception as e:
@@ -696,7 +706,6 @@ class Lcm:
         self.logger.debug("Task kafka_read exit")
 
     def start(self):
-
         # check RO version
         self.loop.run_until_complete(self.check_RO_version())
 
@@ -750,37 +759,12 @@ class Lcm:
             self.fs.fs_disconnect()
 
     def read_config_file(self, config_file):
-        # TODO make a [ini] + yaml inside parser
-        # the configparser library is not suitable, because it does not admit comments at the end of line,
-        # and not parse integer or boolean
-        conf = {}
         try:
-            # read file as yaml format
-            config = configparser.ConfigParser(inline_comment_prefixes="#")
-            config.read(config_file)
-            conf = {s: dict(config.items(s)) for s in config.sections()}
+            with open(config_file) as f:
+                return yaml.safe_load(f)
         except Exception as e:
             self.logger.critical("At config file '{}': {}".format(config_file, e))
-            self.logger.critical("Trying to load config as legacy mode")
-            try:
-                with open(config_file) as f:
-                    conf = yaml.safe_load(f)
-                # Ensure all sections are not empty
-                for k in (
-                    "global",
-                    "timeout",
-                    "RO",
-                    "VCA",
-                    "database",
-                    "storage",
-                    "message",
-                ):
-                    if not conf.get(k):
-                        conf[k] = {}
-            except Exception as e:
-                self.logger.critical("At config file '{}': {}".format(config_file, e))
-                exit(1)
-        return conf
+            exit(1)
 
     @staticmethod
     def get_process_id():
@@ -818,7 +802,6 @@ def usage():
 
 
 if __name__ == "__main__":
-
     try:
         # print("SYS.PATH='{}'".format(sys.path))
         # load parameters and configuration