~openstack-charmers-archive/charms/trusty/nova-compute/old-1501

« back to all changes in this revision

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

  • Committer: james.page at ubuntu
  • Date: 2014-12-15 09:10:57 UTC
  • mfrom: (91.1.8 nova-compute)
  • Revision ID: james.page@ubuntu.com-20141215091057-yixgfa5av3tebjwy
[corey.bryant,r=james-page] Sort out charmhelpers issues.

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
    command = ['juju-log']
69
69
    if level:
70
70
        command += ['-l', level]
 
71
    if not isinstance(message, six.string_types):
 
72
        message = repr(message)
71
73
    command += [message]
72
74
    subprocess.call(command)
73
75
 
394
396
 
395
397
 
396
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
397
406
def relation_types():
398
407
    """Get a list of relation types supported by this charm"""
399
 
    charmdir = os.environ.get('CHARM_DIR', '')
400
 
    mdf = open(os.path.join(charmdir, 'metadata.yaml'))
401
 
    md = yaml.safe_load(mdf)
402
408
    rel_types = []
 
409
    md = metadata()
403
410
    for key in ('provides', 'requires', 'peers'):
404
411
        section = md.get(key)
405
412
        if section:
406
413
            rel_types.extend(section.keys())
407
 
    mdf.close()
408
414
    return rel_types
409
415
 
410
416
 
411
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
412
424
def relations():
413
425
    """Get a nested dictionary of relation data for all related units"""
414
426
    rels = {}