Ejemplo n.º 1
0
    def get(cls, context, baymodel_id):
        """Find a baymodel based on its id or uuid and return a BayModel object.

        :param baymodel_id: the id *or* uuid of a baymodel.
        :returns: a :class:`BayModel` object.
        """
        if utils.is_int_like(baymodel_id):
            return cls.get_by_id(context, baymodel_id)
        elif utils.is_uuid_like(baymodel_id):
            return cls.get_by_uuid(context, baymodel_id)
        else:
            raise exception.InvalidIdentity(identity=baymodel_id)
Ejemplo n.º 2
0
    def get(cls, context, cluster_id):
        """Find a cluster based on its id or uuid and return a Cluster object.

        :param cluster_id: the id *or* uuid of a cluster.
        :param context: Security context
        :returns: a :class:`Cluster` object.
        """
        if strutils.is_int_like(cluster_id):
            return cls.get_by_id(context, cluster_id)
        elif uuidutils.is_uuid_like(cluster_id):
            return cls.get_by_uuid(context, cluster_id)
        else:
            raise exception.InvalidIdentity(identity=cluster_id)
Ejemplo n.º 3
0
    def get(cls, context, x509keypair_id):
        """Find a x509keypair_id based on its id or uuid and return a
        X509KeyPair object.

        :param x509keypair_id: the id *or* uuid of a x509keypair.
        :returns: a :class:`X509KeyPair` object.
        """
        if utils.is_int_like(x509keypair_id):
            return cls.get_by_id(context, x509keypair_id)
        elif utils.is_uuid_like(x509keypair_id):
            return cls.get_by_uuid(context, x509keypair_id)
        else:
            raise exception.InvalidIdentity(identity=x509keypair_id)
Ejemplo n.º 4
0
    def get(cls, context, bay_id):
        """Find a bay based on its id or uuid and return a Bay object.

        :param bay_id: the id *or* uuid of a bay.
        :param context: Security context
        :returns: a :class:`Bay` object.
        """
        if strutils.is_int_like(bay_id):
            return cls.get_by_id(context, bay_id)
        elif uuidutils.is_uuid_like(bay_id):
            return cls.get_by_uuid(context, bay_id)
        else:
            raise exception.InvalidIdentity(identity=bay_id)
Ejemplo n.º 5
0
    def get(cls, context, federation_id):
        """Find a federation based on its id or uuid and return it.

        :param federation_id: the id *or* uuid of a federation.
        :param context: Security context
        :returns: a :class:`Federation` object.
        """
        if strutils.is_int_like(federation_id):
            return cls.get_by_id(context, federation_id)
        elif uuidutils.is_uuid_like(federation_id):
            return cls.get_by_uuid(context, federation_id)
        else:
            raise exception.InvalidIdentity(identity=federation_id)
Ejemplo n.º 6
0
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 strutils.is_int_like(value):
        return query.filter_by(id=value)
    elif uuidutils.is_uuid_like(value):
        return query.filter_by(uuid=value)
    else:
        raise exception.InvalidIdentity(identity=value)
Ejemplo n.º 7
0
 def test_InvalidIdentity(self):
     self.assertRaises(exception.InvalidIdentity,
                       lambda: self.raise_(exception.InvalidIdentity()))