]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume util create a helper for converting to bytes
authorAlfredo Deza <adeza@redhat.com>
Fri, 27 Jul 2018 15:13:19 +0000 (11:13 -0400)
committerAlfredo Deza <adeza@redhat.com>
Fri, 27 Jul 2018 21:48:01 +0000 (17:48 -0400)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
(cherry picked from commit fb518165445479cf08eefc8a2755ad78dcafd07f)

src/ceph-volume/ceph_volume/util/__init__.py

index 0222d56a0791f44c91591ad9f420341fce9e16d9..dfa83fc46d35fb962da8e0fbd67876cf88dc1183 100644 (file)
@@ -16,6 +16,16 @@ def as_string(string):
     return string
 
 
+def as_bytes(string):
+    """
+    Ensure that whatever type of string is incoming, it is returned as bytes,
+    encoding to utf-8 otherwise
+    """
+    if isinstance(string, bytes):
+        return string
+    return string.encode('utf-8', errors='ignore')
+
+
 def str_to_int(string, round_down=True):
     """
     Parses a string number into an integer, optionally converting to a float