]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: Infer config on "cephadm shell"
authorRicardo Marques <rimarques@suse.com>
Fri, 24 Apr 2020 09:59:21 +0000 (10:59 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Mon, 4 May 2020 16:04:43 +0000 (18:04 +0200)
Fixes: https://tracker.ceph.com/issues/44792
Signed-off-by: Ricardo Marques <rimarques@suse.com>
(cherry picked from commit eb732dcbc5afd0218849afbf70c09a7f9c06d731)

doc/cephadm/install.rst
src/cephadm/cephadm

index 36aea18b6341de4913b1a8b2a21dddbab7641621..81779ab64cf045fc2eefb48d14696030ead26107 100644 (file)
@@ -114,10 +114,12 @@ host.  However, we recommend enabling easy access to the the ``ceph``
 command.  There are several ways to do this:
 
 * The ``cephadm shell`` command launches a bash shell in a container
-  with all of the Ceph packages installed.  By default, if
+  with all of the Ceph packages installed. By default, if
   configuration and keyring files are found in ``/etc/ceph`` on the
   host, they are passed into the container environment so that the
-  shell is fully functional::
+  shell is fully functional. Note that when executed on a MON host,
+  ``cephadm shell`` will infer the ``config`` from the MON container
+  instead of using the default configuration::
 
     # cephadm shell
 
index aaf4386cc01723987e6c3bbfb6bd753a7b8d6649..7c4dc03eb54c7dfa2803505800cf302f53a89a44 100755 (executable)
@@ -1080,6 +1080,36 @@ def infer_fsid(func):
 
     return _infer_fsid
 
+def infer_config(func):
+    """
+    If we find a MON daemon, use the config from that container
+    """
+    @wraps(func)
+    def _infer_config():
+        if args.config:
+            logger.debug('Using specified config: %s' % args.config)
+            return func()
+        config = None
+        if args.fsid:
+            name = args.name
+            if not name:
+                daemon_list = list_daemons(detail=False)
+                for daemon in daemon_list:
+                    if daemon['name'].startswith('mon.'):
+                        name = daemon['name']
+                        break
+            if name:
+                config = '/var/lib/ceph/{}/{}/config'.format(args.fsid, name)
+        if config:
+            logger.info('Inferring config %s' % config)
+            args.config = config
+        elif os.path.exists(SHELL_DEFAULT_CONF):
+            logger.debug('Using default config: %s' % SHELL_DEFAULT_CONF)
+            args.config = SHELL_DEFAULT_CONF
+        return func()
+
+    return _infer_config
+
 def _get_default_image():
     if DEFAULT_IMAGE_IS_MASTER:
         yellow = '\033[93m'
@@ -2716,6 +2746,7 @@ def command_run():
 ##################################
 
 @infer_fsid
+@infer_config
 @infer_image
 def command_shell():
     # type: () -> int
@@ -2737,8 +2768,6 @@ def command_shell():
     # use /etc/ceph files by default, if present.  we do this instead of
     # making these defaults in the arg parser because we don't want an error
     # if they don't exist.
-    if not args.config and os.path.exists(SHELL_DEFAULT_CONF):
-        args.config = SHELL_DEFAULT_CONF
     if not args.keyring and os.path.exists(SHELL_DEFAULT_KEYRING):
         args.keyring = SHELL_DEFAULT_KEYRING