当前位置: 首页>>代码示例>>Python>>正文


Python UnitProfile.get_collection方法代码示例

本文整理汇总了Python中pulp.server.db.model.consumer.UnitProfile.get_collection方法的典型用法代码示例。如果您正苦于以下问题:Python UnitProfile.get_collection方法的具体用法?Python UnitProfile.get_collection怎么用?Python UnitProfile.get_collection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pulp.server.db.model.consumer.UnitProfile的用法示例。


在下文中一共展示了UnitProfile.get_collection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: tearDown

# 需要导入模块: from pulp.server.db.model.consumer import UnitProfile [as 别名]
# 或者: from pulp.server.db.model.consumer.UnitProfile import get_collection [as 别名]
 def tearDown(self):
     super(BaseProfilerConduitTests, self).tearDown()
     Consumer.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     RepoContentUnit.get_collection().remove()
     UnitProfile.get_collection().remove()
     typedb.clean()
     factory.reset()
开发者ID:fdammeke,项目名称:pulp,代码行数:12,代码来源:test_profiler_conduit.py

示例2: setUp

# 需要导入模块: from pulp.server.db.model.consumer import UnitProfile [as 别名]
# 或者: from pulp.server.db.model.consumer.UnitProfile import get_collection [as 别名]
 def setUp(self):
     super(BaseProfilerConduitTests, self).setUp()
     Consumer.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     RepoContentUnit.get_collection().remove()
     UnitProfile.get_collection().remove()
     plugin_api._create_manager()
     typedb.update_database([self.TYPE_1_DEF, self.TYPE_2_DEF])
     mock_plugins.install()
开发者ID:jeremycline,项目名称:pulp,代码行数:12,代码来源:test_profiler.py

示例3: setUp

# 需要导入模块: from pulp.server.db.model.consumer import UnitProfile [as 别名]
# 或者: from pulp.server.db.model.consumer.UnitProfile import get_collection [as 别名]
 def setUp(self):
     base.PulpServerTests.setUp(self)
     Consumer.get_collection().remove()
     UnitProfile.get_collection().remove()
     plugins._create_manager()
     mock_plugins.install()
     profiler, cfg = plugins.get_profiler_by_type('rpm')
     profiler.units_applicable = \
         Mock(side_effect=lambda i,r,t,u,c,x:
              [ApplicabilityReport('mysummary', 'mydetails')])
开发者ID:domcleal,项目名称:pulp,代码行数:12,代码来源:test_applicability_manager.py

示例4: setUp

# 需要导入模块: from pulp.server.db.model.consumer import UnitProfile [as 别名]
# 或者: from pulp.server.db.model.consumer.UnitProfile import get_collection [as 别名]
 def setUp(self):
     base.PulpWebserviceTests.setUp(self)
     Consumer.get_collection().remove()
     UnitProfile.get_collection().remove()
     plugin_api._create_manager()
     mock_plugins.install()
     profiler = plugin_api.get_profiler_by_type('errata')[0]
     profiler.unit_applicable = \
         mock.Mock(side_effect=lambda i,u,c,x:
             ApplicabilityReport(u, True, self.SUMMARY, self.DETAILS))
开发者ID:pkilambi,项目名称:pulp,代码行数:12,代码来源:test_consumer_controller.py

示例5: tearDown

# 需要导入模块: from pulp.server.db.model.consumer import UnitProfile [as 别名]
# 或者: from pulp.server.db.model.consumer.UnitProfile import get_collection [as 别名]
 def tearDown(self):
     super(BaseProfilerConduitTests, self).tearDown()
     Consumer.get_collection().remove()
     model.Repository.objects.delete()
     model.Distributor.objects.delete()
     Bind.get_collection().remove()
     RepoContentUnit.get_collection().remove()
     UnitProfile.get_collection().remove()
     typedb.clean()
     factory.reset()
     mock_plugins.reset()
开发者ID:alanoe,项目名称:pulp,代码行数:13,代码来源:test_profiler.py

示例6: batch_regenerate_applicability

# 需要导入模块: from pulp.server.db.model.consumer import UnitProfile [as 别名]
# 或者: from pulp.server.db.model.consumer.UnitProfile import get_collection [as 别名]
    def batch_regenerate_applicability(repo_id, existing_applicability_ids):
        """
        Regenerate and save applicability data for a batch of existing applicabilities

        :param repo_id: Repository id for which applicability is being calculated
        :type repo_id: str
        :param existing_applicability_ids: Tuple of Object Ids for applicability profiles
        :type existing_applicability_ids: tuple of dicts in form of {"_id": ObjectID('mongo-id')}
        """
        id_list = [id['_id'] for id in existing_applicability_ids]
        existing_applicabilities = RepoProfileApplicability.get_collection().find(
            {"_id": {"$in": id_list}})
        for existing_applicability in existing_applicabilities:
                # Convert cursor to RepoProfileApplicability object
            existing_applicability = RepoProfileApplicability(**dict(existing_applicability))
            profile_hash = existing_applicability['profile_hash']
            unit_profile = UnitProfile.get_collection().find_one({'profile_hash': profile_hash},
                                                                 fields=['id', 'content_type'])
            if unit_profile is None:
                # Unit profiles change whenever packages are installed or removed on consumers,
                # and it is possible that existing_applicability references a UnitProfile
                # that no longer exists. This is harmless, as Pulp has a monthly cleanup task
                # that will identify these dangling references and remove them.
                continue

            # Regenerate applicability data for given unit_profile and repo id
            ApplicabilityRegenerationManager.regenerate_applicability(
                profile_hash, unit_profile['content_type'], unit_profile['id'], repo_id,
                existing_applicability)
开发者ID:maxamillion,项目名称:pulp,代码行数:31,代码来源:applicability.py

示例7: regenerate_applicability_for_repos

# 需要导入模块: from pulp.server.db.model.consumer import UnitProfile [as 别名]
# 或者: from pulp.server.db.model.consumer.UnitProfile import get_collection [as 别名]
    def regenerate_applicability_for_repos(repo_criteria):
        """
        Regenerate and save applicability data affected by given updated repositories.

        :param repo_criteria: The repo selection criteria
        :type repo_criteria: dict
        """
        repo_criteria = Criteria.from_dict(repo_criteria)
        repo_query_manager = managers.repo_query_manager()

        # Process repo criteria
        repo_criteria.fields = ['id']
        repo_ids = [r['id'] for r in repo_query_manager.find_by_criteria(repo_criteria)]

        for repo_id in repo_ids:
            # Find all existing applicabilities for given repo_id
            existing_applicabilities = RepoProfileApplicability.get_collection().find(
                {'repo_id': repo_id})
            for existing_applicability in existing_applicabilities:
                # Convert cursor to RepoProfileApplicability object
                existing_applicability = RepoProfileApplicability(**dict(existing_applicability))
                profile_hash = existing_applicability['profile_hash']
                unit_profile = UnitProfile.get_collection().find_one({'profile_hash': profile_hash},
                                                                     fields=['id', 'content_type'])
                if unit_profile is None:
                    # Unit profiles change whenever packages are installed or removed on consumers,
                    # and it is possible that existing_applicability references a UnitProfile
                    # that no longer exists. This is harmless, as Pulp has a monthly cleanup task
                    # that will identify these dangling references and remove them.
                    continue

                # Regenerate applicability data for given unit_profile and repo id
                ApplicabilityRegenerationManager.regenerate_applicability(
                    profile_hash, unit_profile['content_type'], unit_profile['id'], repo_id,
                    existing_applicability)
开发者ID:beav,项目名称:pulp,代码行数:37,代码来源:applicability.py

示例8: regenerate_applicability_for_repos

# 需要导入模块: from pulp.server.db.model.consumer import UnitProfile [as 别名]
# 或者: from pulp.server.db.model.consumer.UnitProfile import get_collection [as 别名]
    def regenerate_applicability_for_repos(repo_criteria):
        """
        Regenerate and save applicability data affected by given updated repositories.

        :param repo_criteria: The repo selection criteria
        :type repo_criteria: dict
        """
        repo_criteria = Criteria.from_dict(repo_criteria)
        repo_query_manager = managers.repo_query_manager()

        # Process repo criteria
        repo_criteria.fields = ["id"]
        repo_ids = [r["id"] for r in repo_query_manager.find_by_criteria(repo_criteria)]

        for repo_id in repo_ids:
            # Find all existing applicabilities for given repo_id
            existing_applicabilities = RepoProfileApplicability.get_collection().find({"repo_id": repo_id})
            for existing_applicability in existing_applicabilities:
                # Convert cursor to RepoProfileApplicability object
                existing_applicability = RepoProfileApplicability(**dict(existing_applicability))
                profile_hash = existing_applicability["profile_hash"]
                unit_profile = UnitProfile.get_collection().find_one(
                    {"profile_hash": profile_hash}, fields=["id", "content_type"]
                )
                # Regenerate applicability data for given unit_profile and repo id
                ApplicabilityRegenerationManager.regenerate_applicability(
                    profile_hash, unit_profile["content_type"], unit_profile["id"], repo_id, existing_applicability
                )
开发者ID:preethit,项目名称:pulp-1,代码行数:30,代码来源:applicability.py

示例9: remove_orphans

# 需要导入模块: from pulp.server.db.model.consumer import UnitProfile [as 别名]
# 或者: from pulp.server.db.model.consumer.UnitProfile import get_collection [as 别名]
    def remove_orphans():
        """
        The RepoProfileApplicability objects can become orphaned over time, as repositories are
        deleted, or as consumer profiles change. This method searches for RepoProfileApplicability
        objects that reference either repositories or profile hashes that no longer exist in Pulp.
        """
        # Find all of the repo_ids that are referenced by RepoProfileApplicability objects
        rpa_collection = RepoProfileApplicability.get_collection()
        rpa_repo_ids = rpa_collection.distinct('repo_id')

        # Find all of the repo_ids that exist in Pulp
        repo_ids = model.Repository.objects.distinct('repo_id')

        # Find rpa_repo_ids that aren't part of repo_ids
        missing_repo_ids = list(set(rpa_repo_ids) - set(repo_ids))

        # Remove all RepoProfileApplicability objects that reference these repo_ids
        if missing_repo_ids:
            rpa_collection.remove({'repo_id': {'$in': missing_repo_ids}})

        # Next, we need to find profile_hashes that don't exist in the UnitProfile collection
        rpa_profile_hashes = rpa_collection.distinct('profile_hash')

        # Find the profile hashes that exist in current UnitProfiles
        profile_hashes = UnitProfile.get_collection().distinct('profile_hash')

        # Find profile hashes that we have RepoProfileApplicability objects for, but no real
        # UnitProfiles
        missing_profile_hashes = list(set(rpa_profile_hashes) - set(profile_hashes))

        # Remove all RepoProfileApplicability objects that reference these profile hashes
        if missing_profile_hashes:
            rpa_collection.remove({'profile_hash': {'$in': missing_profile_hashes}})
开发者ID:alexxa,项目名称:pulp,代码行数:35,代码来源:applicability.py

示例10: batch_regenerate_applicability

# 需要导入模块: from pulp.server.db.model.consumer import UnitProfile [as 别名]
# 或者: from pulp.server.db.model.consumer.UnitProfile import get_collection [as 别名]
    def batch_regenerate_applicability(repo_id, profile_hashes):
        """
        Regenerate and save applicability data for a batch of existing applicabilities

        :param repo_id: Repository id for which applicability is being calculated
        :type repo_id: str
        :param profile_hashes: Tuple of consumer profile hashes for applicability profiles.
                               Don't pass too much of these, all the profile data
                               associated with these hashes is loaded into the memory.
        :type profile_hashes: tuple of dicts in form of {'profile_hash': str}
        """
        profile_hash_list = [phash['profile_hash'] for phash in profile_hashes]
        existing_applicabilities = RepoProfileApplicability.get_collection().find(
            {"repo_id": repo_id, "profile_hash": {"$in": profile_hash_list}})
        for existing_applicability in list(existing_applicabilities):
                # Convert cursor to RepoProfileApplicability object
            existing_applicability = RepoProfileApplicability(**dict(existing_applicability))
            profile_hash = existing_applicability['profile_hash']
            unit_profile = UnitProfile.get_collection().find_one({'profile_hash': profile_hash},
                                                                 projection=['id', 'content_type'])
            if unit_profile is None:
                # Unit profiles change whenever packages are installed or removed on consumers,
                # and it is possible that existing_applicability references a UnitProfile
                # that no longer exists. This is harmless, as Pulp has a monthly cleanup task
                # that will identify these dangling references and remove them.
                continue

            # Regenerate applicability data for given unit_profile and repo id
            ApplicabilityRegenerationManager.regenerate_applicability(
                profile_hash, unit_profile['content_type'], unit_profile['id'], repo_id,
                existing_applicability)
开发者ID:alexxa,项目名称:pulp,代码行数:33,代码来源:applicability.py

示例11: test_consumer_deleted

# 需要导入模块: from pulp.server.db.model.consumer import UnitProfile [as 别名]
# 或者: from pulp.server.db.model.consumer.UnitProfile import get_collection [as 别名]
 def test_consumer_deleted(self):
     # Setup
     self.populate()
     collection = UnitProfile.get_collection()
     manager = factory.consumer_profile_manager()
     manager.update(self.CONSUMER_ID, self.TYPE_1, self.PROFILE_1)
     manager.update(self.CONSUMER_ID, self.TYPE_2, self.PROFILE_2)
     collection = UnitProfile.get_collection()
     cursor = collection.find({"consumer_id": self.CONSUMER_ID})
     profiles = list(cursor)
     self.assertEquals(len(profiles), 2)
     # Test
     manager.consumer_deleted(self.CONSUMER_ID)
     cursor = collection.find()
     profiles = list(cursor)
     self.assertEquals(len(profiles), 0)
开发者ID:ryanschneider,项目名称:pulp,代码行数:18,代码来源:test_profile_manager.py

示例12: update

# 需要导入模块: from pulp.server.db.model.consumer import UnitProfile [as 别名]
# 或者: from pulp.server.db.model.consumer.UnitProfile import get_collection [as 别名]
    def update(self, consumer_id, content_type, profile):
        """
        Update a unit profile.
        Created if not already exists.
        @param consumer_id: uniquely identifies the consumer.
        @type consumer_id: str
        @param content_type: The profile (content) type ID.
        @type content_type: str
        @param profile: The unit profile
        @type profile: object
        """
        try:
            profiler, config = plugin_api.get_profiler_by_type(content_type)
        except plugin_exceptions.PluginNotFound:
            # Not all profile types have a type specific profiler, so let's use the baseclass
            # Profiler
            profiler, config = (Profiler(), {})
        consumer = factory.consumer_manager().get_consumer(consumer_id)
        # Allow the profiler a chance to update the profile before we save it
        profile = profiler.update_profile(consumer, content_type, profile, config)

        try:
            p = self.get_profile(consumer_id, content_type)
            p['profile'] = profile
            # We store the profile's hash anytime the profile gets altered
            p['profile_hash'] = UnitProfile.calculate_hash(profile)
        except MissingResource:
            p = UnitProfile(consumer_id, content_type, profile)
        collection = UnitProfile.get_collection()
        collection.save(p, safe=True)
        return p
开发者ID:ashcrow,项目名称:pulp,代码行数:33,代码来源:profile.py

示例13: regenerate_applicability_for_repos

# 需要导入模块: from pulp.server.db.model.consumer import UnitProfile [as 别名]
# 或者: from pulp.server.db.model.consumer.UnitProfile import get_collection [as 别名]
    def regenerate_applicability_for_repos(self, repo_criteria=None):
        """
        Regenerate and save applicability data affected by given updated repositories.

        :param repo_criteria: The repo selection criteria
        :type repo_criteria: pulp.server.db.model.criteria.Criteria
        """
        repo_query_manager = managers.repo_query_manager()

        # Process repo criteria
        repo_criteria.fields = ['id']
        repo_ids = [r['id'] for r in repo_query_manager.find_by_criteria(repo_criteria)]

        for repo_id in repo_ids:
            # Find all existing applicabilities for given repo_id
            existing_applicabilities = RepoProfileApplicability.get_collection().find({'repo_id':repo_id})
            for existing_applicability in existing_applicabilities:
                # Convert cursor to RepoProfileApplicability object
                existing_applicability = RepoProfileApplicability(**dict(existing_applicability))
                profile_hash = existing_applicability['profile_hash']
                unit_profile = UnitProfile.get_collection().find_one({'profile_hash': profile_hash},
                                                                     fields=['id','content_type'])
                # Regenerate applicability data for given unit_profile and repo id
                self.regenerate_applicability(profile_hash, unit_profile['content_type'],
                                              unit_profile['id'],
                                              repo_id,
                                              existing_applicability)
开发者ID:ashcrow,项目名称:pulp,代码行数:29,代码来源:applicability.py

示例14: regenerate_applicability

# 需要导入模块: from pulp.server.db.model.consumer import UnitProfile [as 别名]
# 或者: from pulp.server.db.model.consumer.UnitProfile import get_collection [as 别名]
    def regenerate_applicability(profile_hash, content_type, profile_id, bound_repo_id, existing_applicability=None):
        """
        Regenerate and save applicability data for given profile and bound repo id.
        If existing_applicability is not None, replace it with the new applicability data.

        :param profile_hash: hash of the unit profile
        :type profile_hash: basestring

        :param content_type: profile (unit) type ID
        :type content_type: str

        :param profile_id: unique id of the unit profile
        :type profile_id: str

        :param bound_repo_id: repo id to be used to calculate applicability
                              against the given unit profile
        :type bound_repo_id: str

        :param existing_applicability: existing RepoProfileApplicability object to be replaced
        :type existing_applicability: pulp.server.db.model.consumer.RepoProfileApplicability
        """
        profiler_conduit = ProfilerConduit()
        # Get the profiler for content_type of given unit_profile
        profiler, profiler_cfg = ApplicabilityRegenerationManager._profiler(content_type)

        # Check if the profiler supports applicability, else return
        if profiler.calculate_applicable_units == Profiler.calculate_applicable_units:
            # If base class calculate_applicable_units method is called,
            # skip applicability regeneration
            return

        # Find out which content types have unit counts greater than zero in the bound repo
        repo_content_types = ApplicabilityRegenerationManager._get_existing_repo_content_types(bound_repo_id)
        # Get the intersection of existing types in the repo and the types that the profiler
        # handles. If the intersection is not empty, regenerate applicability
        if set(repo_content_types) & set(profiler.metadata()["types"]):
            # Get the actual profile for existing_applicability or lookup using profile_id
            if existing_applicability:
                profile = existing_applicability.profile
            else:
                unit_profile = UnitProfile.get_collection().find_one({"id": profile_id}, fields=["profile"])
                profile = unit_profile["profile"]
            call_config = PluginCallConfiguration(plugin_config=profiler_cfg, repo_plugin_config=None)
            try:
                applicability = profiler.calculate_applicable_units(
                    profile, bound_repo_id, call_config, profiler_conduit
                )
            except NotImplementedError:
                logger.debug("Profiler for content type [%s] does not support applicability" % content_type)
                return

            if existing_applicability:
                # Update existing applicability object
                existing_applicability.applicability = applicability
                existing_applicability.save()
            else:
                # Create a new RepoProfileApplicability object and save it in the db
                RepoProfileApplicability.objects.create(
                    profile_hash, bound_repo_id, unit_profile["profile"], applicability
                )
开发者ID:preethit,项目名称:pulp-1,代码行数:62,代码来源:applicability.py

示例15: _add_profiles_to_consumer_map_and_get_hashes

# 需要导入模块: from pulp.server.db.model.consumer import UnitProfile [as 别名]
# 或者: from pulp.server.db.model.consumer.UnitProfile import get_collection [as 别名]
def _add_profiles_to_consumer_map_and_get_hashes(consumer_ids, consumer_map):
    """
    Query for all the profiles associated with the given list of consumer_ids, add those
    profiles to the consumer_map, and then return a list of all profile_hashes.

    :param consumer_ids: A list of consumer_ids that we want to map the profiles to
    :type  consumer_ids: list
    :param consumer_map: A dictionary mapping consumer_ids to a dictionary with key 'profiles',
                         which indexes a list that this method will append the found profiles
                         to.
    :type  consumer_map: dict
    :return:             A list of the profile_hashes that were associated with the given
                         consumers
    :rtype:              list
    """
    profiles = UnitProfile.get_collection().find(
        {'consumer_id': {'$in': consumer_ids}},
        projection=['consumer_id', 'profile_hash'])
    profile_hashes = set()
    for p in profiles:
        consumer_map[p['consumer_id']]['profiles'].append(p)
        profile_hashes.add(p['profile_hash'])
    # Let's return a list of all the unique profile_hashes for the query we will do a
    # bit later for applicability data
    return list(profile_hashes)
开发者ID:alexxa,项目名称:pulp,代码行数:27,代码来源:applicability.py


注:本文中的pulp.server.db.model.consumer.UnitProfile.get_collection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。