log.info("Running command: {}".format(" ".join(args)))
return mount_x.client_remote.run(args=args, stdout=StringIO(),
- stdin=stdin)
+ stderr=StringIO(), stdin=stdin)
+ def get_cephfs_shell_cmd_error(self, cmd, mount_x=None, opts=None,
+ stdin=None):
+ return self.run_cephfs_shell_cmd(cmd, mount_x, opts, stdin).stderr.\
+ getvalue().strip()
+
def get_cephfs_shell_cmd_output(self, cmd, mount_x=None, opts=None,
stdin=None):
return self.run_cephfs_shell_cmd(cmd, mount_x, opts, stdin).stdout.\
poutput('max_files: %s' % max_files)
except libcephfs.Error:
perror('max_files is not set')
+ self.exit_code = 1
pass
+ snap_parser = argparse.ArgumentParser(description='Snapshot Management')
+ snap_parser.add_argument('op', type=str,
+ help='Snapshot operation: create or delete')
+ snap_parser.add_argument('name', type=str, action=path_to_bytes,
+ help='Name of snapshot')
+ snap_parser.add_argument('dir', type=str, action=path_to_bytes,
+ help='Directory for which snapshot '
+ 'needs to be created or deleted')
+
+ @with_argparser(snap_parser)
+ def do_snap(self, args):
+ """
+ Snapshot management for the volume
+ """
+ # setting self.colors to None turns off colorizing and
+ # perror emits plain text
+ self.colors = None
+
+ snapdir = '.snap'
+ conf_snapdir = cephfs.conf_get('client_snapdir')
+ if conf_snapdir is not None:
+ snapdir = conf_snapdir
+ snapdir = to_bytes(snapdir)
+ if args.op == 'create':
+ try:
+ if is_dir_exists(args.dir):
+ cephfs.mkdir(os.path.join(args.dir, snapdir, args.name), 0o755)
+ else:
+ self.perror("'{}': no such directory".format(args.dir.decode('utf-8')))
+ except libcephfs.Error:
+ self.perror("snapshot '{}' already exists".format(args.name.decode('utf-8')))
+ elif args.op == 'delete':
+ snap_dir = os.path.join(args.dir, snapdir, args.name)
+ try:
+ if is_dir_exists(snap_dir):
+ newargs = argparse.Namespace(paths=[snap_dir], parent=False)
+ self.do_rmdir_helper(newargs)
+ else:
+ self.perror("'{}': no such snapshot".format(args.name.decode('utf-8')))
+ except libcephfs.Error:
+ self.perror("error while deleting '{}'".format(snap_dir.decode('utf-8')))
+ else:
+ self.perror("snapshot can only be created or deleted; check - help snap")
+
def do_help(self, line):
"""
Get details about a command.