Add cephx support for radosgw

This commit is contained in:
James Page 2012-10-09 13:29:34 +01:00
parent c1e3ce696a
commit 60ebb9966b
4 changed files with 97 additions and 8 deletions

View File

@ -87,12 +87,14 @@ def import_osd_bootstrap_key(key):
subprocess.check_call(cmd)
# OSD caps taken from ceph-create-keys
_osd_bootstrap_caps = [
'allow command osd create ...',
'allow command osd crush set ...',
r'allow command auth add * osd allow\ * mon allow\ rwx',
'allow command mon getmap'
]
_osd_bootstrap_caps = {
'mon': [
'allow command osd create ...',
'allow command osd crush set ...',
r'allow command auth add * osd allow\ * mon allow\ rwx',
'allow command mon getmap'
]
}
def get_osd_bootstrap_key():
@ -104,8 +106,65 @@ def get_osd_bootstrap_key():
utils.get_unit_hostname()
),
'auth', 'get-or-create', 'client.bootstrap-osd',
'mon', '; '.join(_osd_bootstrap_caps)
]
# Add capabilities
for subsystem, subcaps in _osd_bootstrap_caps.iteritems():
cmd.extend([
subsystem,
'; '.join(subcaps),
])
output = subprocess.check_output(cmd).strip() # IGNORE:E1103
# get-or-create appears to have different output depending
# on whether its 'get' or 'create'
# 'create' just returns the key, 'get' is more verbose and
# needs parsing
key = None
if len(output.splitlines()) == 1:
key = output
else:
for element in output.splitlines():
if 'key' in element:
key = element.split(' = ')[1].strip() # IGNORE:E1103
return key
_radosgw_keyring = "/etc/ceph/keyring.rados.gateway"
def import_radosgw_key(key):
if not os.path.exists(_radosgw_keyring):
cmd = [
'ceph-authtool',
_radosgw_keyring,
'--create-keyring',
'--name=client.radosgw.gateway',
'--add-key={}'.format(key)
]
subprocess.check_call(cmd)
# OSD caps taken from ceph-create-keys
_radosgw_caps = {
'mon': ['allow r'],
'osd': ['allow rwx']
}
def get_radosgw_key():
cmd = [
'ceph',
'--name', 'mon.',
'--keyring',
'/var/lib/ceph/mon/ceph-{}/keyring'.format(
utils.get_unit_hostname()
),
'auth', 'get-or-create', 'client.radosgw.gateway',
]
# Add capabilities
for subsystem, subcaps in _radosgw_caps.iteritems():
cmd.extend([
subsystem,
'; '.join(subcaps),
])
output = subprocess.check_output(cmd).strip() # IGNORE:E1103
# get-or-create appears to have different output depending
# on whether its 'get' or 'create'

View File

@ -149,6 +149,7 @@ def mon_relation():
'--subsystem-match=block', '--action=add'])
notify_osds()
notify_radosgws()
else:
utils.juju_log('INFO',
'Not enough mons ({}), punting.'.format(
@ -168,6 +169,16 @@ def notify_osds():
utils.juju_log('INFO', 'End notify_osds.')
def notify_radosgws():
utils.juju_log('INFO', 'Begin notify_radosgws.')
for relid in utils.relation_ids('radosgw'):
utils.relation_set(radosgw_key=ceph.get_radosgw_key(),
rid=relid)
utils.juju_log('INFO', 'End notify_radosgws.')
def osd_relation():
utils.juju_log('INFO', 'Begin osd-relation hook.')
@ -184,6 +195,23 @@ def osd_relation():
utils.juju_log('INFO', 'End osd-relation hook.')
def radosgw_relation():
utils.juju_log('INFO', 'Begin radosgw-relation hook.')
utils.install('radosgw') # Install radosgw for admin tools
if ceph.is_quorum():
utils.juju_log('INFO',
'mon cluster in quorum - \
providing radosgw with keys')
utils.relation_set(radosgw_key=ceph.get_radosgw_key())
else:
utils.juju_log('INFO',
'mon cluster not in quorum - deferring key provision')
utils.juju_log('INFO', 'End radosgw-relation hook.')
def upgrade_charm():
utils.juju_log('INFO', 'Begin upgrade-charm hook.')
emit_cephconf()
@ -205,6 +233,7 @@ utils.do_hooks({
'mon-relation-departed': mon_relation,
'mon-relation-joined': mon_relation,
'osd-relation-joined': osd_relation,
'radosgw-relation-joined': radosgw_relation,
'start': start,
'upgrade-charm': upgrade_charm,
})

View File

@ -0,0 +1 @@
hooks.py

View File

@ -1 +1 @@
80
82