def resolve()

in docker/services/rightsizer_parent_service.py [0:0]


    def resolve(self, licensed_parent: Parent,
                scan_tenants: list = None) -> Parent:
        """
        Resolves RIGHTSIZER parent from RIGHTSIZER_LICENSES.

        Depends on the RIGHTSIZER_LICENSES scope, RIGHTSIZER
        parent will be resolved in different ways:

        ALL_TENANTS: first RIGHTSIZER parent linked to same
        application with ALL_TENANTS scope and
        matching cloud will be taken

        SPECIFIC_TENANTS: RIGHSIZER parent will be taken from scan_tenants,
        from Tenant.pid map

        :param licensed_parent: Parent of RIGHTSIZER_LICENSES type
        :param scan_tenants: list of tenants to scan -
        required for SPECIFIC_TENANTS scope

        :return: Parent with RIGHTSIZER type
        """
        _LOG.debug(f'Searching for RIGHTSIZER parent for licensed parent '
                   f'\'{licensed_parent.parent_id}\'')
        licensed_parent_meta = self.get_parent_meta(parent=licensed_parent)

        if licensed_parent.scope == ParentScope.ALL.value:
            _LOG.debug(f'Licensed scope: {ParentScope.ALL.value}. '
                       f'Going to search for Parent directly')
            parents = self.list_application_parents(
                application_id=licensed_parent.application_id,
                only_active=True,
                type_=ParentType.RIGHTSIZER_PARENT.value
            )

            for parent in parents:
                if parent.scope == ParentScope.ALL.value and \
                        licensed_parent.cloud == parent.cloud:
                    return parent
        elif licensed_parent.scope == ParentScope.SPECIFIC.value \
                and scan_tenants:
            _LOG.debug(f'Licensed scope: {ParentScope.SPECIFIC.value}. '
                       f'Validating tenant {licensed_parent.tenant_name}')
            tenant = self.tenant_service.get(
                tenant_name=licensed_parent.tenant_name)

            parent_map = tenant.parent_map.as_dict()

            linked_parent_id = parent_map.get(
                TENANT_PARENT_MAP_RIGHTSIZER_TYPE)
            linked_licensed_parent_id = parent_map.get(
                TENANT_PARENT_MAP_RIGHTSIZER_LICENSES_TYPE
            )
            if linked_licensed_parent_id != licensed_parent.parent_id:
                return
            if not linked_parent_id:
                _LOG.warning(f'Tenant \'{licensed_parent.tenant_name}\' '
                             f'don\'t have RIGHTSIZER type linkage.')
                return
            return self.get_parent_by_id(parent_id=linked_parent_id)