def get(cls, context, test_id): """Find a test based on its id or uuid and return a Cpulse object. :param test_id: the id *or* uuid of a test. :returns: a :class:`Cpulse` object. """ if utils.is_int_like(test_id): return cls.get_by_id(context, test_id) elif utils.is_uuid_like(test_id): return cls.get_by_uuid(context, test_id) else: raise exception.InvalidIdentity(identity=test_id)
def add_identity_filter(query, value): """Adds an identity filter to a query. Filters results by ID, if supplied value is a valid integer. Otherwise attempts to filter results by UUID. :param query: Initial query to add filter to. :param value: Value for filtering results by. :return: Modified query. """ if utils.is_int_like(value): return query.filter_by(id=value) elif utils.is_uuid_like(value): return query.filter_by(uuid=value) else: raise exception.InvalidIdentity(identity=value)
def get_rpc_resource(resource, resource_ident): """Get the RPC resource from the uuid or logical name. :param resource: the resource type. :param resource_ident: the UUID or logical name of the resource. :returns: The RPC resource. :raises: InvalidUuidOrName if the name or uuid provided is not valid. """ resource = getattr(objects, resource) if utils.is_uuid_like(resource_ident): return resource.get_by_uuid(pecan.request.context, resource_ident) if utils.allow_logical_names(): return resource.get_by_name(pecan.request.context, resource_ident) raise exception.InvalidUuidOrName(name=resource_ident)
def validate(value): if not utils.is_uuid_like(value): raise exception.InvalidUUID(uuid=value) return value