]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: Infer config on "cephadm shell" 34728/head
authorRicardo Marques <rimarques@suse.com>
Fri, 24 Apr 2020 09:59:21 +0000 (10:59 +0100)
committerRicardo Marques <rimarques@suse.com>
Wed, 29 Apr 2020 15:31:29 +0000 (16:31 +0100)
Fixes: https://tracker.ceph.com/issues/44792
Signed-off-by: Ricardo Marques <rimarques@suse.com>
doc/cephadm/install.rst
src/cephadm/cephadm

index 65ac09d8c646bc71b938cefcb384fd3063cd6958..7033cdb48335d31c75e8fe4bd739474da8a68442 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 6031e2535e88b7d2963a4062c11774b8d45104e7..704aabf260d67e7649919d1237fa1900fb0e6a78 100755 (executable)
@@ -1078,6 +1078,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'
@@ -2708,6 +2738,7 @@ def command_run():
 ##################################
 
 @infer_fsid
+@infer_config
 @infer_image
 def command_shell():
     # type: () -> int
@@ -2729,8 +2760,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