~openstack-charmers/charms/trusty/cinder-0mq/trunk

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/openstack/context.py

  • Committer: james.page at ubuntu
  • Date: 2014-07-04 08:44:18 UTC
  • mfrom: (37.1.2 cinder.lp1337266)
  • Revision ID: james.page@ubuntu.com-20140704084418-9sqsohzw4f8oa412
[hopem,r=james-page] Resync helpers to get fix for bug 1337266

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    unit_get,
25
25
    unit_private_ip,
26
26
    ERROR,
 
27
    INFO
27
28
)
28
29
 
29
30
from charmhelpers.contrib.hahelpers.cluster import (
243
244
 
244
245
 
245
246
class AMQPContext(OSContextGenerator):
246
 
    interfaces = ['amqp']
247
247
 
248
 
    def __init__(self, ssl_dir=None):
 
248
    def __init__(self, ssl_dir=None, rel_name='amqp', relation_prefix=None):
249
249
        self.ssl_dir = ssl_dir
 
250
        self.rel_name = rel_name
 
251
        self.relation_prefix = relation_prefix
 
252
        self.interfaces = [rel_name]
250
253
 
251
254
    def __call__(self):
252
255
        log('Generating template context for amqp')
253
256
        conf = config()
 
257
        user_setting = 'rabbit-user'
 
258
        vhost_setting = 'rabbit-vhost'
 
259
        if self.relation_prefix:
 
260
            user_setting = self.relation_prefix + '-rabbit-user'
 
261
            vhost_setting = self.relation_prefix + '-rabbit-vhost'
 
262
 
254
263
        try:
255
 
            username = conf['rabbit-user']
256
 
            vhost = conf['rabbit-vhost']
 
264
            username = conf[user_setting]
 
265
            vhost = conf[vhost_setting]
257
266
        except KeyError as e:
258
267
            log('Could not generate shared_db context. '
259
268
                'Missing required charm config options: %s.' % e)
260
269
            raise OSContextError
261
270
        ctxt = {}
262
 
        for rid in relation_ids('amqp'):
 
271
        for rid in relation_ids(self.rel_name):
263
272
            ha_vip_only = False
264
273
            for unit in related_units(rid):
265
274
                if relation_get('clustered', rid=rid, unit=unit):
418
427
    """
419
428
    Generates a context for an apache vhost configuration that configures
420
429
    HTTPS reverse proxying for one or many endpoints.  Generated context
421
 
    looks something like:
422
 
    {
423
 
        'namespace': 'cinder',
424
 
        'private_address': 'iscsi.mycinderhost.com',
425
 
        'endpoints': [(8776, 8766), (8777, 8767)]
426
 
    }
 
430
    looks something like::
 
431
 
 
432
        {
 
433
            'namespace': 'cinder',
 
434
            'private_address': 'iscsi.mycinderhost.com',
 
435
            'endpoints': [(8776, 8766), (8777, 8767)]
 
436
        }
427
437
 
428
438
    The endpoints list consists of a tuples mapping external ports
429
439
    to internal ports.
541
551
 
542
552
        return nvp_ctxt
543
553
 
 
554
    def n1kv_ctxt(self):
 
555
        driver = neutron_plugin_attribute(self.plugin, 'driver',
 
556
                                          self.network_manager)
 
557
        n1kv_config = neutron_plugin_attribute(self.plugin, 'config',
 
558
                                               self.network_manager)
 
559
        n1kv_ctxt = {
 
560
            'core_plugin': driver,
 
561
            'neutron_plugin': 'n1kv',
 
562
            'neutron_security_groups': self.neutron_security_groups,
 
563
            'local_ip': unit_private_ip(),
 
564
            'config': n1kv_config,
 
565
            'vsm_ip': config('n1kv-vsm-ip'),
 
566
            'vsm_username': config('n1kv-vsm-username'),
 
567
            'vsm_password': config('n1kv-vsm-password'),
 
568
            'restrict_policy_profiles': config(
 
569
                'n1kv_restrict_policy_profiles'),
 
570
        }
 
571
 
 
572
        return n1kv_ctxt
 
573
 
544
574
    def neutron_ctxt(self):
545
575
        if https():
546
576
            proto = 'https'
572
602
            ctxt.update(self.ovs_ctxt())
573
603
        elif self.plugin in ['nvp', 'nsx']:
574
604
            ctxt.update(self.nvp_ctxt())
 
605
        elif self.plugin == 'n1kv':
 
606
            ctxt.update(self.n1kv_ctxt())
575
607
 
576
608
        alchemy_flags = config('neutron-alchemy-flags')
577
609
        if alchemy_flags:
611
643
    The subordinate interface allows subordinates to export their
612
644
    configuration requirements to the principle for multiple config
613
645
    files and multiple serivces.  Ie, a subordinate that has interfaces
614
 
    to both glance and nova may export to following yaml blob as json:
 
646
    to both glance and nova may export to following yaml blob as json::
615
647
 
616
648
        glance:
617
649
            /etc/glance/glance-api.conf:
630
662
 
631
663
    It is then up to the principle charms to subscribe this context to
632
664
    the service+config file it is interestd in.  Configuration data will
633
 
    be available in the template context, in glance's case, as:
 
665
    be available in the template context, in glance's case, as::
 
666
 
634
667
        ctxt = {
635
668
            ... other context ...
636
669
            'subordinate_config': {
657
690
        self.interface = interface
658
691
 
659
692
    def __call__(self):
660
 
        ctxt = {}
 
693
        ctxt = {'sections': {}}
661
694
        for rid in relation_ids(self.interface):
662
695
            for unit in related_units(rid):
663
696
                sub_config = relation_get('subordinate_configuration',
683
716
 
684
717
                    sub_config = sub_config[self.config_file]
685
718
                    for k, v in sub_config.iteritems():
686
 
                        ctxt[k] = v
 
719
                        if k == 'sections':
 
720
                            for section, config_dict in v.iteritems():
 
721
                                log("adding section '%s'" % (section))
 
722
                                ctxt[k][section] = config_dict
 
723
                        else:
 
724
                            ctxt[k] = v
687
725
 
688
 
        if not ctxt:
689
 
            ctxt['sections'] = {}
 
726
        log("%d section(s) found" % (len(ctxt['sections'])), level=INFO)
690
727
 
691
728
        return ctxt
692
729