3 Helper to mount ceph-fuse from /etc/fstab. To use, add an entry
6 DEVICE PATH TYPE OPTIONS
7 none /mnt/ceph fuse.ceph ceph.id=admin,_netdev,defaults 0 0
8 none /mnt/ceph fuse.ceph ceph.name=client.admin,_netdev,defaults 0 0
9 none /mnt/ceph fuse.ceph ceph.id=myuser,ceph.conf=/etc/ceph/foo.conf,_netdev,defaults 0 0
11 ceph-fuse options are specified in the fs_mntops(4) column and must begin
12 with 'ceph.' prefix. This way ceph related fs options will be passed to
13 ceph-fuse and others will be ignored by ceph-fuse.
14 First two examples above, for example, speficy that ceph-fuse will authenticate
15 as client.admin. Third example specify, that ceph-fuse will authenticate as
16 client.myuser and also sets 'conf' option to '/etc/ceph/foo.conf' via ceph-fuse
18 Any valid ceph-fuse options can be passed this way.
21 Old format is also supported
23 DEVICE PATH TYPE OPTIONS
24 id=admin /mnt/ceph fuse.ceph defaults 0 0
25 id=myuser,conf=/etc/ceph/foo.conf /mnt/ceph fuse.ceph defaults 0 0
30 from subprocess import Popen
32 def ceph_options(mntops):
33 ceph_opts = [o for o in mntops if o.startswith('ceph.')]
36 def ceph_options_compat(device):
37 return [ 'ceph.' + opt for opt in device.split(',') ]
39 def fs_options(opts, ceph_opts):
40 # strip out noauto and _netdev options; libfuse doesn't like it
41 strip_opts = ['defaults', 'noauto', '_netdev']
42 return ','.join(list(set(opts) - set(ceph_opts) - set(strip_opts)))
45 parser = argparse.ArgumentParser(description=__doc__,
46 formatter_class=argparse.RawDescriptionHelpFormatter)
47 parser.add_argument('device', type=str, nargs='+',
49 parser.add_argument('mountpoint', type=str, nargs='+',
51 parser.add_argument('-o', dest='options', type=str, nargs='+',
52 help='Filesystem options')
53 args = parser.parse_known_args(arguments)[0]
55 device = args.device[0]
56 mountpoint = args.mountpoint[0]
57 options = ''.join(args.options).split(',')
60 ceph_opts = ceph_options_compat(device)
62 ceph_opts = ceph_options(options)
64 fs_opts = fs_options(options, ceph_opts)
65 ceph_opts = ' '.join(['--' + o.replace('ceph.', '', 1) for o in ceph_opts])
67 command = 'ceph-fuse %s %s' % (ceph_opts, mountpoint)
70 command += ' -o %s' % (fs_opts)
72 mount_cmd = Popen(command, shell=True)
73 mount_cmd.communicate()
75 if (mount_cmd.returncode != 0):
76 print("Mount failed with status code: {}".format(mount_cmd.returncode))
78 if __name__ == '__main__':
79 sys.exit(main(sys.argv[1:]))