~hopem/charms/trusty/keystone/charm-helpers-sync-precise-ipv6-haproxy

« back to all changes in this revision

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

  • Committer: Corey Bryant
  • Date: 2014-06-24 17:11:12 UTC
  • mto: This revision was merged to the branch mainline in revision 68.
  • Revision ID: corey.bryant@canonical.com-20140624171112-lh8j88xrbqmirut3
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):
541
549
 
542
550
        return nvp_ctxt
543
551
 
 
552
    def n1kv_ctxt(self):
 
553
        driver = neutron_plugin_attribute(self.plugin, 'driver',
 
554
                                          self.network_manager)
 
555
        n1kv_config = neutron_plugin_attribute(self.plugin, 'config',
 
556
                                               self.network_manager)
 
557
        n1kv_ctxt = {
 
558
            'core_plugin': driver,
 
559
            'neutron_plugin': 'n1kv',
 
560
            'neutron_security_groups': self.neutron_security_groups,
 
561
            'local_ip': unit_private_ip(),
 
562
            'config': n1kv_config,
 
563
            'vsm_ip': config('n1kv-vsm-ip'),
 
564
            'vsm_username': config('n1kv-vsm-username'),
 
565
            'vsm_password': config('n1kv-vsm-password'),
 
566
            'restrict_policy_profiles': config(
 
567
                'n1kv_restrict_policy_profiles'),
 
568
        }
 
569
 
 
570
        return n1kv_ctxt
 
571
 
544
572
    def neutron_ctxt(self):
545
573
        if https():
546
574
            proto = 'https'
572
600
            ctxt.update(self.ovs_ctxt())
573
601
        elif self.plugin in ['nvp', 'nsx']:
574
602
            ctxt.update(self.nvp_ctxt())
 
603
        elif self.plugin == 'n1kv':
 
604
            ctxt.update(self.n1kv_ctxt())
575
605
 
576
606
        alchemy_flags = config('neutron-alchemy-flags')
577
607
        if alchemy_flags: