mstrio > object_management > migration > migration

class mstrio.object_management.migration.migration.Migration(connection, id=None, name=None)

Bases: EntityBase, ProgressBarMixin, DeleteMixin

A class encapsulating migration process from env A to env B.

Raises VersionException if either of environments are running IServer version lower than 11.3.10

Parameters:
  • connection (Connection) –

  • id (str | None) –

  • name (str | None) –

id

ID of the migration

Type:

str

name

Name of the migration

Type:

str

type

MSTR type of the migration object. Returns either NOT_SUPPORTED or None

Type:

str

connection

A Strategy One connection object

Type:

Connection

import_info

Information about the import process

Type:

ImportInfo

package_info

Information about the package configuration and status

Type:

PackageInfo

validation

Information about the validation process

Type:

Validation

version

Version of the migration API

Type:

str

alter_migration_info(name=None, target_env=None, target_project=None)

Alter the migration object info.

Parameters:
  • name (str, optional) – The name of the migration object.

  • target_env (Connection | Environment | str, optional) –

    The target environment for the migration. It can be a Connection object, an Environment object, or a string representing the environment

    base url.

  • target_project (Project | str, optional) – The target project for the migration. It can be a Project object or a string representing the project ID.

Return type:

None

static build_package_config(connection, content, package_settings, object_action_map=None, object_dependents_map=None, default_action=None, default_dependents=False)
Build administration or object migration package definition based on the

provided content.

Parameters:
  • connection (Connection) – A Strategy One connection object.

  • content (list[Object | dict]) – List of objects to migrate.

  • package_settings (PackageSettings) – Package settings information.

  • object_action_map (list[tuple], optional) – List of tuples where the first element is the object type and the second element is the action to perform. If None, default_action will be used.

  • object_dependents_map (list[tuple], optional) – List of tuples where the first element is the object type and the second element is the include_dependents flag. If None, default_dependents will be used.

  • default_action (Action, optional) – Default action to apply to the list of migration objects passed with the content field. When an object in the content has the include_dependents flag set to True, then it’s dependents action will be taken from package_settings field. If not provided, the default_action from package_settings will be used.

  • default_dependents (bool, optional) – Default value for include_dependents flag. Defaults to False.

Returns:

A new PackageConfig object.

Return type:

PackageConfig

classmethod bulk_from_dict(source_list, connection=None, to_snake_case=True, with_missing_value=False)

Creates multiple objects from a list of dictionaries. For each dictionary provided the keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in the object’s _FROM_DICT_MAP.

Parameters:
  • cls (T) – Class (type) of the objects that should be created.

  • source_list (List[Dict[str, Any]]) – A list of dictionaries from which the objects will be constructed.

  • connection (Connection, optional) – A MSTR Connection object. Defaults to None.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.

  • with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

A list of objects of type T.

Return type:

T

certify(status=None, creator=None, last_updated_date=None, auto_sync=None)

Update a migration’s package certification status or trigger a process to synchronize the status.

Notes

If argument ‘auto_sync’ is True, the migration’s package certification status is synchronized with shared environment via storage service. Otherwise, the package certification status is updated with the definition of ‘status’, ‘creator’ and ‘last_updated_date’.

Parameters:
  • status (PackageCertificationStatus, str, optional) – Package certification status. Optional only if auto_sync is set to True.

  • creator (User, optional) – Creator of this file. Optional only if auto_sync is set to True.

  • last_updated_date (datetime, optional) – The last updated date of the certification operation. Optional only if auto_sync is set to True.

  • auto_sync (bool, optional) – If True, the migration’s package certification status is synchronized with shared environment via storage service.

Return type:

None

classmethod create(connection, body, project_id=None, project_name=None)

Create a totally new migration object.

Parameters:
  • connection (Connection) – A Strategy One connection object

  • body (dict) – a json body with migration details

  • project_id (str | None) – ID of the project

  • project_name (str | None) – Name of the project

Returns:

A new Migration object

Return type:

Migration

classmethod create_admin_migration(connection, toc_view, tree_view=None, name=None)

Create a new migration for administration migration purpose.

Parameters:
  • connection (Connection) – A Strategy One connection object.

  • toc_view (dict, PackageConfig) – A dictionary representing the TOC view or a PackageConfig object.

  • tree_view (str) – A string representing the tree view.

  • name (str, optional) – Name of the migration. Used for identification purposes for the convenience of the user. If None default name will be generated.

Returns:

A new Migration object.

Return type:

Migration

classmethod create_object_migration(connection, toc_view, tree_view=None, name=None, project_id=None, project_name=None)

Create a new migration for object migration purpose.

Parameters:
  • connection (Connection) – A Strategy One connection object.

  • toc_view (dict, PackageConfig) – A dictionary representing the TOC view or a PackageConfig object.

  • tree_view (str, optional) – A string representing the tree view.

  • name (str, optional) – Name of the migration. Used for identification purposes for the convenience of the user. If None default name will be generated.

  • project_id (str, optional) – ID of the project.

  • project_name (str, optional) – Name of the project.

Returns:

A new Migration object.

Return type:

Migration

classmethod create_project_merge_migration(connection, toc_view, tree_view=None, name=None, project_id=None, project_name=None)

Create a new migration for project merge migration purpose.

Parameters:
  • connection (Connection) – A Strategy One connection object.

  • toc_view (dict) – A dictionary representing the TOC view or a ProjectMergePackageSettings | ProjectMergePackageTocView object.

  • tree_view (str) – A string representing the tree view.

  • name (str, optional) – Name of the migration. Used for identification purposes for the convenience of the user. If None default name will be generated.

  • project_id (str, optional) – ID of the project.

  • project_name (str, optional) – Name of the project.

Returns:

A new Migration object.

Return type:

Migration

delete(force=False)

Deletes the Migration.

Parameters:

force (bool) – If True, no additional prompt will be shown before deleting Migration.

Returns:

True for success. False otherwise.

Return type:

bool

download_package(save_path=None)

Download the package binary to the specified location.

Parameters:
  • save_path (str | None) – a full path where the package binary will be saved.

  • None (if) –

  • directory. (the package will be saved in the current working) –

Returns:

Dictionary with the filepath and file binary.

Return type:

dict

fetch(attr=None)

Fetch the latest object’s state from the I-Server.

Note

This method can overwrite local changes made to the object.

Parameters:
  • attr (Optional[str]) – Attribute name to be fetched. If not specified

  • dictionary. (it will use all getters specified in _API_GETTERS) –

  • None. (Defaults to) –

Raises:

ValueError – If attr cannot be fetched.

Return type:

None

classmethod from_dict(source, connection=None, to_snake_case=True)

Initialize Migration object from dictionary.

Parameters:
  • source (dict) –

  • connection (Connection | None) –

  • to_snake_case (bool) –

get_migration_content()

Get full body of the migration object

Return type:

dict

list_properties(excluded_properties=None)

Fetches all attributes from the server and converts all properties of the object to a dictionary.

Parameters:

excluded_properties (list[str], optional) – A list of object properties that should be excluded from the dict. Defaults to None.

Returns:

A dictionary which keys are object’s attribute names, and

which values are object’s attribute values.

Return type:

dict

migrate(target_env, target_project_id=None, target_project_name=None, generate_undo=True)

Migrate the package to the target environment. Project information is required in case of object migration.

Parameters:
  • target_env (Connection, Environment) – Destination environment to migrate the package.

  • target_project_id (str, optional) – ID of the target project. Project information is required in case of object migration.

  • target_project_name (str, optional) – Name of the target project. Project information is required in case of object migration.

  • generate_undo (bool, optional) – Specify weather to generate an undo package or not. True by default.

classmethod migrate_from_file(connection, file_path, package_type, name=None, target_project_id=None, target_project_name=None)

Create a new migration object from an existing package file. Project information is required in case of object migration.

Parameters:
  • connection (Connection) – A Strategy One connection object.

  • file_path (str) – A full path to the package file.

  • package_type (PackageType | str) – Type of the package.

  • name (str, optional) – Name of the migration. Used for identification purposes for the convenience of the user. Defaults to None.

  • target_project_id (str, optional) – ID of the target project. Project information is required in case of object migration.

  • target_project_name (str, optional) – Name of the target project. Project information is required in case of object migration.

Returns:

A new Migration object.

Return type:

Migration

print()

Pretty Print all properties of the object.

Return type:

None

reuse(target_env, target_project_id=None, target_project_name=None)

Reuse an already migrated package to create a new one with the same properties, and then migrate it to a different environment or the same one.

Parameters:
  • target_env (Connection, Environment) – Target environment to migrate reused package to.

  • target_project_id (str, optional) – ID of the target project. Project information is required in case of object migration.

  • target_project_name (str, optional) – Name of the target project. Project information is required in case of object migration.

Returns:

A new Migration object based on the reused package.

Return type:

Migration

reverse(target_env, target_project_id=None)

Reverse the migration process by importing the undo package.

Parameters:
  • target_env (Environment, Connection) – Destination environment to reverse the migration.

  • target_project_id (str, optional) – ID of the target project. Project information is required in case of object migration.

Return type:

None

classmethod to_csv(objects, name, path=None, properties=None)

Exports MSTR objects to a csv file.

Optionally, saves only the object properties specified in the properties parameter.

Parameters:
  • objects (T | list[T]) – List of objects of the same type that

  • exported. (will be) –

  • name (str) – The name of the csv file ending with ‘.csv’

  • path (Optional[str], optional) – A path to the directory where the file will be saved. Defaults to None.

  • properties (Optional[list[str]], optional) – A list of object’s attribute names that should be included in the exported file. Defaults to None.

Raises:
  • TypeError – If objects is not of type T or list of type T

  • objects.

Return type:

None

to_dataframe()

Converts all properties of the object to a dataframe.

Returns:

A DataFrame object containing object properties.

Return type:

DataFrame

to_dict(camel_case=True)

Converts an object to a dictionary excluding object’s private properties. When converting the object to a dictionary, the object’s attributes become the dictionary’s keys and are in camel case by default Attribute values stored as objects are automatically converted to non-/ primitive data structures.

Parameters:

camel_case (bool, optional) – Set to True if attribute names should be converted from snake case to camel case. Defaults to True.

Returns:

A dictionary representation of object’s attributes and values.

By default, the dictionary keys are in camel case.

Return type:

dict

trigger_validation(target_env, target_project_id=None, target_project_name=None)

Trigger a validate process to migrate the package from the source environment to the destination environment according to the action defined, without committing any changes to the metadata. This API can only be called by administrator when package is created.

Parameters:
  • target_env (Connection, Environment) – Destination environment to validate the package.

  • target_project_id (str, optional) – ID of the target project. Project information is required in case of object migration.

  • target_project_name (str, optional) – Name of the target project. Project information is required in case of object migration.

Return type:

None

update_properties()

Save compatible local changes of the object attributes to the I-Server. Changes are retrieved from the self._altered_properties dictionary. After the process of update has finished, self._altered_properties is cleared. For this method to work properly, you must override the _alter_properties() method in a subclass.

Raises:

requests.HTTPError – If I-Server raises exception

Return type:

None

mstrio.object_management.migration.migration.list_migration_possible_content(connection, package_type)

List possible content for migration process based on the package type and environment version.

Parameters:
  • connection (Connection) – A Strategy One connection object

  • package_type (PackageType) – Type of the package

Returns:

Set of MigratedObjectTypes

Return type:

list[ObjectTypes | ObjectSubTypes]

mstrio.object_management.migration.migration.list_migrations(connection, name=None, migration_purpose=None, package_status=None, import_status=None, limit=None, to_dictionary=False)

Get list of Migration objects. Optionally use to_dictionary to choose output format.

Parameters:
  • connection (Connection) – A Strategy One connection object

  • name (str, optional) – characters that the Migration name must contain

  • migration_purpose (MigrationPurpose, str, optional) – purpose of the migration can be either ‘object_migration’, ‘project_merge’ or ‘migration_from_shared_file_store’. If None returns migration of all purposes

  • package_status (PackageStatus, str, optional) – status of the migration package

  • import_status (ImportStatus, str, optional) – status of the Migration import process

  • limit (integer, optional) – limit the number of elements returned. If None all object are returned

  • to_dictionary (bool, optional) – If True returns dict, by default (False) returns Metric objects

Returns:

List of Migration objects or list of dictionaries

Return type:

list[Migration] | list[dict]