Skip to content
Snippets Groups Projects
Commit 6bf4557d authored by garciadeblas's avatar garciadeblas
Browse files

Update cluster list and show commands after combination of both cluster collections in NBI


Change-Id: Id121ebf7891a9f10a2653537e737f3f6df84d504
Signed-off-by: default avatargarciadeblas <gerardo.garciadeblas@telefonica.com>
parent 7dd5d3e7
No related branches found
No related tags found
No related merge requests found
Pipeline #18153 passed with stage
in 3 minutes and 21 seconds
......@@ -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(
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment