mirror of
https://github.com/ceph/ceph
synced 2025-04-01 23:02:17 +00:00
ceph-volume util normalize comma with dot for str-to-int conversion
Signed-off-by: Alfredo Deza <adeza@redhat.com>
This commit is contained in:
parent
5c71f5421c
commit
aa5323fbcf
@ -30,10 +30,21 @@ def str_to_int(string, round_down=True):
|
||||
"""
|
||||
Parses a string number into an integer, optionally converting to a float
|
||||
and rounding down.
|
||||
|
||||
Some LVM values may come with a comma instead of a dot to define decimals.
|
||||
This function normalizes a comma into a dot
|
||||
"""
|
||||
error_msg = "Unable to convert to integer: '%s'" % str(string)
|
||||
try:
|
||||
integer = float(string)
|
||||
integer = float(string.replace(',', '.'))
|
||||
except AttributeError:
|
||||
# this might be a integer already, so try to use it, otherwise raise
|
||||
# the original exception
|
||||
if isinstance(string, (int, float)):
|
||||
integer = string
|
||||
else:
|
||||
logger.exception(error_msg)
|
||||
raise RuntimeError(error_msg)
|
||||
except (TypeError, ValueError):
|
||||
logger.exception(error_msg)
|
||||
raise RuntimeError(error_msg)
|
||||
|
Loading…
Reference in New Issue
Block a user