~moon127/charms/trusty/ceilometer/add-execd-preinstall

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from charmhelpers.contrib.openstack import (
    templating,
    context,
)
from ceilometer_contexts import (
    LoggingConfigContext,
    MongoDBContext,
    CeilometerContext
)
from charmhelpers.contrib.openstack.utils import (
    get_os_codename_package
)

CEILOMETER_CONF = "/etc/ceilometer/ceilometer.conf"

CEILOMETER_SERVICES = [
    'ceilometer-agent-central',
    'ceilometer-collector',
    'ceilometer-api'
]

CEILOMETER_DB = "ceilometer"
CEILOMETER_SERVICE = "ceilometer"

CEILOMETER_PACKAGES = [
    'ceilometer-agent-central',
    'ceilometer-collector',
    'ceilometer-api'
]

CEILOMETER_ROLE = "ResellerAdmin"

#NOVA_CONF = "/etc/nova/nova.conf"
#NOVA_SETTINGS = [
#    ('DEFAULT', 'instance_usage_audit', 'True'),
#    ('DEFAULT', 'instance_usage_audit_period', 'hour'),
#    ('DEFAULT', 'notification_driver', 'ceilometer.compute.nova_notifier')
#]

CONFIG_FILES = {
    CEILOMETER_CONF: {
        'hook_contexts': [context.IdentityServiceContext(),
                          context.AMQPContext(),
                          LoggingConfigContext(),
                          MongoDBContext(),
                          CeilometerContext()],
        'services': CEILOMETER_SERVICES
    }
}

TEMPLATES = 'templates'


def register_configs():
    """
    Register config files with their respective contexts.
    Regstration of some configs may not be required depending on
    existing of certain relations.
    """
    # if called without anything installed (eg during install hook)
    # just default to earliest supported release. configs dont get touched
    # till post-install, anyway.
    release = get_os_codename_package('ceilometer-common', fatal=False) \
                or 'grizzly'
    configs = templating.OSConfigRenderer(templates_dir=TEMPLATES,
                                          openstack_release=release)

    for conf in CONFIG_FILES:
        configs.register(conf, CONFIG_FILES[conf]['hook_contexts'])

    return configs


def restart_map():
    '''
    Determine the correct resource map to be passed to
    charmhelpers.core.restart_on_change() based on the services configured.

    :returns: dict: A dictionary mapping config file to lists of services
                    that should be restarted when file changes.
    '''
    _map = {}
    for f, ctxt in CONFIG_FILES.iteritems():
        svcs = []
        for svc in ctxt['services']:
            svcs.append(svc)
        if svcs:
            _map[f] = svcs
    return _map


def get_ceilometer_context():
    ''' Retrieve a map of all current relation data for agent configuration '''
    ctxt = {}
    for context in CONFIG_FILES[CEILOMETER_CONF]['hook_contexts']:
        ctxt.update(context())
    return ctxt