Update cluster list and show commands after combination of both cluster collections... 73/14873/2
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Mon, 13 Jan 2025 10:09:43 +0000 (11:09 +0100)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Thu, 16 Jan 2025 23:52:09 +0000 (00:52 +0100)
Change-Id: Id121ebf7891a9f10a2653537e737f3f6df84d504
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osmclient/cli_commands/cluster.py
osmclient/sol005/cluster.py

index 4cb15b9..6f4b56f 100755 (executable)
@@ -133,7 +133,7 @@ def cluster_list(ctx, filter, output):
         },
     ]
     common.generic_list(
-        callback=ctx.obj.cluster.list_both,
+        callback=ctx.obj.cluster.enhanced_list,
         filter=filter,
         format=output,
         extras=extra_items,
@@ -153,7 +153,7 @@ def cluster_show(ctx, name, output):
     NAME: name or ID of the K8s cluster
     """
     logger.debug("")
-    common.generic_show(callback=ctx.obj.cluster.get_both, name=name, format=output)
+    common.generic_show(callback=ctx.obj.cluster.get, name=name, format=output)
 
 
 @click.command(
index 2665351..b1291c2 100644 (file)
@@ -134,30 +134,17 @@ class Cluster(GenericOSMAPIObject):
         endpoint_suffix = f"{item['_id']}/update"
         self.generic_operation(cluster_changes, endpoint_suffix=endpoint_suffix)
 
-    def list_both(self, filter=None):
-        """List all clusters from both new and old APIs"""
+    def enhanced_list(self, filter=None):
+        """List all clusters with additional resolution (VIM)"""
         self._logger.debug("")
-        cluster_list1 = self.list(filter)
-        cluster_list2 = self._client.k8scluster.list(filter)
-        list1_names = {item["name"] for item in cluster_list1}
-        for item in cluster_list2:
-            if item["name"] not in list1_names:
-                # Complete the information for clusters from old API
-                item["state"] = "N/A"
-                old_state = item.get("_admin", {}).get("operationalState", "Unknown")
-                item["bootstrap"] = "NO"
-                item["operatingState"] = "N/A"
-                item["resourceState"] = old_state
-                item["created"] = "NO"
-                cluster_list1.append(item)
-        # Complete cluster info with vim_account name and vim_type
+        cluster_list = self.list(filter)
         vim_list = self._client.vim.list()
         self._logger.debug(f"VIM list: {vim_list}")
         if not vim_list:
             self._logger.warning(
                 "Could not complete cluster info with VIM account info"
             )
-        for item in cluster_list1:
+        for item in cluster_list:
             vim_id = item["vim_account"]
             vim_name, vim_type = next(
                 (
@@ -168,20 +155,4 @@ class Cluster(GenericOSMAPIObject):
                 (None, None),
             )
             item["vim_account"] = f"{vim_name} ({vim_type})"
-        return cluster_list1
-
-    def get_both(self, name):
-        """
-        Gets and shows an individual cluster
-        from both new and old API
-        """
-        self._logger.debug("")
-        try:
-            cluster = self.get(name)
-            return cluster
-        except NotFound:
-            try:
-                cluster2 = self._client.k8scluster.get(name)
-                return cluster2
-            except NotFound:
-                raise NotFound(f"{self._logObjectName} {name} not found")
+        return cluster_list