def getid(obj):
    try:
        return obj.id
    except AttributeError:
        return int(obj)
Abstracts the common pattern of allowing both an object or an object's ID
dataset/ETHPy150Open jacobian-archive/openstack.compute/openstack/compute/base.py/getid