]> git.proxmox.com Git - ceph.git/blob - ceph/src/mount.fuse.ceph
check in ceph 17.2.3 sources
[ceph.git] / ceph / src / mount.fuse.ceph
1 #!/usr/bin/python3
2 '''
3 Helper to mount ceph-fuse from /etc/fstab. To use, add an entry
4 like:
5
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
10
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
15 The first two examples above specify that ceph-fuse will authenticate
16 as client.admin. The third example specify that ceph-fuse will authenticate as
17 client.myuser and also sets 'conf' option to '/etc/ceph/foo.conf' via ceph-fuse
18 command line. Any valid ceph-fuse options can be passed this way.
19
20 NOTE:
21 Old format is also supported
22
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
26 '''
27
28 import sys
29 import argparse
30 import errno
31 import platform
32 from subprocess import Popen
33
34 def ceph_options(mntops):
35 ceph_opts = [o for o in mntops if o.startswith('ceph.')]
36 return ceph_opts
37
38 def ceph_options_compat(device):
39 return [ 'ceph.' + opt for opt in device.split(',') ]
40
41 def fs_options(opts, ceph_opts):
42 # strip out noauto and _netdev options; libfuse doesn't like it
43 strip_opts = ['defaults', 'noauto', '_netdev']
44 return ','.join(list(set(opts) - set(ceph_opts) - set(strip_opts)))
45
46 def main(arguments):
47 parser = argparse.ArgumentParser(description=__doc__,
48 formatter_class=argparse.RawDescriptionHelpFormatter)
49 parser.add_argument('device', type=str, nargs='+',
50 help='Device')
51 parser.add_argument('mountpoint', type=str, nargs='+',
52 help='Mount point')
53 parser.add_argument('-o', dest='options', type=str, nargs='+',
54 help='Filesystem options')
55 args = parser.parse_known_args(arguments)[0]
56
57 device = args.device[0]
58 mountpoint = args.mountpoint[0]
59 options = ''.join(args.options).split(',')
60
61 if '=' in device:
62 ceph_opts = ceph_options_compat(device)
63 else:
64 ceph_opts = ceph_options(options)
65
66 fs_opts = fs_options(options, ceph_opts)
67 ceph_opts = ' '.join(['--' + o.replace('ceph.', '', 1) for o in ceph_opts])
68
69 command = 'ceph-fuse %s %s' % (ceph_opts, mountpoint)
70
71 if fs_opts:
72 command += ' -o %s' % (fs_opts)
73
74 mount_cmd = Popen(command, shell=True)
75 mount_cmd.communicate()
76
77 if (mount_cmd.returncode != 0):
78 if (platform.system() == "Linux"):
79 if (mount_cmd.returncode != errno.EBUSY):
80 print("Mount failed with status code: {}".format(mount_cmd.returncode))
81 else:
82 print("Mount failed with status code: {}".format(mount_cmd.returncode))
83
84 if __name__ == '__main__':
85 sys.exit(main(sys.argv[1:]))