diff options
author | sayaleeraut <saraut@redhat.com> | 2020-08-11 22:46:11 +0530 |
---|---|---|
committer | Sayalee Raut <saraut@redhat.com> | 2020-08-12 05:20:03 +0000 |
commit | 1d0ff4497fa3df2f4acebbc0eef044fb122b64d9 (patch) | |
tree | b3448f10e5a37816dabb256d587c8b12278c12b8 /glustolibs-gluster/glustolibs/gluster | |
parent | d4ee7ad936e45019275e536f0041addee54812c4 (diff) |
[LibFix] Add encoding type to get_fattr()
Currently the get_fattr() function returns the xattr value in the
hex encoding format. Adding the option to add/specify other
encoding types, i.e. text and base64, where hex will be the default
encoding format.
Reason -
When the xattrs are custom set through mountpoint, it becomes
easier to test if the value is correct by using the "text"
encoding.
Example -
>>> ret = get_fattr(host, fqpath, fattr)
>>> print ret
0x414243
>>> ret = get_fattr(host, fqpath, fattr, encode="text")
>>> print ret
"ABC"
The value "ABC" is easily readable as opposed to 0x414243 when
performing a test.
Change-Id: Ie2377b924816ebab0a2af116d82600e01f03d61f
Signed-off-by: sayaleeraut <saraut@redhat.com>
Diffstat (limited to 'glustolibs-gluster/glustolibs/gluster')
-rwxr-xr-x | glustolibs-gluster/glustolibs/gluster/glusterfile.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/glusterfile.py b/glustolibs-gluster/glustolibs/gluster/glusterfile.py index 32068d9f4..86383e800 100755 --- a/glustolibs-gluster/glustolibs/gluster/glusterfile.py +++ b/glustolibs-gluster/glustolibs/gluster/glusterfile.py @@ -97,22 +97,24 @@ def get_mountpoint(host, fqpath): return None -def get_fattr(host, fqpath, fattr): +def get_fattr(host, fqpath, fattr, encode="hex"): """getfattr for filepath on remote system Args: host (str): The hostname/ip of the remote system. fqpath (str): The fully-qualified path to the file. fattr (str): name of the fattr to retrieve - + Kwargs: + encode(str): The supported types of encoding are + [hex|text|base64] + Defaults to hex type of encoding Returns: getfattr result on success. None on fail. """ - command = ("getfattr --absolute-names -e hex " + command = ("getfattr --absolute-names -e '%s' " "-n '%s' %s" % - (fattr, fqpath)) + (encode, fattr, fqpath)) rcode, rout, rerr = g.run(host, command) - if not rcode: return rout.strip().split('=')[1] |