]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk-prepare: Take fsid from config file.
authorTommi Virtanen <tv@inktank.com>
Tue, 3 Jul 2012 16:22:28 +0000 (09:22 -0700)
committerTommi Virtanen <tv@inktank.com>
Wed, 5 Sep 2012 18:28:04 +0000 (11:28 -0700)
Closes: #2546.
Signed-off-by: Tommi Virtanen <tv@inktank.com>
src/ceph-disk-prepare

index 7791b945e7ff9ed2763de88a3495ba05fb255b9e..164f79cc3fb0743a5d65d408c1b30209b84f60f9 100755 (executable)
@@ -4,6 +4,7 @@ import argparse
 import logging
 import os
 import os.path
+import subprocess
 import sys
 import uuid
 
@@ -41,6 +42,33 @@ def write_one_line(parent, name, text):
 CEPH_OSD_ONDISK_MAGIC = 'ceph osd volume v026'
 
 
+def get_fsid(cluster):
+    try:
+        p = subprocess.Popen(
+            args=[
+                'ceph-conf',
+                '--cluster={cluster}'.format(
+                    cluster=cluster,
+                    ),
+                '--name=osd.',
+                '--lookup',
+                'fsid',
+                ],
+            stdout=subprocess.PIPE,
+            close_fds=True,
+            )
+    except OSError as e:
+        raise PrepareError('error executing ceph-conf', e)
+    (out, _err) = p.communicate()
+    ret = p.wait()
+    if ret != 0:
+        raise PrepareError('getting cluster uuid from configuration failed')
+    fsid = out.split('\n', 1)[0]
+    if not fsid:
+        return None
+    return fsid
+
+
 def prepare(
     path,
     cluster_uuid,
@@ -69,11 +97,15 @@ def parse_args():
         action='store_true', default=None,
         help='be more verbose',
         )
+    parser.add_argument(
+        '--cluster',
+        metavar='NAME',
+        help='cluster name to assign this disk to',
+        )
     parser.add_argument(
         '--cluster-uuid',
         metavar='UUID',
         help='cluster uuid to assign this disk to',
-        required=True,
         )
     parser.add_argument(
         'path',
@@ -83,6 +115,7 @@ def parse_args():
     parser.set_defaults(
         # we want to hold on to this, for later
         prog=parser.prog,
+        cluster='ceph',
         )
     args = parser.parse_args()
     return args
@@ -100,6 +133,12 @@ def main():
         )
 
     try:
+        if args.cluster_uuid is None:
+            args.cluster_uuid = get_fsid(cluster=args.cluster)
+            if args.cluster_uuid is None:
+                raise PrepareError(
+                    'must have fsid in config or pass --cluster--uuid=',
+                    )
         prepare(
             path=args.path,
             cluster_uuid=args.cluster_uuid,