]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: adds a prepare util for checking OSD ID existance
authorAndrew Schoen <aschoen@redhat.com>
Mon, 29 Jan 2018 16:43:04 +0000 (10:43 -0600)
committerAndrew Schoen <aschoen@redhat.com>
Mon, 29 Jan 2018 16:43:04 +0000 (10:43 -0600)
Signed-off-by: Andrew Schoen <aschoen@redhat.com>
src/ceph-volume/ceph_volume/util/prepare.py

index ddd00e13c4320ab170e6416cf2aa99aeef971de9..fccbf170bfc1b300ce787a8dc70240d1165deb38 100644 (file)
@@ -6,6 +6,7 @@ the single-call helper
 """
 import os
 import logging
+import json
 from ceph_volume import process, conf
 from ceph_volume.util import system, constants
 
@@ -70,6 +71,36 @@ def create_id(fsid, json_secrets):
     return ' '.join(stdout).strip()
 
 
+def check_id(osd_id):
+    """
+    Checks to see if an osd ID exists or not. Returns True
+    if it does exist, False if it doesn't.
+
+    :param osd_id: The osd ID to check
+    """
+    if not osd_id:
+        return False
+    bootstrap_keyring = '/var/lib/ceph/bootstrap-osd/%s.keyring' % conf.cluster
+    stdout, stderr, returncode = process.call(
+        [
+            'ceph',
+            '--cluster', conf.cluster,
+            '--name', 'client.bootstrap-osd',
+            '--keyring', bootstrap_keyring,
+            'osd',
+            'tree',
+            '-f', 'json',
+        ],
+        show_command=True
+    )
+    if returncode != 0:
+        raise RuntimeError('Unable check if OSD id exists: %s' % osd_id)
+
+    output = json.loads(stdout)
+    osds = output['nodes']
+    return any([osd['id'] == osd_id for osd in osds])
+
+
 def mount_tmpfs(path):
     process.run([
         'mount',