-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
mount.ceph
executable file
·127 lines (102 loc) · 4.28 KB
/
mount.ceph
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python3
"""
mount.ceph helper script
when placed or symlinked in /sbin/mount.ceph,
it can be invoked e.g. by the `mount` tool or systemd .mount units.
should behave like ceph's mount.ceph but this is a pure-python implementation.
(c) 2019-2020 Jonas Jelten <jj@sft.lol>
Released under GPLv3 or later.
"""
import argparse
import os
import sys
from importlib.util import spec_from_loader, module_from_spec
from importlib.machinery import SourceFileLoader
from pathlib import Path
def main():
"""
pick interesting arguments from the mount options
and invoke the cephfs_mount tool.
"""
# load the cephfs_mount module that actually uploads the key
# and mounts the filesystem
real_tool = "cephfs_mount"
real_tool_path = Path(__file__).resolve().parent / real_tool
if real_tool_path.is_file():
# first, try to load the cephfs_mount from the resolved current directory
# (i.e. follow all symlinks to the development repo)
spec = spec_from_loader(real_tool,
SourceFileLoader(real_tool, str(real_tool_path)))
cephfs_mount = module_from_spec(spec)
spec.loader.exec_module(cephfs_mount)
else:
# otherwise, import regularly
import cephfs_mount
cli = argparse.ArgumentParser(
description=("Mount CephFS, a distributed cluster filesystem."),
)
cli.add_argument("-v", "--verbose", action="count", default=0,
help="increase program verbosity")
cli.add_argument("-q", "--quiet", action="count", default=0,
help="decrease program verbosity")
cli.add_argument("--user", default="admin",
help=("default username for authentication if -o name=$username"
" is missing. default is %(default)s."))
cli.add_argument("--keyfile",
help=("default secret keyfile if -o secretfile=$file is missing."
" default is /etc/ceph/ceph.client.$username.keyring"))
cli.add_argument("-o", "--options", default="rw",
help=("ceph mount options, e.g.: rw,name=username,secretfile=..."
" default value is -o %(default)s."))
cli.add_argument("source",
help=("mount source, format: mon1,mon2,mon3:/path. "
"use :/path to use monitor addresses from /etc/ceph/ceph.conf"))
cli.add_argument("destination", help="mount destination")
args = cli.parse_args()
cephfs_mount.log_setup(args.verbose - args.quiet)
if os.geteuid() != 0:
sys.exit("need root privileges")
sources = args.source.split(":", maxsplit=1)
if len(sources) != 2:
cli.error("mount source invalid: missing ':' in %s" % (sources,))
monitors, source_path = sources
options = args.options.split(",")
cleaned_options_list = []
keyfile = None
username = None
for option in options:
if "=" in option and option[-1] != "=":
option_name, option_value = option.split("=", maxsplit=1)
if option_name == "secret":
cli.error("secret=... no longer possible, "
"use secretfile= instead")
elif option_name == "noauto":
# filter out
continue
elif option_name in ("secretfile", "keyfile"):
keyfile = option_value
continue
elif option_name == "name":
username = option_value
continue
cleaned_options_list.append(option)
cleaned_options = ",".join(cleaned_options_list)
if not username:
username = args.user
if not keyfile:
if args.keyfile:
keyfile = args.keyfile
else:
keyfile = "/etc/ceph/ceph.client.%s.keyring" % (username,)
# call to the actual mount tool
cephfs_mount.ceph_mount(monitors,
source_path,
args.destination,
username,
keyfile,
keyid=None,
mount_options=cleaned_options,
no_kernel_keyring=False,
kernel_resolve=False)
if __name__ == "__main__":
main()