]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephfs-shell: Add setxattr command
authorVarsha Rao <varao@redhat.com>
Tue, 28 Jan 2020 09:44:29 +0000 (15:14 +0530)
committerVarsha Rao <varao@redhat.com>
Wed, 29 Jan 2020 19:46:27 +0000 (01:16 +0530)
Fixes: https://tracker.ceph.com/issues/42530
Signed-off-by: Varsha Rao <varao@redhat.com>
src/tools/cephfs/cephfs-shell

index 01141027c260d979d4afc4f96b354b320ae0bdb3..a7349b809a97eb4b38bfe41223d56b3fda1517db 100755 (executable)
@@ -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()
 
 #######################################################
 #