本文整理汇总了Python中nailgun.network.manager.NetworkManager.find_nic_assoc_with_ng方法的典型用法代码示例。如果您正苦于以下问题:Python NetworkManager.find_nic_assoc_with_ng方法的具体用法?Python NetworkManager.find_nic_assoc_with_ng怎么用?Python NetworkManager.find_nic_assoc_with_ng使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nailgun.network.manager.NetworkManager
的用法示例。
在下文中一共展示了NetworkManager.find_nic_assoc_with_ng方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_config
# 需要导入模块: from nailgun.network.manager import NetworkManager [as 别名]
# 或者: from nailgun.network.manager.NetworkManager import find_nic_assoc_with_ng [as 别名]
def get_config(cls, cluster):
urls = objects.Cluster.get_repo_urls(cluster)
nodes = []
errors = []
# if there is nothing to verify - just skip this task
if not urls:
return
all_public = \
objects.Cluster.should_assign_public_to_all_nodes(cluster)
public_networks = filter(
lambda ng: ng.name == 'public', cluster.network_groups)
for public in public_networks:
# we are not running this verification for nodes not in discover
# state
nodes_with_public_ip = []
required_ips = 0
group_nodes = objects.NodeCollection.filter_by(
None, group_id=public.group_id,
status=consts.NODE_STATUSES.discover).all()
for node in group_nodes:
if not (all_public or
objects.Node.should_have_public_with_ip(node)):
continue
ip = NetworkManager.get_ip_by_network_name(node, public.name)
nodes_with_public_ip.append((node, ip))
if ip is None:
required_ips += 1
if not nodes_with_public_ip:
continue
# we are not doing any allocations during verification
# just ask for free ips and use them
free_ips = iter(NetworkManager.get_free_ips(public, required_ips))
mask = public.cidr.split('/')[1]
lacp_modes = (
consts.BOND_MODES.lacp_balance_tcp,
consts.BOND_MODES.l_802_3ad)
for node, ip in nodes_with_public_ip:
if not node.online:
continue
iface = NetworkManager.find_nic_assoc_with_ng(
node, public)
if iface.bond and iface.bond.mode in lacp_modes:
errors.append(
'Iface {0} on node {1} configured to use '
'lacp-balance-tcp mode as part of {2}. Repo '
'availability verification for this node '
'will be skipped.'.format(
iface.name, node.name, iface.bond.name))
continue
ip = ip or next(free_ips)
node_config = {
'addr': '{0}/{1}'.format(ip, mask),
'gateway': public.gateway,
'vlan': public.vlan_start or 0,
'iface': iface.name,
'urls': urls,
'uid': node.uid}
nodes.append(node_config)
# if no nodes will be present - we will skip this task
return nodes, errors