]> git-server-git.apps.pok.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>
Fri, 4 May 2018 17:19:27 +0000 (13:19 -0400)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
src/ceph-volume/ceph_volume/util/system.py

index 0ba46d362766b3acb48e83f349f5ebf821912844..ab5b2c7bba39b666439488690d55270ba90997f7 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