[gnuoy,trivial] Charmhelper sync (+1'd by mojo)

This commit is contained in:
Liam Young 2015-09-03 10:42:00 +01:00
parent 1b4b4de734
commit cbdea8da8d
2 changed files with 15 additions and 9 deletions

View File

@ -435,7 +435,11 @@ def get_hostname(address, fqdn=True):
rev = dns.reversename.from_address(address) rev = dns.reversename.from_address(address)
result = ns_query(rev) result = ns_query(rev)
if not result: if not result:
try:
result = socket.gethostbyaddr(address)[0]
except:
return None return None
else: else:
result = address result = address

View File

@ -767,21 +767,23 @@ def status_set(workload_state, message):
def status_get(): def status_get():
"""Retrieve the previously set juju workload state """Retrieve the previously set juju workload state and message
If the status-get command is not found then assume this is juju < 1.23 and
return 'unknown', ""
If the status-set command is not found then assume this is juju < 1.23 and
return 'unknown'
""" """
cmd = ['status-get'] cmd = ['status-get', "--format=json", "--include-data"]
try: try:
raw_status = subprocess.check_output(cmd, universal_newlines=True) raw_status = subprocess.check_output(cmd)
status = raw_status.rstrip()
return status
except OSError as e: except OSError as e:
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
return 'unknown' return ('unknown', "")
else: else:
raise raise
else:
status = json.loads(raw_status.decode("UTF-8"))
return (status["status"], status["message"])
def translate_exc(from_exc, to_exc): def translate_exc(from_exc, to_exc):