~matsubara/charms/trusty/mongodb/bug-1410847

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/core/hookenv.py

  • Committer: Jorge Niedbalski
  • Date: 2014-12-11 14:56:12 UTC
  • Revision ID: jorge.niedbalski@canonical.com-20141211145612-uu8p1ke8ql7k6eu7
- Make sync after fixing LP: #1397134
- Fixes LP: #1401211

Show diffs side-by-side

added added

removed removed

Lines of Context:
396
396
 
397
397
 
398
398
@cached
 
399
def metadata():
 
400
    """Get the current charm metadata.yaml contents as a python object"""
 
401
    with open(os.path.join(charm_dir(), 'metadata.yaml')) as md:
 
402
        return yaml.safe_load(md)
 
403
 
 
404
 
 
405
@cached
399
406
def relation_types():
400
407
    """Get a list of relation types supported by this charm"""
401
 
    charmdir = os.environ.get('CHARM_DIR', '')
402
 
    mdf = open(os.path.join(charmdir, 'metadata.yaml'))
403
 
    md = yaml.safe_load(mdf)
404
408
    rel_types = []
 
409
    md = metadata()
405
410
    for key in ('provides', 'requires', 'peers'):
406
411
        section = md.get(key)
407
412
        if section:
408
413
            rel_types.extend(section.keys())
409
 
    mdf.close()
410
414
    return rel_types
411
415
 
412
416
 
413
417
@cached
 
418
def charm_name():
 
419
    """Get the name of the current charm as is specified on metadata.yaml"""
 
420
    return metadata().get('name')
 
421
 
 
422
 
 
423
@cached
414
424
def relations():
415
425
    """Get a nested dictionary of relation data for all related units"""
416
426
    rels = {}