本文整理汇总了Python中nailgun.objects.Release.get_all_components方法的典型用法代码示例。如果您正苦于以下问题:Python Release.get_all_components方法的具体用法?Python Release.get_all_components怎么用?Python Release.get_all_components使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nailgun.objects.Release
的用法示例。
在下文中一共展示了Release.get_all_components方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GET
# 需要导入模块: from nailgun.objects import Release [as 别名]
# 或者: from nailgun.objects.Release import get_all_components [as 别名]
def GET(self, release_id):
""":returns: JSONized component data for release and releated plugins.
:http: * 200 (OK)
* 404 (release not found in db)
"""
release = self.get_object_or_404(Release, release_id)
components = Release.get_all_components(release)
return [ComponentSerializer.serialize(c) for c in components]
示例2: get_cluster_attributes_by_components
# 需要导入模块: from nailgun.objects import Release [as 别名]
# 或者: from nailgun.objects.Release import get_all_components [as 别名]
def get_cluster_attributes_by_components(cls, components, release_id):
"""Enable cluster attributes by given components
:param components: list of component names
:type components: list of strings
:param release_id: Release model id
:type release_id: str
:returns: dict -- objects with enabled attributes for cluster
"""
def _update_attributes_dict_by_binds_exp(bind_exp, value):
"""Update cluster and attributes data with bound values
:param bind_exp: path to specific attribute for model in format
model:some.attribute.value. Model can be
settings|cluster
:type bind_exp: str
:param value: value for specific attribute
:type value: bool|str|int
:returns: None
"""
model, attr_expr = bind_exp.split(':')
if model not in ('settings', 'cluster'):
return
path_items = attr_expr.split('.')
path_items.insert(0, model)
attributes = cluster_attributes
for i in six.moves.range(0, len(path_items) - 1):
attributes = attributes.setdefault(path_items[i], {})
attributes[path_items[-1]] = value
release = Release.get_by_uid(release_id)
cluster_attributes = {}
for component in Release.get_all_components(release):
if component['name'] in components:
for bind_item in component.get('bind', []):
if isinstance(bind_item, six.string_types):
_update_attributes_dict_by_binds_exp(bind_item, True)
elif isinstance(bind_item, list):
_update_attributes_dict_by_binds_exp(bind_item[0],
bind_item[1])
return {
'editable': cluster_attributes.get('settings', {}),
'cluster': cluster_attributes.get('cluster', {})
}