~charmers/charms/precise/nova-cloud-controller/trunk

« back to all changes in this revision

Viewing changes to hooks/nova_cc_hooks.py

  • Committer: James Page
  • Date: 2013-11-17 21:50:30 UTC
  • mfrom: (52.3.10 nova-cloud-controller)
  • Revision ID: james.page@canonical.com-20131117215030-vmf1iqtf9ihhg7cj
[gandelman-a] NVP + VMware vSphere supprot

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
import os
4
4
import shutil
5
5
import sys
 
6
import uuid
6
7
 
7
8
from subprocess import check_call
8
9
from urlparse import urlparse
25
26
)
26
27
 
27
28
from charmhelpers.fetch import (
28
 
    apt_install, apt_update, filter_installed_packages
 
29
    apt_install, apt_update
29
30
)
30
31
 
31
32
from charmhelpers.contrib.openstack.utils import (
148
149
 
149
150
    if eligible_leader(CLUSTER_RES):
150
151
        migrate_database()
 
152
        log('Triggering remote cloud-compute restarts.')
 
153
        [compute_joined(rid=rid, remote_restart=True)
 
154
         for rid in relation_ids('cloud-compute')]
151
155
 
152
156
 
153
157
@hooks.hook('image-service-relation-changed')
184
188
        CONFIGS.write(NEUTRON_CONF)
185
189
    [compute_joined(rid) for rid in relation_ids('cloud-compute')]
186
190
    [quantum_joined(rid) for rid in relation_ids('quantum-network-service')]
 
191
    [nova_vmware_relation_joined(rid) for rid in relation_ids('nova-vmware')]
187
192
    configure_https()
188
193
 
189
194
 
230
235
        out.write('export OS_REGION_NAME=%s\n' % config('region'))
231
236
 
232
237
 
 
238
def keystone_compute_settings():
 
239
    ks_auth_config = _auth_config()
 
240
    rel_settings = {}
 
241
 
 
242
    if network_manager() in ['quantum', 'neutron']:
 
243
        if ks_auth_config:
 
244
            rel_settings.update(ks_auth_config)
 
245
 
 
246
        rel_settings.update({
 
247
            # XXX: Rename these relations settings?
 
248
            'quantum_plugin': neutron_plugin(),
 
249
            'region': config('region'),
 
250
            'quantum_security_groups': config('quantum-security-groups'),
 
251
            'quantum_url': (canonical_url(CONFIGS) + ':' +
 
252
                            str(api_port('neutron-server'))),
 
253
        })
 
254
 
 
255
    ks_ca = keystone_ca_cert_b64()
 
256
    if ks_auth_config and ks_ca:
 
257
        rel_settings['ca_cert'] = ks_ca
 
258
 
 
259
    return rel_settings
 
260
 
 
261
 
233
262
@hooks.hook('cloud-compute-relation-joined')
234
 
def compute_joined(rid=None):
 
263
def compute_joined(rid=None, remote_restart=False):
235
264
    if not eligible_leader(CLUSTER_RES):
236
265
        return
237
266
    rel_settings = {
242
271
        'ec2_host': unit_get('private-address'),
243
272
    }
244
273
 
245
 
    ks_auth_config = _auth_config()
246
 
 
247
 
    if network_manager() in ['quantum', 'neutron']:
248
 
        if ks_auth_config:
249
 
            rel_settings.update(ks_auth_config)
250
 
 
251
 
        rel_settings.update({
252
 
            # XXX: Rename these relations settings?
253
 
            'quantum_plugin': neutron_plugin(),
254
 
            'region': config('region'),
255
 
            'quantum_security_groups': config('quantum-security-groups'),
256
 
            'quantum_url': (canonical_url(CONFIGS) + ':' +
257
 
                            str(api_port('neutron-server'))),
258
 
        })
259
 
 
260
 
    ks_ca = keystone_ca_cert_b64()
261
 
    if ks_auth_config and ks_ca:
262
 
        rel_settings['ca_cert'] = ks_ca
 
274
    # update relation setting if we're attempting to restart remote
 
275
    # services
 
276
    if remote_restart:
 
277
        rel_settings['restart_trigger'] = str(uuid.uuid4())
 
278
 
 
279
    rel_settings.update(keystone_compute_settings())
263
280
    relation_set(relation_id=rid, **rel_settings)
264
281
 
265
282
 
287
304
    if not eligible_leader(CLUSTER_RES):
288
305
        return
289
306
 
290
 
    if network_manager() == 'quantum':
291
 
        pkg = 'quantum-server'
292
 
    else:
293
 
        pkg = 'neutron-server'
294
 
 
295
 
    required_pkg = filter_installed_packages([pkg])
296
 
    if required_pkg:
297
 
        apt_install(required_pkg)
298
 
 
299
307
    url = canonical_url(CONFIGS) + ':9696'
300
308
    # XXX: Can we rename to neutron_*?
301
309
    rel_settings = {
397
405
        identity_joined(rid=rid)
398
406
 
399
407
 
 
408
@hooks.hook()
 
409
def nova_vmware_relation_joined(rid=None):
 
410
    rel_settings = {'network_manager': network_manager()}
 
411
 
 
412
    ks_auth = _auth_config()
 
413
    if ks_auth:
 
414
        rel_settings.update(ks_auth)
 
415
        rel_settings.update({
 
416
            'quantum_plugin': neutron_plugin(),
 
417
            'quantum_security_groups': config('quantum-security-groups'),
 
418
            'quantum_url': (canonical_url(CONFIGS) + ':' +
 
419
                            str(api_port('neutron-server')))})
 
420
 
 
421
    relation_set(relation_id=rid, **rel_settings)
 
422
 
 
423
 
 
424
@hooks.hook('nova-vmware-relation-changed')
 
425
@restart_on_change(restart_map())
 
426
def nova_vmware_relation_changed():
 
427
    CONFIGS.write('/etc/nova/nova.conf')
 
428
 
 
429
 
400
430
@hooks.hook('upgrade-charm')
401
431
def upgrade_charm():
402
432
    for r_id in relation_ids('amqp'):