本文整理汇总了Python中nailgun.network.manager.NetworkManager.get_node_interface_by_netname方法的典型用法代码示例。如果您正苦于以下问题:Python NetworkManager.get_node_interface_by_netname方法的具体用法?Python NetworkManager.get_node_interface_by_netname怎么用?Python NetworkManager.get_node_interface_by_netname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nailgun.network.manager.NetworkManager
的用法示例。
在下文中一共展示了NetworkManager.get_node_interface_by_netname方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_network_scheme
# 需要导入模块: from nailgun.network.manager import NetworkManager [as 别名]
# 或者: from nailgun.network.manager.NetworkManager import get_node_interface_by_netname [as 别名]
def generate_network_scheme(cls, node):
# Create a data structure and fill it with static values.
attrs = {
'version': '1.0',
'provider': 'ovs',
'interfaces': {}, # It's a list of physical interfaces.
'endpoints': {
'br-storage': {},
'br-ex': {},
'br-mgmt': {},
# There should be an endpoint for a fw-admin network.
},
'roles': {
'ex': 'br-ex',
'management': 'br-mgmt',
'storage': 'br-storage',
'fw-admin': ''
},
'transformations': []
}
# Add bridges for networks.
for brname in ('br-ex', 'br-mgmt', 'br-storage', 'br-prv'):
attrs['transformations'].append({
'action': 'add-br',
'name': brname
})
# Add a dynamic data to a structure.
# Fill up interfaces and add bridges for them.
for iface in node.interfaces:
attrs['interfaces'][iface.name] = {}
if iface.name == node.admin_interface.name:
# A physical interface for the FuelWeb admin network should
# not be used through bridge. Directly only.
continue
attrs['transformations'].append({
'action': 'add-br',
'name': 'br-%s' % iface.name
})
attrs['transformations'].append({
'action': 'add-port',
'bridge': 'br-%s' % iface.name,
'name': iface.name
})
nm = NetworkManager()
# Populate IP address information to endpoints.
netgroup_mapping = [
('storage', 'br-storage'),
('public', 'br-ex'),
('management', 'br-mgmt')
]
netgroups = {}
for ngname, brname in netgroup_mapping:
# Here we get a dict with network description for this particular
# node with its assigned IPs and device names for each network.
netgroup = nm.get_node_network_by_netname(node.id, ngname)
attrs['endpoints'][brname]['IP'] = [netgroup['ip']]
netgroups[ngname] = netgroup
attrs['endpoints']['br-ex']['gateway'] = netgroups['public']['gateway']
# Connect interface bridges to network bridges.
for ngname, brname in netgroup_mapping:
netgroup = nm.get_node_network_by_netname(node.id, ngname)
if not netgroup['vlan']:
# Untagged network.
attrs['transformations'].append({
'action': 'add-patch',
'bridges': ['br-%s' % netgroup['dev'], brname],
'trunks': [0]
})
elif netgroup['vlan'] > 1:
# Tagged network.
attrs['transformations'].append({
'action': 'add-patch',
'bridges': ['br-%s' % netgroup['dev'], brname],
'tags': [netgroup['vlan'], 0]
})
else:
# FIXME! Should raise some exception I think.
logger.error('Invalid vlan for network: %s' % str(netgroup))
# Dance around Neutron segmentation type.
if node.cluster.net_segment_type == 'vlan':
attrs['endpoints']['br-prv'] = {'IP': 'none'}
attrs['roles']['private'] = 'br-prv'
attrs['transformations'].append({
'action': 'add-patch',
'bridges': [
'br-%s' % nm.get_node_interface_by_netname(
node.id,
'private'
).name,
'br-prv'
]
})
#.........这里部分代码省略.........