~billy-olsen/charm-helpers/better-address-endpoint-overrides

« back to all changes in this revision

Viewing changes to charmhelpers/core/hookenv.py

  • Committer: Liam Young
  • Date: 2015-05-08 14:32:13 UTC
  • mfrom: (158.2.74 integration)
  • Revision ID: liam.young@canonical.com-20150508143213-opns331whrf9ltcg
[stub,r=gnuoy] This is an integration branch containing the last few months worth of outstanding merge proposals. If you review and land this, all my other outstanding ones will automatically get flagged as merged.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#  Charm Helpers Developers <juju@lists.ubuntu.com>
22
22
 
23
23
from __future__ import print_function
 
24
from functools import wraps
24
25
import os
25
26
import json
26
27
import yaml
58
59
 
59
60
    will cache the result of unit_get + 'test' for future calls.
60
61
    """
 
62
    @wraps(func)
61
63
    def wrapper(*args, **kwargs):
62
64
        global cache
63
65
        key = str((func, args, kwargs))
64
66
        try:
65
67
            return cache[key]
66
68
        except KeyError:
67
 
            res = func(*args, **kwargs)
68
 
            cache[key] = res
69
 
            return res
 
69
            pass  # Drop out of the exception handler scope.
 
70
        res = func(*args, **kwargs)
 
71
        cache[key] = res
 
72
        return res
70
73
    return wrapper
71
74
 
72
75
 
178
181
 
179
182
def remote_unit():
180
183
    """The remote unit for the current relation hook"""
181
 
    return os.environ['JUJU_REMOTE_UNIT']
 
184
    return os.environ.get('JUJU_REMOTE_UNIT', None)
182
185
 
183
186
 
184
187
def service_name():
250
253
        except KeyError:
251
254
            return (self._prev_dict or {})[key]
252
255
 
 
256
    def get(self, key, default=None):
 
257
        try:
 
258
            return self[key]
 
259
        except KeyError:
 
260
            return default
 
261
 
253
262
    def keys(self):
254
263
        prev_keys = []
255
264
        if self._prev_dict is not None:
509
518
        return None
510
519
 
511
520
 
 
521
def unit_public_ip():
 
522
    """Get this unit's public IP address"""
 
523
    return unit_get('public-address')
 
524
 
 
525
 
512
526
def unit_private_ip():
513
527
    """Get this unit's private IP address"""
514
528
    return unit_get('private-address')