~raharper/charms/trusty/glance/change-notifier

« back to all changes in this revision

Viewing changes to hooks/glance_utils.py

  • Committer: James Page
  • Date: 2014-03-13 16:38:06 UTC
  • mfrom: (43.4.5 glance)
  • Revision ID: james.page@canonical.com-20140313163806-xnh1nmtzw393s0wm
[yolanda.robla,r=james-page] Managed ceph.conf using alternatives to support co-install with glance, nova and ceph

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
from charmhelpers.core.hookenv import (
15
15
    config,
16
16
    log,
17
 
    relation_ids)
 
17
    relation_ids,
 
18
    service_name)
18
19
 
19
20
from charmhelpers.core.host import mkdir
20
21
 
30
31
    create_pool as ceph_create_pool,
31
32
    pool_exists as ceph_pool_exists)
32
33
 
 
34
from charmhelpers.contrib.openstack.alternatives import install_alternative
33
35
from charmhelpers.contrib.openstack.utils import (
34
36
    get_os_codename_install_source,
35
37
    get_os_codename_package,
36
 
    configure_installation_source, )
 
38
    configure_installation_source)
37
39
 
38
40
CLUSTER_RES = "res_glance_vip"
39
41
 
51
53
GLANCE_API_CONF = "/etc/glance/glance-api.conf"
52
54
GLANCE_API_PASTE_INI = "/etc/glance/glance-api-paste.ini"
53
55
CEPH_CONF = "/etc/ceph/ceph.conf"
 
56
CHARM_CEPH_CONF = '/var/lib/charm/{}/ceph.conf'
 
57
 
54
58
HAPROXY_CONF = "/etc/haproxy/haproxy.cfg"
55
59
HTTPS_APACHE_CONF = "/etc/apache2/sites-available/openstack_https_frontend"
56
60
HTTPS_APACHE_24_CONF = "/etc/apache2/sites-available/" \
60
64
 
61
65
TEMPLATES = 'templates/'
62
66
 
 
67
def ceph_config_file():
 
68
    return CHARM_CEPH_CONF.format(service_name())
 
69
 
63
70
CONFIG_FILES = OrderedDict([
64
71
    (GLANCE_REGISTRY_CONF, {
65
72
        'hook_contexts': [context.SharedDBContext(),
85
92
        'hook_contexts': [context.IdentityServiceContext()],
86
93
        'services': ['glance-registry']
87
94
    }),
88
 
    (CEPH_CONF, {
 
95
    (ceph_config_file(), {
89
96
        'hook_contexts': [context.CephContext()],
90
97
        'services': ['glance-api', 'glance-registry']
91
98
    }),
104
111
    })
105
112
])
106
113
 
107
 
 
108
114
def register_configs():
109
115
    # Register config files with their respective contexts.
110
116
    # Regstration of some configs may not be required depending on
120
126
             HAPROXY_CONF]
121
127
 
122
128
    if relation_ids('ceph'):
123
 
        mkdir('/etc/ceph')
124
 
        confs.append(CEPH_CONF)
 
129
        mkdir(os.path.dirname(ceph_config_file()))
 
130
        mkdir(os.path.dirname(CEPH_CONF))
 
131
 
 
132
        # Install ceph config as an alternative for co-location with
 
133
        # ceph and ceph-osd charms - glance ceph.conf will be
 
134
        # lower priority that both of these but thats OK
 
135
        if not os.path.exists(ceph_config_file()):
 
136
            # touch file for pre-templated generation
 
137
            open(ceph_config_file(), 'w').close()
 
138
        install_alternative(os.path.basename(CEPH_CONF),
 
139
                            CEPH_CONF, ceph_config_file())
 
140
        confs.append(ceph_config_file())
125
141
 
126
142
    for conf in confs:
127
143
        configs.register(conf, CONFIG_FILES[conf]['hook_contexts'])
137
153
 
138
154
 
139
155
def migrate_database():
140
 
    '''Runs glance-manage to initialize a new database or migrate existing'''
 
156
    '''Runs glance-manage to initialize a new database
 
157
    or migrate existing
 
158
    '''
141
159
    cmd = ['glance-manage', 'db_sync']
142
160
    subprocess.check_call(cmd)
143
161
 
144
162
 
145
163
def ensure_ceph_pool(service, replicas):
146
 
    '''Creates a ceph pool for service if one does not exist'''
147
 
    # TODO: Ditto about moving somewhere sharable.
 
164
    '''Creates a ceph pool for service
 
165
    if one does not exist
 
166
    '''
 
167
    # TODO(Ditto about moving somewhere sharable.)
148
168
    if not ceph_pool_exists(service=service, name=service):
149
169
        ceph_create_pool(service=service, name=service, replicas=replicas)
150
170
 
151
171
 
152
172
def do_openstack_upgrade(configs):
153
 
    """
154
 
    Perform an uprade of cinder.  Takes care of upgrading packages, rewriting
155
 
    configs + database migration and potentially any other post-upgrade
156
 
    actions.
 
173
    """Perform an uprade of cinder.  Takes care of upgrading
 
174
    packages, rewriting configs + database migration and potentially
 
175
    any other post-upgrade actions.
157
176
 
158
177
    :param configs: The charms main OSConfigRenderer object.
159
178
 
180
199
 
181
200
 
182
201
def restart_map():
183
 
    '''
184
 
    Determine the correct resource map to be passed to
 
202
    '''Determine the correct resource map to be passed to
185
203
    charmhelpers.core.restart_on_change() based on the services configured.
186
204
 
187
205
    :returns: dict: A dictionary mapping config file to lists of services