ucsschool.importer.mass_import package#

Submodules#

ucsschool.importer.mass_import.mass_import module#

Default mass import class.

class ucsschool.importer.mass_import.mass_import.MassImport(dry_run: bool | None = True)[source]#

Bases: object

Create/modify/delete all objects from the input.

Currently only implemented for users.

Parameters:

dry_run (bool) – set to False to actually commit changes to LDAP

pyhooks_base_path = '/usr/share/ucs-school-import/pyhooks'#
mass_import() None[source]#
import_computers()[source]#
import_groups()[source]#
import_inventory_numbers()[source]#
import_networks()[source]#
import_ous()[source]#
import_printers()[source]#
import_routers()[source]#
import_users() None[source]#

ucsschool.importer.mass_import.sisopi_user_import module#

Single source database, partial import user import class.

class ucsschool.importer.mass_import.sisopi_user_import.SingleSourcePartialUserImport(dry_run=True)[source]#

Bases: UserImport

Currently used by MassImport like this:

  1. read_input()

  2. detect_users_to_delete()

  3. delete_users()

  4. create_and_modify_users()

  5. log_stats()

  6. get_result_data()

In the SingleSourcePartialImport scenario the following is done:

  • Deletion: if a user is a member of the school being imported and is not part of the import data set, then only this school is removed from its schools attribute. If it was the last school, then the limbo school is added, and thus user object is moved there. A user never gets truly deleted in this scenario.

  • Creation: if a user is to be created, then first a search is done if it exists in any school (including the limbo school). If if exists somewhere, the school being imported is added to its schools attribute. If it was the limbo school, it’s removed from it and thus moved from it to the school being imported. A new user object is only created, if it doesn’t exist anywhere in the domain.

Parameters:

dry_run (bool) – set to False to actually commit changes to LDAP

prepare_imported_user(imported_user: ImportUser, old_user: ImportUser | None) ImportUser[source]#

Prepare attributes of imported_user object. Optionally save existing user (old_user) object reference in imported_user.old_user. Sets imported_user.action according to is_new_user.

In case of SingleSourcePartialImport, when a user exists:

  • when user is in limbo OU: move to new school

  • when user is any other OU: keep old school and add new school to schools

Parameters:
  • imported_user (ImportUser) – object to prepare attributes of

  • old_user (ImportUser or None) – imported_user equivalent already existing in LDAP or None

Returns:

ImportUser object with attributes prepared

Return type:

ImportUser

get_existing_users_search_filter()[source]#

Create LDAP filter with which to find existing users.

In the case of SingleSourcePartialImport, we look at:

user.source_uid == config[source_uid] && config[school] in user.schools
Returns:

LDAP filter

Return type:

str

do_delete(user)[source]#

Delete or deactivate a user.

In the case of SingleSourcePartialImport:

  • if member of multiple schools, only remove from school being imported

  • if member of only one school (the one being imported), deactivate immediately and move to limbo school

Parameters:

user (ImportUser) – user to be deleted

Returns:

whether the deletion worked

Return type:

bool

ucsschool.importer.mass_import.user_import module#

Default user import class.

class ucsschool.importer.mass_import.user_import.UserImport(dry_run=True)[source]#

Bases: object

Currently used by MassImport like this:

  1. read_input()

  2. detect_users_to_delete()

  3. delete_users()

  4. create_and_modify_users()

  5. log_stats()

  6. get_result_data()

Parameters:

dry_run (bool) – set to False to actually commit changes to LDAP

read_input() List[ImportUser][source]#

Read users from input data.

  • UcsSchoolImportErrors are stored in in self.errors (with input entry number in

    error.entry_count).

Returns:

ImportUsers found in input

Return type:

list(ImportUser)

create_and_modify_users(imported_users: List[ImportUser]) Tuple[List[UcsSchoolImportError], Dict[str, List[Dict[str, Any]]], Dict[str, List[Dict[str, Any]]]][source]#

Create and modify users.

  • self.added_users and self.modified_users will hold created / modified

    ImportUser objects.

  • UcsSchoolImportErrors are stored in self.errors (with failed

    ImportUser objects in error.import_user).

Parameters:

imported_users (list()) – ImportUser objects

Returns:

(self.errors, self.added_users, self.modified_users)

Return type:

tuple(list[UcsSchoolImportError], list[dict], list[dict])

find_importuser_in_ldap(import_user: ImportUser) ImportUser[source]#

Fetch fresh ImportUser object from LDAP.

Parameters:

import_user (ImportUser) – ImportUser object to use as reference for search

Returns:

fresh ImportUser object

Return type:

ImportUser

Raises:
  • NoObject – if ImportUser cannot be found

  • WrongUserType – if the user in LDAP is not of the same type as the import_user object

prepare_imported_user(imported_user: ImportUser, old_user: ImportUser | None) ImportUser[source]#

Prepare attributes of imported_user object. Optionally save existing user (old_user) object reference in imported_user.old_user. Sets imported_user.action according to is_new_user.

Parameters:
  • imported_user (ImportUser) – object to prepare attributes of

  • old_user (ImportUser or None) – imported_user equivalent already existing in LDAP or None

Returns:

ImportUser object with attributes prepared

Return type:

ImportUser

determine_add_modify_action(imported_user: ImportUser) ImportUser[source]#

Determine what to do with the ImportUser. Should set attribute action to either A or M. If set to M the returned user must be a opened ImportUser from LDAP.

Run modify preparations here, like school-move etc.

Parameters:

imported_user (ImportUser) – ImportUser from input

Returns:

ImportUser with action set and possibly fetched from LDAP

Return type:

ImportUser

Raises:

WrongUserType – if the user in LDAP is not of the same type as the import_user object

get_existing_users_search_filter() str[source]#

Create LDAP filter with which to find existing users.

In the case of the default UserImport, we look at: user.source_uid == config[source_uid]

Returns:

LDAP filter

Return type:

str

get_ids_of_existing_users() List[Tuple[str, str]][source]#

Get IDs of existing users.

Returns:

list of tuples: [(source_uid, record_uid), ..]

Return type:

list(tuple(str, str))

detect_users_to_delete() List[Tuple[str, str, List[str]]][source]#

Find difference between source database and UCS user database.

Returns:

list of tuples: [(source_uid, record_uid, input_data), ..]

Return type:

list(tuple(str, str, list(str)))

delete_users(users: List[Tuple[str, str, List[str]]] | None = None) Tuple[List[UcsSchoolImportError], Dict[str, List[Dict[str, Any]]]][source]#

Delete users.

  • detect_users_to_delete() should have run before this.

  • self.deleted_users will hold objects of deleted ImportUser.

  • UcsSchoolImportErrors are stored in self.errors (with failed

    ImportUser object in error.import_user).

  • To add or change a deletion strategy overwrite do_delete().

Parameters:

users (list()) – list() of tuples: [(source_uid, record_uid, input_data), ..]

Returns:

(self.errors, self.deleted_users)

Return type:

tuple

school_move(imported_user: ImportUser, user: ImportUser) ImportUser[source]#

Change users primary school.

Parameters:
  • imported_user (ImportUser) – User from input with target school

  • user (ImportUser) – existing User with old school

Returns:

user in new position, freshly fetched from LDAP

Return type:

ImportUser

do_school_move(imported_user: ImportUser, user: ImportUser) ImportUser[source]#

Change users primary school - school_move() without calling Python hooks (ucsschool lib calls executables anyway).

Parameters:
  • imported_user (ImportUser) – User from input with target school

  • user (ImportUser) – existing User with old school

Returns:

user in new position, freshly fetched from LDAP

Return type:

ImportUser

do_delete(user: ImportUser) bool[source]#

Delete or deactivate a user.

IMPLEMENTME to add or change a deletion variant.

Parameters:

user (ImportUser) – user to be deleted

Returns:

whether the deletion worked

Return type:

bool

deactivate_user_now(user: ImportUser) bool[source]#

Deactivate the user. Does not run user.modify().

Parameters:

user (ImportUser) – user to deactivate when modidy() is run

Returns:

whether any changes were made to the object and user.modify() is required

Return type:

bool

delete_user_now(user: ImportUser) bool[source]#

Truly delete the user.

Parameters:

user (ImportUser) – object to delete

Returns:

return value from the ucsschool.lib.model remove() call

Return type:

bool

set_deactivation_grace(user: ImportUser, grace: int) bool[source]#

Sets the account expiration date (UDM attribute userexpiry) on the user object. Does not run user.modify().

Parameters:
  • user (ImportUser) – object to delete

  • grace (int) – days until deactivation

Returns:

whether any changes were made to the object and user.modify() is required

Return type:

bool

set_deletion_grace(user: ImportUser, grace: int) bool[source]#

Sets the account deletion timestamp (UDM attribute ucsschoolPurgeTimestamp) on the user object. Does not run user.modify().

Parameters:
  • user (ImportUser) – user to schedule the deletion for

  • grace (int) – days until deletion

Returns:

whether any changes were made to the object and user.modify() is required

Return type:

bool

log_stats() str[source]#

Log statistics about read, created, modified and deleted users.

progress_report(description, percentage=0, done=0, total=0, **kwargs)[source]#
get_result_data() UserImportData[source]#
class ucsschool.importer.mass_import.user_import.UserImportData(user_import: UserImport)[source]#

Bases: object