'Return the resource in this stack with the specified refid.
:returns: resource in this stack with the specified refid, or None if
not found.'

def resource_by_refid(self, refid):

    for r in six.itervalues(self):
        if (r.state not in ((r.INIT, r.COMPLETE), (r.CREATE, r.IN_PROGRESS), (r.CREATE, r.COMPLETE), (r.RESUME, r.IN_PROGRESS), (r.RESUME, r.COMPLETE), (r.UPDATE, r.IN_PROGRESS), (r.UPDATE, r.COMPLETE), (r.CHECK, r.COMPLETE))):
            continue
        proxy = self.defn[r.name]
        if (proxy._resource_data is None):
            matches = ((r.FnGetRefId() == refid) or (r.name == refid))
        else:
            matches = (proxy.FnGetRefId() == refid)
        if matches:
            if (self.in_convergence_check and (r.id is not None)):
                db_res = resource_objects.Resource.get_obj(self.context, r.id)
                if (db_res is not None):
                    r._load_data(db_res)
            return r
