Schema

Usage example

# Get the schema as an LDAP entry
schema = standalone.schema.get_entry()

# Get the schema as a python-ldap SubSchema object
subschema = standalone.schema.get_subschema()

# Get a list of the schema files in the instance schemadir
schema_files = standalone.schema.list_files()


# Convert the given schema file name to its python-ldap format suitable for passing to ldap.schema.SubSchema()
parsed = standalone.schema.file_to_ldap('/full/path/to/file.ldif')

# Convert the given schema file name to its python-ldap format ldap.schema.SubSchema object
parsed = standalone.schema.file_to_subschema('/full/path/to/file.ldif')

# Add a schema element to the schema
standalone.schema.add_schema(attr, val)

# Delete a schema element from the schema
standalone.schema.del_schema(attr, val)

# Add 'attributeTypes' definition to the schema
standalone.schema.add_attribute(attributes)

# Add 'objectClasses' definition to the schema
standalone.schema.add_objectclass(objectclasses)

# Get a schema nsSchemaCSN attribute
schema_csn = standalone.schema.get_schema_csn()

# Get a list of ldap.schema.models.ObjectClass objects for all objectClasses supported by this instance
objectclasses = standalone.schema.get_objectclasses()

# Get a list of ldap.schema.models.AttributeType objects for all attributeTypes supported by this instance
attributetypes = standalone.schema.get_attributetypes()

# Get a list of the server defined matching rules
matchingrules = standalone.schema.get_matchingrules()

# Get a single matching rule instance that matches the mr_name. Returns None if the matching rule doesn't exist
matchingrule = standalone.schema.query_matchingrule(matchingrule_name)

# Get a single ObjectClass instance that matches objectclassname. Returns None if the objectClass doesn't exist
objectclass = standalone.schema.query_objectclass(objectclass_name)

# Returns a tuple of the AttributeType, and what objectclasses may or must take this attributeType. Returns None if attributetype doesn't
(attributetype, may, must) = standalone.schema.query_attributetype(attributetype_name)

Module documentation

class lib389.schema.Schema(instance)[source]

An object that represents the schema entry

Parameters

instance (lib389.DirSrv) – An instance

add_attributetype(parameters)[source]

Add an attribute type definition to the schema.

Parameters

parameters (str) – an attribute type definition to add

add_objectclass(parameters)[source]

Add an object class definition to the schema.

Parameters

parameters (str) – an objectClass definition to add

edit_attributetype(name, parameters)[source]

Edit the attribute type definition in the schema

Parameters
  • name (str) – the name of the attribute type you want to edit.

  • parameters (str) – an attribute type definition to edit

edit_objectclass(name, parameters)[source]

Edit an objectClass definition in the schema.

Parameters
  • name (str) – the name of the objectClass you want to edit.

  • parameters (str) – an objectClass definition to edit

file_to_ldap(filename)[source]

Convert the given schema file name to its python-ldap format suitable for passing to ldap.schema.SubSchema()

Parameters

filename (str) – the full path and filename of a schema file in ldif format

file_to_subschema(filename)[source]

Convert the given schema file name to its python-ldap format ldap.schema.SubSchema object

Parameters

filename (str) – the full path and filename of a schema file in ldif format

static get_attr_syntaxes(json=False)[source]

Get a list of available attribute syntaxes

get_attributetypes(json=False)[source]

Returns a list of ldap.schema.models.AttributeType objects for all attributeTypes supported by this instance.

Parameters

json (bool) – return the result in JSON format

get_matchingrules(json=False)[source]

Return a list of the server defined matching rules

Parameters

json (bool) – return the result in JSON format

get_objectclasses(json=False)[source]

Returns a list of ldap.schema.models.ObjectClass objects for all objectClasses supported by this instance.

Parameters

json (bool) – return the result in JSON format

get_schema_csn()[source]

Return the schema nsSchemaCSN attribute

list_files()[source]

Return a list of the schema files in the instance schemadir

query_attributetype(attributetypename, json=False)[source]

Returns a tuple of the AttributeType, and what objectclasses may or must take this attributeType. Returns None if attributetype doesn’t exist.

Parameters
  • attributetypename (str) – The name of the attributeType you want to query

  • json (bool) – return the result in JSON format

Returns

(AttributeType, Must, May) or None

ex. query_attributetype(‘uid’) ( <ldap.schema.models.AttributeType instance>,

[<ldap.schema.models.ObjectClass instance>, …], [<ldap.schema.models.ObjectClass instance>, …] )

query_matchingrule(mr_name, json=False)[source]

Returns a single matching rule instance that matches the mr_name. Returns None if the matching rule doesn’t exist.

Parameters
  • mr_name (str) – the name of the matching rule you want to query.

  • json (bool) – return the result in JSON format

Returns

MatchingRule or None

<ldap.schema.models.MatchingRule instance>

query_objectclass(objectclassname, json=False)[source]

Returns a single ObjectClass instance that matches objectclassname. Returns None if the objectClass doesn’t exist.

Parameters
  • objectclassname (str) – The name of the objectClass you want to query.

  • json (bool) – return the result in JSON format

Returns

ObjectClass or None

ex. query_objectclass(‘account’) <ldap.schema.models.ObjectClass instance>

reload(schema_dir=None)[source]

Reload the schema

remove_attributetype(name)[source]

Remove the attribute type definition from the schema.

Parameters

name (str) – the name of the attributeType you want to remove.

remove_objectclass(name)[source]

Remove an objectClass definition from the schema.

Parameters

name (str) – the name of the objectClass you want to remove.

validate_syntax(basedn, _filter=None)[source]

Create a validate syntax task

Parameters
  • basedn (str) – Basedn to validate

  • _filter (str) – a filter for entries to validate

Returns

an instance of Task(DSLdapObject)