本文整理匯總了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', {})
}