Skip to content

Commit

Permalink
ceph-disk: implement --sysconfdir as /etc/ceph
Browse files Browse the repository at this point in the history
Replace hardcoded /etc/ceph with the SYSCONFDIR global variable and
implement the --sysconfdir option to override the default value.

Signed-off-by: Loic Dachary <loic@dachary.org>
  • Loading branch information
Loic Dachary committed Jan 3, 2014
1 parent 5525604 commit 9c84c13
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/ceph-disk
Expand Up @@ -117,6 +117,8 @@ INIT_SYSTEMS = [

STATEDIR = '/var/lib/ceph'

SYSCONFDIR = '/etc/ceph'

# Nuke the TERM variable to avoid confusing any subprocesses we call.
# For example, libreadline will print weird control sequences for some
# TERM values.
Expand Down Expand Up @@ -1716,9 +1718,9 @@ def find_cluster_by_uuid(_uuid):
"""
_uuid = _uuid.lower()
no_fsid = []
if not os.path.exists('/etc/ceph'):
if not os.path.exists(SYSCONFDIR):
return None
for conf_file in os.listdir('/etc/ceph'):
for conf_file in os.listdir(SYSCONFDIR):
if not conf_file.endswith('.conf'):
continue
cluster = conf_file[:-5]
Expand All @@ -1733,7 +1735,7 @@ def find_cluster_by_uuid(_uuid):
return cluster
# be tolerant of /etc/ceph/ceph.conf without an fsid defined.
if len(no_fsid) == 1 and no_fsid[0] == 'ceph':
LOG.warning('No fsid defined in /etc/ceph/ceph.conf; using anyway')
LOG.warning('No fsid defined in ' + SYSCONFDIR + '/ceph.conf; using anyway')
return 'ceph'
return None

Expand All @@ -1752,7 +1754,7 @@ def activate(

cluster = find_cluster_by_uuid(ceph_fsid)
if cluster is None:
raise Error('No cluster conf found in /etc/ceph with fsid %s' % ceph_fsid)
raise Error('No cluster conf found in ' + SYSCONFDIR + ' with fsid %s' % ceph_fsid)
LOG.debug('Cluster name is %s', cluster)

fsid = read_one_line(path, 'fsid')
Expand Down Expand Up @@ -2235,6 +2237,10 @@ def setup_statedir(dir):
global SUPPRESS_PREFIX
SUPPRESS_PREFIX = STATEDIR + '/tmp/suppress-activate.'

def setup_sysconfdir(dir):
global SYSCONFDIR
SYSCONFDIR = dir

def parse_args():
parser = argparse.ArgumentParser(
'ceph-disk',
Expand All @@ -2256,6 +2262,12 @@ def parse_args():
default='/var/lib/ceph',
help='directory in which ceph state is preserved (default /var/lib/ceph)',
)
parser.add_argument(
'--sysconfdir',
metavar='PATH',
default='/etc/ceph',
help='directory in which ceph configuration files are found (default /etc/ceph)',
)
parser.set_defaults(
# we want to hold on to this, for later
prog=parser.prog,
Expand Down Expand Up @@ -2476,6 +2488,8 @@ def main():
os.environ['PATH'] = args.prepend_to_path + ":" + path

setup_statedir(args.statedir)
setup_sysconfdir(args.sysconfdir)

try:
args.func(args)

Expand Down

0 comments on commit 9c84c13

Please sign in to comment.