~ionutbalutoiu/charms/trusty/neutron-api/next

« back to all changes in this revision

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

  • Committer: David Ames
  • Date: 2015-09-28 17:45:40 UTC
  • mfrom: (145 trunk)
  • mto: This revision was merged to the branch mainline in revision 146.
  • Revision ID: david.ames@canonical.com-20150928174540-wx0t0d3uwgmlsotb
PullĀ inĀ upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
623
623
    return unit_get('private-address')
624
624
 
625
625
 
 
626
@cached
 
627
def storage_get(attribute="", storage_id=""):
 
628
    """Get storage attributes"""
 
629
    _args = ['storage-get', '--format=json']
 
630
    if storage_id:
 
631
        _args.extend(('-s', storage_id))
 
632
    if attribute:
 
633
        _args.append(attribute)
 
634
    try:
 
635
        return json.loads(subprocess.check_output(_args).decode('UTF-8'))
 
636
    except ValueError:
 
637
        return None
 
638
 
 
639
 
 
640
@cached
 
641
def storage_list(storage_name=""):
 
642
    """List the storage IDs for the unit"""
 
643
    _args = ['storage-list', '--format=json']
 
644
    if storage_name:
 
645
        _args.append(storage_name)
 
646
    try:
 
647
        return json.loads(subprocess.check_output(_args).decode('UTF-8'))
 
648
    except ValueError:
 
649
        return None
 
650
    except OSError as e:
 
651
        import errno
 
652
        if e.errno == errno.ENOENT:
 
653
            # storage-list does not exist
 
654
            return []
 
655
        raise
 
656
 
 
657
 
626
658
class UnregisteredHookError(Exception):
627
659
    """Raised when an undefined hook is called"""
628
660
    pass