summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkshithijiyer <kshithij.ki@gmail.com>2019-03-04 14:45:59 +0530
committerKshithij Iyer <kiyer@redhat.com>2019-03-20 13:12:57 +0000
commitad4931feb6602838432288553d17b5377457d540 (patch)
tree3281afc5b7bd65c8ff8e2e1b5e7259ec0ae95dbe
parentdbaad29430e627b2e21b0f6c7619a907076d157e (diff)
Adding get_dir_contents() to glusterdir library.
Change-Id: I7a043753b8ae2ae46ee944e04ddd9137f177960f Signed-off-by: kshithijiyer <kshithij.ki@gmail.com>
-rw-r--r--glustolibs-gluster/glustolibs/gluster/glusterdir.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/glusterdir.py b/glustolibs-gluster/glustolibs/gluster/glusterdir.py
index 50c37c7..f1d8826 100644
--- a/glustolibs-gluster/glustolibs/gluster/glusterdir.py
+++ b/glustolibs-gluster/glustolibs/gluster/glusterdir.py
@@ -82,6 +82,24 @@ def rmdir(host, fqpath, force=False):
return False
+def get_dir_contents(host, path):
+ """Get the files and directories present in a given directory.
+
+ Args:
+ host (str): The hostname/ip of the remote system.
+ path (str): The path to the directory.
+
+ Returns:
+ file_dir_list (list): List of files and directories on path.
+ None: In case of error or failure.
+ """
+ ret, out, _ = g.run(host, ' ls '+path)
+ if ret != 0:
+ return None
+ file_dir_list = filter(None, out.split("\n"))
+ return file_dir_list
+
+
class GlusterDir(GlusterFile):
"""Class to handle directories specific to Gluster (client and backend)"""
def mkdir(self, parents=False, mode=None):