From 4ac99de6d98b646bf160230584f6532775cdc9cb Mon Sep 17 00:00:00 2001 From: Andrew Schoen Date: Mon, 29 Jan 2018 10:43:04 -0600 Subject: [PATCH] ceph-volume: adds a prepare util for checking OSD ID existance Signed-off-by: Andrew Schoen --- src/ceph-volume/ceph_volume/util/prepare.py | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/ceph-volume/ceph_volume/util/prepare.py b/src/ceph-volume/ceph_volume/util/prepare.py index ddd00e13c43..fccbf170bfc 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', -- 2.39.5