Skip to content

Extract Collections

Overview

Extract and outputs the collection hierarchy structure.

Parameters:

Name Type Description Default
start_collection_name str

Collection to start on.

required
safe_delete_name str

The client name to be used when printing the safe delete commands. Default is 'client'.

'client'
api_version Optional[str]

API version to use. If None, default is "2019-11-01-preview".

None

Returns:

Type Description
None

None. Will print out the script to create the collection hierarchy structure

None

starting at the start_collection_name.

Source code in purviewautomation/collections.py
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
def extract_collections(
    self, start_collection_name: str, safe_delete_name: str = "client", api_version: Optional[str] = None
) -> None:
    """Extract and outputs the collection hierarchy structure.

    Args:
        start_collection_name: Collection to start on.
        safe_delete_name:  The client name to be used when printing
            the safe delete commands. Default is 'client'.
        api_version: API version to use. If None, default is "2019-11-01-preview".

    Returns:
        None. Will print out the script to create the collection hierarchy structure
        starting at the start_collection_name.
    """
    if not api_version:
        api_version = self.collections_api_version

    collections_list = []
    recursive_list = []

    start_collection_name = [start_collection_name]
    for name in start_collection_name:
        name = self.get_real_collection_name(name)
        self._recursive_append(name, collections_list)
        if collections_list[0] is not None:
            for item in collections_list:
                self._recursive_append(item, recursive_list)
            for item2 in recursive_list:
                if item2 is not None:
                    collections_list.append(item2)
                    self._recursive_append(item2, recursive_list)

    self._safe_delete_recursivly(collections_list, safe_delete_name, name, True)

Examples

If the Purview collections look like this:

Extract Collections

To extract the exact script to create the hierarchy starting from collection1:

client.extract_collections(start_collection_name="collection1")

Will output (print) to the screen the script to recreate the hierarchy:

Extract Collections

Important

The start_collection parameter value may show random strings as the name. This is because the code will grab the original actual name to recreate the hierarchy exactly as it was (same actual and friendly names). For more info on what actual names and friendly names mean, see: Purview Names Overview.

The script can be saved for later use or to deploy to other Purview (UAT/PROD) environments.

For example, another Purview that's used as a UAT Purview:

Extract Collections

To recreate the same hierarchy as the original Purview, just update the initial start_collection from purview-test-2 to the new purview-uat-1:

client.create_collections(start_collection='purview-uat-1', collection_names='collection1',safe_delete_friendly_name='collection1')         

client.create_collections(start_collection='collection1', collection_names='test1', safe_delete_friendly_name='test1')

client.create_collections(start_collection='test1', collection_names='test2', safe_delete_friendly_name='test2')

client.create_collections(start_collection='test2', collection_names='test3', safe_delete_friendly_name='test3')

client.create_collections(start_collection='test3', collection_names='test4', safe_delete_friendly_name='test4')

The output will be the exact same hierarchy as the original Purview (same actual and friendly names) so it's consistent across environments:

Extract Collections

Info

Make sure the Service Principal/user is authenticated to the new Purview and assigned the Collection Admin role on the initial start collection (purview-uat-1 in the example above).