本文整理汇总了Python中nailgun.objects.Cluster.get_network_roles方法的典型用法代码示例。如果您正苦于以下问题:Python Cluster.get_network_roles方法的具体用法?Python Cluster.get_network_roles怎么用?Python Cluster.get_network_roles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nailgun.objects.Cluster
的用法示例。
在下文中一共展示了Cluster.get_network_roles方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_network_role_mapping
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import get_network_roles [as 别名]
def _get_network_role_mapping(cls, node, mapping):
"""Aggregates common logic for methods 'get_network_role_mapping_to_ip'
and 'get_network_role_mapping_to_interfaces'.
"""
roles = dict()
for role in Cluster.get_network_roles(node.cluster):
default_mapping = mapping.get(role['default_mapping'])
if default_mapping:
roles[role['id']] = default_mapping
return roles
示例2: _get_network_role_mapping
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import get_network_roles [as 别名]
def _get_network_role_mapping(cls, node, mapping):
"""Aggregates common logic for mapping retrieval methods
these methods are:
- 'get_network_role_mapping_to_ip'
- 'get_network_role_mapping_to_interfaces'.
"""
roles = dict()
for role in Cluster.get_network_roles(node.cluster):
default_mapping = mapping.get(role["default_mapping"])
if default_mapping:
roles[role["id"]] = default_mapping
return roles
示例3: get_vips_by_cluster_id
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import get_network_roles [as 别名]
def get_vips_by_cluster_id(cls, cluster_id,
network_id=None, network_role=None):
"""Get VIP filtered by cluster ID.
VIP is determined by not NULL vip_name field of IPAddr model.
:param cluster_id: cluster identifier or None to get all records
:type cluster_id: int|None
:param network_id: network identifier
:type network_id: int
:param network_role: network role
:type network_role: str
:return: vips query
:rtype: SQLAlchemy Query
"""
query = cls.get_by_cluster_id(cluster_id)\
.filter(models.IPAddr.vip_name.isnot(None))
if network_id:
query = query.filter(models.IPAddr.network == network_id)
if network_role:
# Get all network_roles for cluster and gain vip names from it,
# then bound query to this names.
# See network_roles.yaml in plugin examples for the details of
# input structure.
cluster_obj = Cluster.get_by_uid(cluster_id)
vips = []
for cluster_network_role in Cluster.get_network_roles(cluster_obj):
if cluster_network_role.get('id') == network_role:
vips.extend(
cluster_network_role
.get('properties', {})
.get('vip', [])
)
vip_names = (vip['name'] for vip in vips)
unique_vip_names = list(set(vip_names))
query = query.filter(models.IPAddr.vip_name.in_(unique_vip_names))
return query