# For those usages not covered by the Apache License, Version 2.0 please
# contact with: nfvlabs@tid.es
##
+from typing import Union
import os
import yaml
return True
async def inspect_kdu(self, kdu_model: str, repo_url: str = None) -> str:
-
self.log.debug(
"inspect kdu_model {} from (optional) repo: {}".format(kdu_model, repo_url)
)
return namespace in namespaces if namespaces else False
async def _get_namespaces(self, cluster_id: str):
-
self.log.debug("get namespaces cluster_id {}".format(cluster_id))
# init config, env
return namespaces
async def _create_namespace(self, cluster_id: str, namespace: str):
-
self.log.debug(f"create namespace: {cluster_id} for cluster_id: {namespace}")
# init config, env
async def _get_services(
self, cluster_id: str, kdu_instance: str, namespace: str, kubeconfig: str
):
-
# init config, env
paths, env = self._init_paths_env(
cluster_name=cluster_id, create_if_not_exist=True
pass
async def _instances_list(self, cluster_id: str):
-
# init paths, env
paths, env = self._init_paths_env(
cluster_name=cluster_id, create_if_not_exist=True
cluster_id: str,
kdu_instance: str,
namespace: str = None,
+ yaml_format: bool = False,
show_error_log: bool = False,
- return_text: bool = False,
- ):
-
+ ) -> Union[str, dict]:
self.log.debug(
"status of kdu_instance: {}, namespace: {} ".format(kdu_instance, namespace)
)
env=env,
)
- if return_text:
+ if yaml_format:
return str(output)
if rc != 0:
# remove field 'notes' and manifest
try:
del data.get("info")["notes"]
- del data["manifest"]
except KeyError:
pass
- # unable to parse 'resources' as currently it is not included in helm3
+ # parse the manifest to a list of dictionaries
+ if "manifest" in data:
+ manifest_str = data.get("manifest")
+ manifest_docs = yaml.load_all(manifest_str, Loader=yaml.SafeLoader)
+
+ data["manifest"] = []
+ for doc in manifest_docs:
+ data["manifest"].append(doc)
+
return data
def _get_install_command(
timeout: float,
kubeconfig: str,
) -> str:
-
timeout_str = ""
if timeout:
timeout_str = "--timeout {}s".format(timeout)
timeout: float,
kubeconfig: str,
) -> str:
-
timeout_str = ""
if timeout:
timeout_str = "--timeout {}s".format(timeout)
def _get_uninstall_command(
self, kdu_instance: str, namespace: str, kubeconfig: str
) -> str:
-
return "env KUBECONFIG={} {} uninstall {} --namespace={}".format(
kubeconfig, self._helm_command, kdu_instance, namespace
)