From: Andrew Schoen Date: Mon, 29 Jan 2018 16:43:04 +0000 (-0600) Subject: ceph-volume: adds a prepare util for checking OSD ID existance X-Git-Tag: v12.2.3~20^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7e8dbc50129b7729036974bf3f20cfbfad2794bb;p=ceph.git ceph-volume: adds a prepare util for checking OSD ID existance Signed-off-by: Andrew Schoen (cherry picked from commit 4ac99de6d98b646bf160230584f6532775cdc9cb) --- diff --git a/src/ceph-volume/ceph_volume/util/prepare.py b/src/ceph-volume/ceph_volume/util/prepare.py index ddd00e13c432..fccbf170bfc1 100644 --- a/src/ceph-volume/ceph_volume/util/prepare.py +++ b/src/ceph-volume/ceph_volume/util/prepare.py @@ -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',