check_container_engine,
find_container_engine,
)
+from cephadmlib.data_utils import dict_get, dict_get_join
FuncT = TypeVar('FuncT', bound=Callable)
##################################
-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)
--- /dev/null
+# 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