~james-page/charms/precise/cinder/whitelist-blocks

« back to all changes in this revision

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

  • Committer: James Page
  • Date: 2014-03-20 13:42:57 UTC
  • Revision ID: james.page@canonical.com-20140320134257-7xccdbkwzuw076i6
Resynced helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    determine_apache_port,
30
30
    determine_api_port,
31
31
    https,
 
32
    is_clustered
32
33
)
33
34
 
34
35
from charmhelpers.contrib.hahelpers.apache import (
240
241
        '''This generates context for /etc/ceph/ceph.conf templates'''
241
242
        if not relation_ids('ceph'):
242
243
            return {}
 
244
 
243
245
        log('Generating template context for ceph')
 
246
 
244
247
        mon_hosts = []
245
248
        auth = None
246
249
        key = None
 
250
        use_syslog = str(config('use-syslog')).lower()
247
251
        for rid in relation_ids('ceph'):
248
252
            for unit in related_units(rid):
249
253
                mon_hosts.append(relation_get('private-address', rid=rid,
255
259
            'mon_hosts': ' '.join(mon_hosts),
256
260
            'auth': auth,
257
261
            'key': key,
258
 
            'use_syslog': str(config('use-syslog')).lower()
 
262
            'use_syslog': use_syslog
259
263
        }
260
264
 
261
265
        if not os.path.isdir('/etc/ceph'):
392
396
        return ctxt
393
397
 
394
398
 
395
 
class NeutronContext(object):
 
399
class NeutronContext(OSContextGenerator):
396
400
    interfaces = []
397
401
 
398
402
    @property
453
457
 
454
458
        return nvp_ctxt
455
459
 
 
460
    def neutron_ctxt(self):
 
461
        if https():
 
462
            proto = 'https'
 
463
        else:
 
464
            proto = 'http'
 
465
        if is_clustered():
 
466
            host = config('vip')
 
467
        else:
 
468
            host = unit_get('private-address')
 
469
        url = '%s://%s:%s' % (proto, host, '9696')
 
470
        ctxt = {
 
471
            'network_manager': self.network_manager,
 
472
            'neutron_url': url,
 
473
        }
 
474
        return ctxt
 
475
 
456
476
    def __call__(self):
457
477
        self._ensure_packages()
458
478
 
462
482
        if not self.plugin:
463
483
            return {}
464
484
 
465
 
        ctxt = {'network_manager': self.network_manager}
 
485
        ctxt = self.neutron_ctxt()
466
486
 
467
487
        if self.plugin == 'ovs':
468
488
            ctxt.update(self.ovs_ctxt())
494
514
            if not config_flags:
495
515
                return {}
496
516
 
497
 
            if config_flags.find('==') >= 0:
498
 
                log("config_flags is not in expected format (key=value)",
499
 
                    level=ERROR)
500
 
                raise OSContextError
501
 
 
502
 
            # strip the following from each value.
503
 
            post_strippers = ' ,'
504
 
            # we strip any leading/trailing '=' or ' ' from the string then
505
 
            # split on '='.
506
 
            split = config_flags.strip(' =').split('=')
507
 
            limit = len(split)
508
 
            flags = {}
509
 
            for i in xrange(0, limit - 1):
510
 
                current = split[i]
511
 
                next = split[i + 1]
512
 
                vindex = next.rfind(',')
513
 
                if (i == limit - 2) or (vindex < 0):
514
 
                    value = next
515
 
                else:
516
 
                    value = next[:vindex]
517
 
 
518
 
                if i == 0:
519
 
                    key = current
520
 
                else:
521
 
                    # if this not the first entry, expect an embedded key.
522
 
                    index = current.rfind(',')
523
 
                    if index < 0:
524
 
                        log("invalid config value(s) at index %s" % (i),
525
 
                            level=ERROR)
526
 
                        raise OSContextError
527
 
                    key = current[index + 1:]
528
 
 
529
 
                # Add to collection.
530
 
                flags[key.strip(post_strippers)] = value.rstrip(post_strippers)
531
 
 
 
517
            flags = config_flags_parser(config_flags)
532
518
            return {'user_config_flags': flags}
533
519
 
534
520