~openstack-charmers-next/charms/xenial/heat/trunk

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/storage/linux/ceph.py

  • Committer: James Page
  • Date: 2016-05-27 11:26:45 UTC
  • Revision ID: james.page@ubuntu.com-20160527112645-mltr9ruxjw00m6ed
Resync charm helpers

Add support for OpenStack Newton and Ocata.

Rework version detection code to just match on major version for
OpenStack projects using semantic versioning.

Provide fallback version detection based on major.minor versions
for swift packages.

Rework config-flags support helpers.

Fix is_ip function to correctly detect both IPv4 and IPv6 addresses.

Change-Id: I82f3364d68ac1175942f069acb133fd9bfef5e8d

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    CalledProcessError,
41
41
)
42
42
from charmhelpers.core.hookenv import (
 
43
    config,
43
44
    local_unit,
44
45
    relation_get,
45
46
    relation_ids,
64
65
)
65
66
 
66
67
from charmhelpers.core.kernel import modprobe
 
68
from charmhelpers.contrib.openstack.utils import config_flags_parser
67
69
 
68
70
KEYRING = '/etc/ceph/ceph.client.{}.keyring'
69
71
KEYFILE = '/etc/ceph/ceph.client.{}.key'
1204
1206
        for rid in relation_ids(relation):
1205
1207
            log('Sending request {}'.format(request.request_id), level=DEBUG)
1206
1208
            relation_set(relation_id=rid, broker_req=request.request)
 
1209
 
 
1210
 
 
1211
class CephConfContext(object):
 
1212
    """Ceph config (ceph.conf) context.
 
1213
 
 
1214
    Supports user-provided Ceph configuration settings. Use can provide a
 
1215
    dictionary as the value for the config-flags charm option containing
 
1216
    Ceph configuration settings keyede by their section in ceph.conf.
 
1217
    """
 
1218
    def __init__(self, permitted_sections=None):
 
1219
        self.permitted_sections = permitted_sections or []
 
1220
 
 
1221
    def __call__(self):
 
1222
        conf = config('config-flags')
 
1223
        if not conf:
 
1224
            return {}
 
1225
 
 
1226
        conf = config_flags_parser(conf)
 
1227
        if type(conf) != dict:
 
1228
            log("Provided config-flags is not a dictionary - ignoring",
 
1229
                level=WARNING)
 
1230
            return {}
 
1231
 
 
1232
        permitted = self.permitted_sections
 
1233
        if permitted:
 
1234
            diff = set(conf.keys()).symmetric_difference(set(permitted))
 
1235
            if diff:
 
1236
                log("Config-flags contains invalid keys '%s' - they will be "
 
1237
                    "ignored" % (', '.join(diff)), level=WARNING)
 
1238
 
 
1239
        ceph_conf = {}
 
1240
        for key in conf:
 
1241
            if permitted and key not in permitted:
 
1242
                log("Ignoring key '%s'" % key, level=WARNING)
 
1243
                continue
 
1244
 
 
1245
            ceph_conf[key] = conf[key]
 
1246
 
 
1247
        return ceph_conf