~freyes/+junk/lp1387390

« back to all changes in this revision

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

  • Committer: Corey Bryant
  • Date: 2014-07-11 02:24:52 UTC
  • mto: This revision was merged to the branch mainline in revision 70.
  • Revision ID: corey.bryant@canonical.com-20140711022452-72xfia0gz5klgugi
Sync with charm-helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
243
243
 
244
244
 
245
245
class AMQPContext(OSContextGenerator):
246
 
    interfaces = ['amqp']
247
246
 
248
 
    def __init__(self, ssl_dir=None):
 
247
    def __init__(self, ssl_dir=None, rel_name='amqp', relation_prefix=None):
249
248
        self.ssl_dir = ssl_dir
 
249
        self.rel_name = rel_name
 
250
        self.relation_prefix = relation_prefix
 
251
        self.interfaces = [rel_name]
250
252
 
251
253
    def __call__(self):
252
254
        log('Generating template context for amqp')
253
255
        conf = config()
 
256
        user_setting = 'rabbit-user'
 
257
        vhost_setting = 'rabbit-vhost'
 
258
        if self.relation_prefix:
 
259
            user_setting = self.relation_prefix + '-rabbit-user'
 
260
            vhost_setting = self.relation_prefix + '-rabbit-vhost'
 
261
 
254
262
        try:
255
 
            username = conf['rabbit-user']
256
 
            vhost = conf['rabbit-vhost']
 
263
            username = conf[user_setting]
 
264
            vhost = conf[vhost_setting]
257
265
        except KeyError as e:
258
266
            log('Could not generate shared_db context. '
259
267
                'Missing required charm config options: %s.' % e)
260
268
            raise OSContextError
261
269
        ctxt = {}
262
 
        for rid in relation_ids('amqp'):
 
270
        for rid in relation_ids(self.rel_name):
263
271
            ha_vip_only = False
264
272
            for unit in related_units(rid):
265
273
                if relation_get('clustered', rid=rid, unit=unit):
418
426
    """
419
427
    Generates a context for an apache vhost configuration that configures
420
428
    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
 
    }
 
429
    looks something like::
 
430
 
 
431
        {
 
432
            'namespace': 'cinder',
 
433
            'private_address': 'iscsi.mycinderhost.com',
 
434
            'endpoints': [(8776, 8766), (8777, 8767)]
 
435
        }
427
436
 
428
437
    The endpoints list consists of a tuples mapping external ports
429
438
    to internal ports.
541
550
 
542
551
        return nvp_ctxt
543
552
 
 
553
    def n1kv_ctxt(self):
 
554
        driver = neutron_plugin_attribute(self.plugin, 'driver',
 
555
                                          self.network_manager)
 
556
        n1kv_config = neutron_plugin_attribute(self.plugin, 'config',
 
557
                                               self.network_manager)
 
558
        n1kv_ctxt = {
 
559
            'core_plugin': driver,
 
560
            'neutron_plugin': 'n1kv',
 
561
            'neutron_security_groups': self.neutron_security_groups,
 
562
            'local_ip': unit_private_ip(),
 
563
            'config': n1kv_config,
 
564
            'vsm_ip': config('n1kv-vsm-ip'),
 
565
            'vsm_username': config('n1kv-vsm-username'),
 
566
            'vsm_password': config('n1kv-vsm-password'),
 
567
            'restrict_policy_profiles': config(
 
568
                'n1kv_restrict_policy_profiles'),
 
569
        }
 
570
 
 
571
        return n1kv_ctxt
 
572
 
544
573
    def neutron_ctxt(self):
545
574
        if https():
546
575
            proto = 'https'
572
601
            ctxt.update(self.ovs_ctxt())
573
602
        elif self.plugin in ['nvp', 'nsx']:
574
603
            ctxt.update(self.nvp_ctxt())
 
604
        elif self.plugin == 'n1kv':
 
605
            ctxt.update(self.n1kv_ctxt())
575
606
 
576
607
        alchemy_flags = config('neutron-alchemy-flags')
577
608
        if alchemy_flags:
611
642
    The subordinate interface allows subordinates to export their
612
643
    configuration requirements to the principle for multiple config
613
644
    files and multiple serivces.  Ie, a subordinate that has interfaces
614
 
    to both glance and nova may export to following yaml blob as json:
 
645
    to both glance and nova may export to following yaml blob as json::
615
646
 
616
647
        glance:
617
648
            /etc/glance/glance-api.conf:
630
661
 
631
662
    It is then up to the principle charms to subscribe this context to
632
663
    the service+config file it is interestd in.  Configuration data will
633
 
    be available in the template context, in glance's case, as:
 
664
    be available in the template context, in glance's case, as::
 
665
 
634
666
        ctxt = {
635
667
            ... other context ...
636
668
            'subordinate_config': {