]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: infer the fsid by name
authorMichael Fritch <mfritch@suse.com>
Thu, 23 Jan 2020 15:11:59 +0000 (08:11 -0700)
committerMichael Fritch <mfritch@suse.com>
Thu, 23 Jan 2020 15:17:19 +0000 (08:17 -0700)
Signed-off-by: Michael Fritch <mfritch@suse.com>
src/cephadm/cephadm

index d4424846a2df9850dc5c792a85a6e19c0e327dab..6067be3e4c262e30a1dbaf260b8b08deca9cbab2 100755 (executable)
@@ -630,23 +630,25 @@ def infer_fsid(func):
             logger.debug('Using specified fsid: %s' % args.fsid)
             return func()
 
-        fsid_list = []
-        if os.path.exists(args.data_dir):
-            for i in os.listdir(args.data_dir):
-                if is_fsid(i):
-                    fsid_list.append(i)
-        logger.debug('Found fsids %s' % str(fsid_list))
-
-        if not fsid_list:
-            # TODO: raise?
-            return func()
-
-        if len(fsid_list) > 1:
-            raise Error('cannot infer fsid, must specify --fsid')
-
-        logger.info('Inferring fsid %s' % fsid_list[0])
-        args.fsid = fsid_list[0]
+        fsids = set()
+        daemon_list = list_daemons(detail=False)
+        for daemon in daemon_list:
+            if 'name' not in args or not args.name:
+                fsids.add(daemon['fsid'])
+            elif daemon['name'] == args.name:
+                fsids.add(daemon['fsid'])
+        fsids = list(fsids)
+
+        if not fsids:
+            # some commands do not always require an fsid
+            pass
+        elif len(fsids) == 1:
+            logger.info('Inferring fsid %s' % fsids[0])
+            args.fsid = fsids[0]
+        else:
+            raise Error('Cannot infer an fsid, one must be specified: %s' % fsids)
         return func()
+
     return _infer_fsid
 
 def write_tmp(s, uid, gid):