~1chb1n/charms/trusty/cinder/15.10-stable-flip-tests-helper-syncs

« back to all changes in this revision

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

  • Committer: James Page
  • Date: 2015-10-22 13:19:13 UTC
  • Revision ID: james.page@ubuntu.com-20151022131913-02u2l9s2fa0xtbio
Tags: 15.10
15.10 Charm release

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
767
799
 
768
800
 
769
801
def status_get():
770
 
    """Retrieve the previously set juju workload state
771
 
 
772
 
    If the status-set command is not found then assume this is juju < 1.23 and
773
 
    return 'unknown'
 
802
    """Retrieve the previously set juju workload state and message
 
803
 
 
804
    If the status-get command is not found then assume this is juju < 1.23 and
 
805
    return 'unknown', ""
 
806
 
774
807
    """
775
 
    cmd = ['status-get']
 
808
    cmd = ['status-get', "--format=json", "--include-data"]
776
809
    try:
777
 
        raw_status = subprocess.check_output(cmd, universal_newlines=True)
778
 
        status = raw_status.rstrip()
779
 
        return status
 
810
        raw_status = subprocess.check_output(cmd)
780
811
    except OSError as e:
781
812
        if e.errno == errno.ENOENT:
782
 
            return 'unknown'
 
813
            return ('unknown', "")
783
814
        else:
784
815
            raise
 
816
    else:
 
817
        status = json.loads(raw_status.decode("UTF-8"))
 
818
        return (status["status"], status["message"])
785
819
 
786
820
 
787
821
def translate_exc(from_exc, to_exc):