def get_linked_parent()

in modular_sdk/services/parent_service.py [0:0]


    def get_linked_parent(self, tenant_name: str, cloud: Optional[str],
                          customer_name: str,
                          type_: ParentType) -> Optional[Parent]:
        """

        :param tenant_name:
        :param cloud:
        :param customer_name:
        :param type_:
        :return:
        """
        _LOG.debug(f'Looking for a disabled parent with type {type_} for '
                   f'tenant {tenant_name}')
        disabled = next(self.get_by_tenant_scope(
            customer_id=customer_name,
            type_=type_,
            tenant_name=tenant_name,
            disabled=True,
            limit=1
        ), None)
        if disabled:
            _LOG.info('Disabled parent is found. Returning None')
            return
        _LOG.debug(f'Looking for a specific parent with type {type_} for '
                   f'tenant {tenant_name}')
        specific = next(self.get_by_tenant_scope(
            customer_id=customer_name,
            type_=type_,
            tenant_name=tenant_name,
            disabled=False,
            limit=1
        ), None)
        if specific:
            _LOG.info('Specific parent is found. Returning it')
            return specific
        if cloud:
            _LOG.debug(f'Looking for a parent with scope ALL and type {type_} '
                       f'for tenant\'s cloud')
            all_cloud = next(self.get_by_all_scope(
                customer_id=customer_name,
                type_=type_,
                cloud=cloud.upper()
            ), None)
            if all_cloud:
                _LOG.info('Parent with type ALL and tenant\'s cloud found.')
                return all_cloud
        all_ = next(self.get_by_all_scope(
            customer_id=customer_name,
            type_=type_,
        ), None)
        if all_:
            _LOG.info('Parent with type ALL found.')
            return all_
        _LOG.info(f'No parent with type {type_} for '
                  f'tenant {tenant_name} found')