def unite_statuses(statuses, update):
  """ Takes two dictionaries <hostname, hoststatus> and returns dictionary with united entries (returncode is set
  to the max value per host, logs per host are concatenated)"""
  result = {}
  for key, value in statuses.iteritems():
    if key in update:
      upd_status = update[key]
      res_status = {
        "exitstatus" : max(value["exitstatus"], upd_status["exitstatus"]),
        "log" : value["log"] + "\n" + upd_status["log"]
      }
      result[key] = res_status
    else:
      result[key] = value
  return result