'Find a resource in a stack by either name or physical ID.'

@staticmethod
def _find_resource_in_stack(cnxt, resource_name, stack):

    if (resource_name in stack):
        return stack[resource_name]
    rsrcs = resource_objects.Resource.get_all_by_physical_resource_id(cnxt, resource_name)
    def in_stack(rs):
        return ((rs.stack_id == stack.id) and (stack[rs.name].id == rs.id))
    matches = [stack[rs.name] for rs in rsrcs if in_stack(rs)]
    if matches:
        if (len(matches) == 1):
            return matches[0]
        raise exception.PhysicalResourceIDAmbiguity(phys_id=resource_name)
    match = stack.resource_by_refid(resource_name)
    if (match is not None):
        return match
    raise exception.ResourceNotFound(resource_name=resource_name, stack_name=stack.name)
