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

« back to all changes in this revision

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

  • Committer: Liam Young
  • Date: 2015-09-28 12:41:31 UTC
  • mfrom: (142.2.1 trunk)
  • Revision ID: liam.young@canonical.com-20150928124131-hzlbsw4n1ligxsm2
[hopem, r=gnuoy] Sync charmhelpers to get fix for bug 1499643

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