当前位置: 首页>>代码示例>>Python>>正文


Python NetworkManager.get_node_interface_by_netname方法代码示例

本文整理汇总了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'
                ]
            })
#.........这里部分代码省略.........
开发者ID:andrey-borisov,项目名称:fuel-web,代码行数:103,代码来源:deployment_serializers.py


注:本文中的nailgun.network.manager.NetworkManager.get_node_interface_by_netname方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。