本文整理汇总了Python中pulp.server.db.model.consumer.RepoProfileApplicability.applicability方法的典型用法代码示例。如果您正苦于以下问题:Python RepoProfileApplicability.applicability方法的具体用法?Python RepoProfileApplicability.applicability怎么用?Python RepoProfileApplicability.applicability使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulp.server.db.model.consumer.RepoProfileApplicability
的用法示例。
在下文中一共展示了RepoProfileApplicability.applicability方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: regenerate_applicability
# 需要导入模块: from pulp.server.db.model.consumer import RepoProfileApplicability [as 别名]
# 或者: from pulp.server.db.model.consumer.RepoProfileApplicability import applicability [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},
projection=['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:
msg = "Profiler for content type [%s] does not support applicability" % content_type
_logger.debug(msg)
return
try:
# Create a new RepoProfileApplicability object and save it in the db
RepoProfileApplicability.objects.create(profile_hash,
bound_repo_id,
profile,
applicability)
except DuplicateKeyError:
# Update existing applicability
if not existing_applicability:
applicability_dict = RepoProfileApplicability.get_collection().find_one(
{'repo_id': bound_repo_id, 'profile_hash': profile_hash})
existing_applicability = RepoProfileApplicability(**applicability_dict)
existing_applicability.applicability = applicability
existing_applicability.save()