Feature-9904: Enhancing NG-UI to enable Juju operational view dashboard
Added functions to get action list, config list and executed action list for KNF
Change-Id: Ibec764c719da5507168c474cf48fc23efbb9c846
Signed-off-by: jayaramans <selvi.j@tataelxsi.co.in>
Signed-off-by: ksaikiranr <saikiran.k@tataelxsi.co.in>
diff --git a/n2vc/utils.py b/n2vc/utils.py
index 16a4733..6e0f2c0 100644
--- a/n2vc/utils.py
+++ b/n2vc/utils.py
@@ -15,6 +15,7 @@
import base64
import re
import binascii
+import yaml
from enum import Enum
from juju.machine import Machine
from juju.application import Application
@@ -120,3 +121,33 @@
)
}
)
+
+
+def obj_to_yaml(obj: object) -> str:
+ """
+ Converts object to yaml format
+ :return: yaml data
+ """
+ # dump to yaml
+ dump_text = yaml.dump(obj, default_flow_style=False, indent=2)
+ # split lines
+ lines = dump_text.splitlines()
+ # remove !!python/object tags
+ yaml_text = ""
+ for line in lines:
+ index = line.find("!!python/object")
+ if index >= 0:
+ line = line[:index]
+ yaml_text += line + "\n"
+ return yaml_text
+
+
+def obj_to_dict(obj: object) -> dict:
+ """
+ Converts object to dictionary format
+ :return: dict data
+ """
+ # convert obj to yaml
+ yaml_text = obj_to_yaml(obj)
+ # parse to dict
+ return yaml.load(yaml_text, Loader=yaml.Loader)