]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: move assorted data manipulation funcs to data_utils.py
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 16 Aug 2023 20:14:01 +0000 (16:14 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 30 Aug 2023 17:59:10 +0000 (13:59 -0400)
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Pair-programmed-with: Adam King <adking@redhat.com>
Co-authored-by: Adam King <adking@redhat.com>
src/cephadm/cephadm.py
src/cephadm/cephadmlib/data_utils.py [new file with mode: 0644]

index 48f4b6a0aaea80faf36731a8e0a808fe648b356a..303ba4f8d25707cc4ffec8c5f4542aaea611fd4e 100755 (executable)
@@ -109,6 +109,7 @@ from cephadmlib.container_engines import (
     check_container_engine,
     find_container_engine,
 )
+from cephadmlib.data_utils import dict_get, dict_get_join
 
 FuncT = TypeVar('FuncT', bound=Callable)
 
@@ -1404,45 +1405,6 @@ def touch(file_path: str, uid: Optional[int] = None, gid: Optional[int] = None)
 ##################################
 
 
-def dict_get(d: Dict, key: str, default: Any = None, require: bool = False) -> Any:
-    """
-    Helper function to get a key from a dictionary.
-    :param d: The dictionary to process.
-    :param key: The name of the key to get.
-    :param default: The default value in case the key does not
-        exist. Default is `None`.
-    :param require: Set to `True` if the key is required. An
-        exception will be raised if the key does not exist in
-        the given dictionary.
-    :return: Returns the value of the given key.
-    :raises: :exc:`self.Error` if the given key does not exist
-        and `require` is set to `True`.
-    """
-    if require and key not in d.keys():
-        raise Error('{} missing from dict'.format(key))
-    return d.get(key, default)  # type: ignore
-
-##################################
-
-
-def dict_get_join(d: Dict[str, Any], key: str) -> Any:
-    """
-    Helper function to get the value of a given key from a dictionary.
-    `List` values will be converted to a string by joining them with a
-    line break.
-    :param d: The dictionary to process.
-    :param key: The name of the key to get.
-    :return: Returns the value of the given key. If it was a `list`, it
-        will be joining with a line break.
-    """
-    value = d.get(key)
-    if isinstance(value, list):
-        value = '\n'.join(map(str, value))
-    return value
-
-##################################
-
-
 def get_supported_daemons():
     # type: () -> List[str]
     supported_daemons = list(Ceph.daemons)
diff --git a/src/cephadm/cephadmlib/data_utils.py b/src/cephadm/cephadmlib/data_utils.py
new file mode 100644 (file)
index 0000000..9453f77
--- /dev/null
@@ -0,0 +1,41 @@
+# data_utils.py - assorted data management functions
+
+
+from typing import Dict, Any
+
+from .exceptions import Error
+
+
+def dict_get(d: Dict, key: str, default: Any = None, require: bool = False) -> Any:
+    """
+    Helper function to get a key from a dictionary.
+    :param d: The dictionary to process.
+    :param key: The name of the key to get.
+    :param default: The default value in case the key does not
+        exist. Default is `None`.
+    :param require: Set to `True` if the key is required. An
+        exception will be raised if the key does not exist in
+        the given dictionary.
+    :return: Returns the value of the given key.
+    :raises: :exc:`self.Error` if the given key does not exist
+        and `require` is set to `True`.
+    """
+    if require and key not in d.keys():
+        raise Error('{} missing from dict'.format(key))
+    return d.get(key, default)  # type: ignore
+
+
+def dict_get_join(d: Dict[str, Any], key: str) -> Any:
+    """
+    Helper function to get the value of a given key from a dictionary.
+    `List` values will be converted to a string by joining them with a
+    line break.
+    :param d: The dictionary to process.
+    :param key: The name of the key to get.
+    :return: Returns the value of the given key. If it was a `list`, it
+        will be joining with a line break.
+    """
+    value = d.get(key)
+    if isinstance(value, list):
+        value = '\n'.join(map(str, value))
+    return value