check_container_engine,
find_container_engine,
)
-from cephadmlib.data_utils import dict_get, dict_get_join
+from cephadmlib.data_utils import (
+ bytes_to_human,
+ dict_get,
+ dict_get_join,
+ with_units_to_int,
+)
from cephadmlib.file_utils import (
makedirs,
populate_files,
print(json.dumps(ls, indent=4))
-def with_units_to_int(v: str) -> int:
- if v.endswith('iB'):
- v = v[:-2]
- elif v.endswith('B'):
- v = v[:-1]
- mult = 1
- if v[-1].upper() == 'K':
- mult = 1024
- v = v[:-1]
- elif v[-1].upper() == 'M':
- mult = 1024 * 1024
- v = v[:-1]
- elif v[-1].upper() == 'G':
- mult = 1024 * 1024 * 1024
- v = v[:-1]
- elif v[-1].upper() == 'T':
- mult = 1024 * 1024 * 1024 * 1024
- v = v[:-1]
- return int(float(v) * mult)
-
-
def list_daemons(ctx, detail=True, legacy_dir=None):
# type: (CephadmContext, bool, Optional[str]) -> List[Dict[str, str]]
host_version: Optional[str] = None
##################################
-def bytes_to_human(num, mode='decimal'):
- # type: (float, str) -> str
- """Convert a bytes value into it's human-readable form.
-
- :param num: number, in bytes, to convert
- :param mode: Either decimal (default) or binary to determine divisor
- :returns: string representing the bytes value in a more readable format
- """
- unit_list = ['', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB']
- divisor = 1000.0
- yotta = 'YB'
-
- if mode == 'binary':
- unit_list = ['', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB']
- divisor = 1024.0
- yotta = 'YiB'
-
- for unit in unit_list:
- if abs(num) < divisor:
- return '%3.1f%s' % (num, unit)
- num /= divisor
- return '%.1f%s' % (num, yotta)
-
-##################################
-
-
class Enclosure:
def __init__(self, enc_id: str, enc_path: str, dev_path: str):
"""External disk enclosure metadata
if isinstance(value, list):
value = '\n'.join(map(str, value))
return value
+
+
+def bytes_to_human(num, mode='decimal'):
+ # type: (float, str) -> str
+ """Convert a bytes value into it's human-readable form.
+
+ :param num: number, in bytes, to convert
+ :param mode: Either decimal (default) or binary to determine divisor
+ :returns: string representing the bytes value in a more readable format
+ """
+ unit_list = ['', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB']
+ divisor = 1000.0
+ yotta = 'YB'
+
+ if mode == 'binary':
+ unit_list = ['', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB']
+ divisor = 1024.0
+ yotta = 'YiB'
+
+ for unit in unit_list:
+ if abs(num) < divisor:
+ return '%3.1f%s' % (num, unit)
+ num /= divisor
+ return '%.1f%s' % (num, yotta)
+
+
+def with_units_to_int(v: str) -> int:
+ if v.endswith('iB'):
+ v = v[:-2]
+ elif v.endswith('B'):
+ v = v[:-1]
+ mult = 1
+ if v[-1].upper() == 'K':
+ mult = 1024
+ v = v[:-1]
+ elif v[-1].upper() == 'M':
+ mult = 1024 * 1024
+ v = v[:-1]
+ elif v[-1].upper() == 'G':
+ mult = 1024 * 1024 * 1024
+ v = v[:-1]
+ elif v[-1].upper() == 'T':
+ mult = 1024 * 1024 * 1024 * 1024
+ v = v[:-1]
+ return int(float(v) * mult)