'Get flavor information from the instance object,
allowing a fallback to lookup by-id for deleted instances only.'

def _get_flavor(self, context, instance, flavors_cache):

    try:
        return instance.get_flavor()
    except exception.NotFound:
        if (not instance.deleted):
            raise
    flavor_type = instance.instance_type_id
    if (flavor_type in flavors_cache):
        return flavors_cache[flavor_type]
    try:
        flavor_ref = objects.Flavor.get_by_id(context, flavor_type)
        flavors_cache[flavor_type] = flavor_ref
    except exception.FlavorNotFound:
        flavor_ref = None
    return flavor_ref
