~johnsca/charm-helpers/hook-context

« back to all changes in this revision

Viewing changes to charmhelpers/contrib/openstack/utils.py

  • Committer: Liam Young
  • Date: 2014-10-20 09:39:31 UTC
  • mfrom: (202.3.11 charm-helpers-0mq)
  • Revision ID: liam.young@canonical.com-20141020093931-m8eiogi1u36zxsuv
[gnuoy,r=jamespage] Add 0mq support to charmhelpers/contrib/openstack

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
# Common python helper functions used for OpenStack charms.
4
4
from collections import OrderedDict
 
5
from functools import wraps
5
6
 
6
7
import subprocess
7
8
import json
468
469
        return result.split('.')[0]
469
470
 
470
471
 
 
472
def get_matchmaker_map(mm_file='/etc/oslo/matchmaker_ring.json'):
 
473
    mm_map = {}
 
474
    if os.path.isfile(mm_file):
 
475
        with open(mm_file, 'r') as f:
 
476
            mm_map = json.load(f)
 
477
    return mm_map
 
478
 
 
479
 
471
480
def sync_db_with_multi_ipv6_addresses(database, database_user,
472
481
                                      relation_prefix=None):
473
482
    hosts = get_ipv6_addr(dynamic_only=False)
484
493
 
485
494
    for rid in relation_ids('shared-db'):
486
495
        relation_set(relation_id=rid, **kwargs)
 
496
 
 
497
 
 
498
def os_requires_version(ostack_release, pkg):
 
499
    """
 
500
    Decorator for hook to specify minimum supported release
 
501
    """
 
502
    def wrap(f):
 
503
        @wraps(f)
 
504
        def wrapped_f(*args):
 
505
            if os_release(pkg) < ostack_release:
 
506
                raise Exception("This hook is not supported on releases"
 
507
                                " before %s" % ostack_release)
 
508
            f(*args)
 
509
        return wrapped_f
 
510
    return wrap