]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume util.system capture file contents
authorAlfredo Deza <adeza@redhat.com>
Wed, 2 May 2018 23:15:10 +0000 (19:15 -0400)
committerAlfredo Deza <adeza@redhat.com>
Wed, 1 Aug 2018 15:38:27 +0000 (11:38 -0400)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
(cherry picked from commit 39792573dabac3b85a41760c965b60746ca1f059)

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

index 928c88934ad9a86f20f662116f597d4464d455cc..b637f023a4410e807d2bc5aacc4626aefba8e3c7 100644 (file)
@@ -65,6 +65,19 @@ def get_ceph_user_ids():
     return user[2], user[3]
 
 
+def get_file_contents(path, default=''):
+    contents = default
+    if not os.path.exists(path):
+        return contents
+    try:
+        with open(path, 'r') as open_file:
+            contents = open_file.read().strip()
+    except Exception:
+        logger.exception('Failed to read contents from: %s' % path)
+
+    return contents
+
+
 def mkdir_p(path, chown=True):
     """
     A `mkdir -p` that defaults to chown the path to the ceph user