From: Varsha Rao Date: Tue, 28 Jan 2020 09:44:29 +0000 (+0530) Subject: cephfs-shell: Add setxattr command X-Git-Tag: v15.1.1~575^2~3 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=6523ab4f91413091c75c0741a4c470e47bc9927f;p=ceph-ci.git cephfs-shell: Add setxattr command Fixes: https://tracker.ceph.com/issues/42530 Signed-off-by: Varsha Rao --- diff --git a/src/tools/cephfs/cephfs-shell b/src/tools/cephfs/cephfs-shell index 01141027c26..a7349b809a9 100755 --- a/src/tools/cephfs/cephfs-shell +++ b/src/tools/cephfs/cephfs-shell @@ -1410,6 +1410,28 @@ class CephFSShell(Cmd): perror(e) self.exit_code = e.get_error_code() + setxattr_parser = argparse.ArgumentParser( + description='Set extended attribute for a file') + setxattr_parser.add_argument('path', type=str, action=path_to_bytes, help='Name of the file') + setxattr_parser.add_argument('name', type=str, help='Extended attribute name') + setxattr_parser.add_argument('value', type=str, help='Extended attribute value') + + @with_argparser(setxattr_parser) + def do_setxattr(self, args): + """ + Set extended attribute for a file + """ + val_bytes = to_bytes(args.value) + name_bytes = to_bytes(args.name) + try: + cephfs.setxattr(args.path, name_bytes, val_bytes, os.XATTR_CREATE) + poutput('{} is successfully set to {}'.format(args.name, args.value)) + except libcephfs.ObjectExists: + cephfs.setxattr(args.path, name_bytes, val_bytes, os.XATTR_REPLACE) + poutput('{} is successfully reset to {}'.format(args.name, args.value)) + except libcephfs.Error as e: + perror(e) + self.exit_code = e.get_error_code() ####################################################### #