import six


def get_status(resource, status_attr="status"):
    """Get the status of a given resource object.

    The status is returned in upper case. The status is checked for the
    standard field names with special cases for Heat and Ceilometer.

    :param resource: The resource object or dict.
    :param status_attr: Allows to specify non-standard status fields.
    :return: The status or "NONE" if it is not available.
    """

    for s_attr in ["stack_status", "state", status_attr]:
        status = getattr(resource, s_attr, None)
        if isinstance(status, six.string_types):
            return status.upper()

    # Dict case
    if ((isinstance(resource, dict) and status_attr in resource.keys() and
         isinstance(resource[status_attr], six.string_types))):
        return resource[status_attr].upper()

    return "NONE"