本文整理汇总了Python中nailgun.network.manager.NetworkManager.get_free_ips方法的典型用法代码示例。如果您正苦于以下问题:Python NetworkManager.get_free_ips方法的具体用法?Python NetworkManager.get_free_ips怎么用?Python NetworkManager.get_free_ips使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nailgun.network.manager.NetworkManager
的用法示例。
在下文中一共展示了NetworkManager.get_free_ips方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from nailgun.network.manager import NetworkManager [as 别名]
# 或者: from nailgun.network.manager.NetworkManager import get_free_ips [as 别名]
def setUp(self):
super(TestRepoAvailability, self).setUp()
self.env.create(
cluster_kwargs={
'net_provider': 'neutron',
'net_segment_type': 'gre'
},
nodes_kwargs=[{'roles': ['controller']},
{'roles': ['controller']},
{'roles': ['compute']},
{'roles': ['compute'], 'online': False}])
self.cluster = self.env.clusters[0]
self.public_ng = next(ng for ng in self.cluster.network_groups
if ng.name == 'public')
self.free_ips = NetworkManager.get_free_ips(self.public_ng, 2)
self.repo_urls = objects.Cluster.get_repo_urls(self.cluster)
self.controllers = [n for n in self.cluster.nodes
if 'controller' in n.all_roles]
self.online_uids = [n.uid for n in self.cluster.nodes if n.online]
示例2: get_config
# 需要导入模块: from nailgun.network.manager import NetworkManager [as 别名]
# 或者: from nailgun.network.manager.NetworkManager import get_free_ips [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