diff options
author | kshithijiyer <kshithij.ki@gmail.com> | 2020-05-04 16:36:56 +0530 |
---|---|---|
committer | kshithijiyer <kshithij.ki@gmail.com> | 2020-05-04 19:34:57 +0530 |
commit | b575b7c7d6ee2e2f4f053b8284445404dbc10b76 (patch) | |
tree | df7984613cc4785668ef1fd8c58c62f31ac38d60 /glustolibs-gluster/glustolibs/gluster | |
parent | fd17e148bf57e1681043b9529ad238c1a518623e (diff) |
[Lib] Add create_link_file() to glusterfile.py
Adding function create_link_file() to create
soft and hard links for an existing file.
Change-Id: I6be313ded1a640beb450425fbd29374df51fbfa3
Signed-off-by: kshithijiyer <kshithij.ki@gmail.com>
Diffstat (limited to 'glustolibs-gluster/glustolibs/gluster')
-rwxr-xr-x | glustolibs-gluster/glustolibs/gluster/glusterfile.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/glusterfile.py b/glustolibs-gluster/glustolibs/gluster/glusterfile.py index 97eb50163..5b3fa13af 100755 --- a/glustolibs-gluster/glustolibs/gluster/glusterfile.py +++ b/glustolibs-gluster/glustolibs/gluster/glusterfile.py @@ -513,6 +513,45 @@ def occurences_of_pattern_in_file(node, search_pattern, filename): return int(out.strip('\n')) +def create_link_file(node, file, link, soft=False): + """ + Create hard or soft link for an exisiting file + + Args: + node(str): Host on which the command is executed. + file(str): Path to the source file. + link(str): Path to the link file. + + Kawrgs: + soft(bool): Create soft link if True else create + hard link. + + Returns: + (bool): True if command successful else False. + + Example: + >>> create_link_file('10.20.30.40', '/mnt/mp/file.txt', + '/mnt/mp/link') + True + """ + cmd = "ln {} {}".format(file, link) + if soft: + cmd = "ln -s {} {}".format(file, link) + + ret, _, err = g.run(node, cmd) + if ret: + if soft: + g.log.error('Failed to create soft link on {} ' + 'for file {} with error {}' + .format(node, file, err)) + else: + g.log.error('Failed to create hard link on {} ' + 'for file {} with error {}' + .format(node, file, err)) + return False + return True + + class GlusterFile(object): """Class to handle files specific to Gluster (client and backend)""" def __init__(self, host, fqpath): |