Simplify check of region and resource group in cluster creation 12/14512/3
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Thu, 15 Aug 2024 08:00:42 +0000 (10:00 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Fri, 16 Aug 2024 16:55:25 +0000 (18:55 +0200)
Change-Id: I4f2b2d434c33f1bebe0388098fdc316d726a8f5a
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osm_nbi/k8s_topics.py

index 2ce01e0..b065c12 100644 (file)
@@ -244,26 +244,22 @@ class K8sTopic(BaseTopic):
 
     def _create_cluster(self, cls_request, rollback, session, indata, kwargs, headers):
         # Check whether the region name and resource group have been given
-        v = "Not_present"
-        t = "Not_present"
-        for key, value in indata.items():
-            if key == "region_name":
-                v = "Present"
-            if key == "resource_group":
-                t = "Present"
+        region_given = "region_name" in indata
+        resource_group_given = "resource_group" in indata
 
         # Get the vim_account details
         vim_account_details = self.db.get_one(
             "vim_accounts", {"name": cls_request["vim_account"]}
         )
 
-        if v == "Not_present" and t == "Not_present":
+        # Check whether the region name and resource group have been given
+        if not region_given and not resource_group_given:
             region_name = vim_account_details["config"]["region_name"]
             resource_group = vim_account_details["config"]["resource_group"]
-        elif v == "Present" and t == "Not_present":
+        elif region_given and not resource_group_given:
             region_name = cls_request["region_name"]
             resource_group = vim_account_details["config"]["resource_group"]
-        elif v == "Not_present" and t == "Present":
+        elif not region_given and resource_group_given:
             region_name = vim_account_details["config"]["region_name"]
             resource_group = cls_request["resource_group"]
         else: