• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python ip_lib.get_ipv6_lladdr函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中neutron.agent.linux.ip_lib.get_ipv6_lladdr函数的典型用法代码示例。如果您正苦于以下问题:Python get_ipv6_lladdr函数的具体用法?Python get_ipv6_lladdr怎么用?Python get_ipv6_lladdr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_ipv6_lladdr函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_expected_keepalive_configuration

    def get_expected_keepalive_configuration(self, router):
        router_id = router.router_id
        ha_device_name = router.get_ha_device_name()
        ha_device_cidr = self._port_first_ip_cidr(router.ha_port)
        external_port = router.get_ex_gw_port()
        ex_port_ipv6 = ip_lib.get_ipv6_lladdr(external_port['mac_address'])
        external_device_name = router.get_external_device_name(
            external_port['id'])
        external_device_cidr = self._port_first_ip_cidr(external_port)
        internal_port = router.router[l3_constants.INTERFACE_KEY][0]
        int_port_ipv6 = ip_lib.get_ipv6_lladdr(internal_port['mac_address'])
        internal_device_name = router.get_internal_device_name(
            internal_port['id'])
        internal_device_cidr = self._port_first_ip_cidr(internal_port)
        floating_ip_cidr = common_utils.ip_to_cidr(
            router.get_floating_ips()[0]['floating_ip_address'])
        default_gateway_ip = external_port['subnets'][0].get('gateway_ip')

        return """vrrp_instance VR_1 {
    state BACKUP
    interface %(ha_device_name)s
    virtual_router_id 1
    priority 50
    nopreempt
    advert_int 2
    track_interface {
        %(ha_device_name)s
    }
    virtual_ipaddress {
        169.254.0.1/24 dev %(ha_device_name)s
    }
    virtual_ipaddress_excluded {
        %(floating_ip_cidr)s dev %(external_device_name)s
        %(external_device_cidr)s dev %(external_device_name)s
        %(internal_device_cidr)s dev %(internal_device_name)s
        %(ex_port_ipv6)s dev %(external_device_name)s scope link
        %(int_port_ipv6)s dev %(internal_device_name)s scope link
    }
    virtual_routes {
        0.0.0.0/0 via %(default_gateway_ip)s dev %(external_device_name)s
        8.8.8.0/24 via 19.4.4.4
    }
}""" % {
            'router_id': router_id,
            'ha_device_name': ha_device_name,
            'ha_device_cidr': ha_device_cidr,
            'external_device_name': external_device_name,
            'external_device_cidr': external_device_cidr,
            'internal_device_name': internal_device_name,
            'internal_device_cidr': internal_device_cidr,
            'floating_ip_cidr': floating_ip_cidr,
            'default_gateway_ip': default_gateway_ip,
            'int_port_ipv6': int_port_ipv6,
            'ex_port_ipv6': ex_port_ipv6
        }
开发者ID:Akanksha08,项目名称:neutron,代码行数:55,代码来源:test_l3_agent.py


示例2: init_l3

    def init_l3(self, device_name, ip_cidrs, namespace=None,
                preserve_ips=None, clean_connections=False):
        """Set the L3 settings for the interface using data from the port.

        ip_cidrs: list of 'X.X.X.X/YY' strings
        preserve_ips: list of ip cidrs that should not be removed from device
        clean_connections: Boolean to indicate if we should cleanup connections
          associated to removed ips
        """
        preserve_ips = preserve_ips or []
        device = ip_lib.IPDevice(device_name, namespace=namespace)

        # The LLA generated by the operating system is not known to
        # Neutron, so it would be deleted if we added it to the 'previous'
        # list here
        default_ipv6_lla = ip_lib.get_ipv6_lladdr(device.link.address)

        cidrs = set()
        remove_ips = set()

        # normalize all the IP addresses first
        for ip_cidr in ip_cidrs:
            net = netaddr.IPNetwork(ip_cidr)
            # Convert to compact IPv6 address because the return values of
            # "ip addr list" are compact.
            if net.version == 6:
                ip_cidr = str(net)
            cidrs.add(ip_cidr)

        # Determine the addresses that must be added and removed
        for address in device.addr.list():
            cidr = address['cidr']
            dynamic = address['dynamic']

            # skip the IPv6 link-local
            if cidr == default_ipv6_lla:
                continue

            if cidr in preserve_ips:
                continue

            # Statically created addresses are OK, dynamically created
            # addresses must be removed and replaced
            if cidr in cidrs and not dynamic:
                cidrs.remove(cidr)
                continue

            remove_ips.add(cidr)

        # Clean up any old addresses.  This must be done first since there
        # could be a dynamic address being replaced with a static one.
        for ip_cidr in remove_ips:
            if clean_connections:
                device.delete_addr_and_conntrack_state(ip_cidr)
            else:
                device.addr.delete(ip_cidr)

        # add any new addresses
        for ip_cidr in cidrs:
            device.addr.add(ip_cidr)
开发者ID:2020human,项目名称:neutron,代码行数:60,代码来源:interface.py


示例3: _check_lla_status

 def _check_lla_status(router, expected):
     internal_devices = router.router[l3_constants.INTERFACE_KEY]
     for device in internal_devices:
         lladdr = ip_lib.get_ipv6_lladdr(device['mac_address'])
         exists = ip_lib.device_exists_with_ips_and_mac(
             router.get_internal_device_name(device['id']), [lladdr],
             device['mac_address'], router.ns_name)
         self.assertEqual(expected, exists)
开发者ID:Blahhhhh,项目名称:neutron,代码行数:8,代码来源:test_ha_router.py


示例4: init_l3

    def init_l3(self, device_name, ip_cidrs, namespace=None,
                preserve_ips=[], gateway_ips=None, extra_subnets=[],
                enable_ra_on_gw=False, clean_connections=False):
        """Set the L3 settings for the interface using data from the port.

        ip_cidrs: list of 'X.X.X.X/YY' strings
        preserve_ips: list of ip cidrs that should not be removed from device
        gateway_ips: For gateway ports, list of external gateway ip addresses
        enable_ra_on_gw: Boolean to indicate configuring acceptance of IPv6 RA
        clean_connections: Boolean to indicate if we should cleanup connections
          associated to removed ips
        """
        device = ip_lib.IPDevice(device_name, namespace=namespace)

        # The LLA generated by the operating system is not known to
        # Neutron, so it would be deleted if we added it to the 'previous'
        # list here
        default_ipv6_lla = ip_lib.get_ipv6_lladdr(device.link.address)
        previous = {addr['cidr'] for addr in device.addr.list(
            filters=['permanent'])} - {default_ipv6_lla}

        # add new addresses
        for ip_cidr in ip_cidrs:

            net = netaddr.IPNetwork(ip_cidr)
            # Convert to compact IPv6 address because the return values of
            # "ip addr list" are compact.
            if net.version == 6:
                ip_cidr = str(net)
            if ip_cidr in previous:
                previous.remove(ip_cidr)
                continue

            device.addr.add(ip_cidr)

        # clean up any old addresses
        for ip_cidr in previous:
            if ip_cidr not in preserve_ips:
                if clean_connections:
                    device.delete_addr_and_conntrack_state(ip_cidr)
                else:
                    device.addr.delete(ip_cidr)

        for gateway_ip in gateway_ips or []:
            device.route.add_gateway(gateway_ip)

        if enable_ra_on_gw:
            self.configure_ipv6_ra(namespace, device_name)

        new_onlink_routes = set(s['cidr'] for s in extra_subnets)
        existing_onlink_routes = set(
            device.route.list_onlink_routes(n_const.IP_VERSION_4) +
            device.route.list_onlink_routes(n_const.IP_VERSION_6))
        for route in new_onlink_routes - existing_onlink_routes:
            device.route.add_onlink_route(route)
        for route in existing_onlink_routes - new_onlink_routes:
            device.route.delete_onlink_route(route)
开发者ID:bgxavier,项目名称:neutron,代码行数:57,代码来源:interface.py


示例5: _disable_ipv6_addressing_on_interface

    def _disable_ipv6_addressing_on_interface(self, interface_name):
        """Disable IPv6 link local addressing on the device and add it as
        a VIP to keepalived. This means that the IPv6 link local address
        will only be present on the master.
        """
        device = ip_lib.IPDevice(interface_name, namespace=self.ns_name)
        ipv6_lladdr = ip_lib.get_ipv6_lladdr(device.link.address)

        if self._should_delete_ipv6_lladdr(ipv6_lladdr):
            device.addr.flush(n_consts.IP_VERSION_6)

        self._remove_vip(ipv6_lladdr)
        self._add_vip(ipv6_lladdr, interface_name, scope='link')
开发者ID:Akanksha08,项目名称:neutron,代码行数:13,代码来源:ha_router.py


示例6: _disable_ipv6_addressing_on_interface

    def _disable_ipv6_addressing_on_interface(self, interface_name):
        """Disable IPv6 link local addressing on the device and add it as
        a VIP to keepalived. This means that the IPv6 link local address
        will only be present on the master.
        """
        device = ip_lib.IPDevice(interface_name, namespace=self.ha_namespace)
        ipv6_lladdr = ip_lib.get_ipv6_lladdr(device.link.address)

        if self._should_delete_ipv6_lladdr(ipv6_lladdr):
            self.driver.configure_ipv6_ra(self.ha_namespace, interface_name,
                                          const.ACCEPT_RA_DISABLED)
            device.addr.flush(n_consts.IP_VERSION_6)
        else:
            self.driver.configure_ipv6_ra(self.ha_namespace, interface_name,
                                          const.ACCEPT_RA_WITHOUT_FORWARDING)

        self._remove_vip(ipv6_lladdr)
        self._add_vip(ipv6_lladdr, interface_name, scope='link')
开发者ID:igordcard,项目名称:neutron,代码行数:18,代码来源:ha_router.py


示例7: init_l3

    def init_l3(
        self, device_name, ip_cidrs, namespace=None, preserve_ips=[], gateway_ips=None, clean_connections=False
    ):
        """Set the L3 settings for the interface using data from the port.

        ip_cidrs: list of 'X.X.X.X/YY' strings
        preserve_ips: list of ip cidrs that should not be removed from device
        gateway_ips: For gateway ports, list of external gateway ip addresses
        clean_connections: Boolean to indicate if we should cleanup connections
          associated to removed ips
        """
        device = ip_lib.IPDevice(device_name, namespace=namespace)

        # The LLA generated by the operating system is not known to
        # Neutron, so it would be deleted if we added it to the 'previous'
        # list here
        default_ipv6_lla = ip_lib.get_ipv6_lladdr(device.link.address)
        previous = {addr["cidr"] for addr in device.addr.list(filters=["permanent"])} - {default_ipv6_lla}

        # add new addresses
        for ip_cidr in ip_cidrs:

            net = netaddr.IPNetwork(ip_cidr)
            # Convert to compact IPv6 address because the return values of
            # "ip addr list" are compact.
            if net.version == 6:
                ip_cidr = str(net)
            if ip_cidr in previous:
                previous.remove(ip_cidr)
                continue

            device.addr.add(ip_cidr)

        # clean up any old addresses
        for ip_cidr in previous:
            if ip_cidr not in preserve_ips:
                if clean_connections:
                    device.delete_addr_and_conntrack_state(ip_cidr)
                else:
                    device.addr.delete(ip_cidr)

        for gateway_ip in gateway_ips or []:
            device.route.add_gateway(gateway_ip)
开发者ID:zhukejian111,项目名称:neutron,代码行数:43,代码来源:interface.py


示例8: get_expected_keepalive_configuration

 def get_expected_keepalive_configuration(self, router):
     ha_device_name = router.get_ha_device_name()
     external_port = router.get_ex_gw_port()
     ex_port_ipv6 = ip_lib.get_ipv6_lladdr(external_port['mac_address'])
     ex_device_name = router.get_external_device_name(
         external_port['id'])
     external_device_cidr = self._port_first_ip_cidr(external_port)
     internal_port = router.router[constants.INTERFACE_KEY][0]
     int_port_ipv6 = ip_lib.get_ipv6_lladdr(internal_port['mac_address'])
     internal_device_name = router.get_internal_device_name(
         internal_port['id'])
     internal_device_cidr = self._port_first_ip_cidr(internal_port)
     floating_ip_cidr = common_utils.ip_to_cidr(
         router.get_floating_ips()[0]['floating_ip_address'])
     default_gateway_ip = external_port['subnets'][0].get('gateway_ip')
     extra_subnet_cidr = external_port['extra_subnets'][0].get('cidr')
     return textwrap.dedent("""\
         global_defs {
             notification_email_from %(email_from)s
             router_id %(router_id)s
         }
         vrrp_instance VR_1 {
             state BACKUP
             interface %(ha_device_name)s
             virtual_router_id 1
             priority 50
             garp_master_delay 60
             nopreempt
             advert_int 2
             track_interface {
                 %(ha_device_name)s
             }
             virtual_ipaddress {
                 169.254.0.1/24 dev %(ha_device_name)s
             }
             virtual_ipaddress_excluded {
                 %(floating_ip_cidr)s dev %(ex_device_name)s
                 %(external_device_cidr)s dev %(ex_device_name)s
                 %(internal_device_cidr)s dev %(internal_device_name)s
                 %(ex_port_ipv6)s dev %(ex_device_name)s scope link
                 %(int_port_ipv6)s dev %(internal_device_name)s scope link
             }
             virtual_routes {
                 0.0.0.0/0 via %(default_gateway_ip)s dev %(ex_device_name)s
                 8.8.8.0/24 via 19.4.4.4
                 %(extra_subnet_cidr)s dev %(ex_device_name)s scope link
             }
         }""") % {
         'email_from': keepalived.KEEPALIVED_EMAIL_FROM,
         'router_id': keepalived.KEEPALIVED_ROUTER_ID,
         'ha_device_name': ha_device_name,
         'ex_device_name': ex_device_name,
         'external_device_cidr': external_device_cidr,
         'internal_device_name': internal_device_name,
         'internal_device_cidr': internal_device_cidr,
         'floating_ip_cidr': floating_ip_cidr,
         'default_gateway_ip': default_gateway_ip,
         'int_port_ipv6': int_port_ipv6,
         'ex_port_ipv6': ex_port_ipv6,
         'extra_subnet_cidr': extra_subnet_cidr,
     }
开发者ID:openstack,项目名称:neutron,代码行数:61,代码来源:framework.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ip_lib.get_routing_table函数代码示例发布时间:2022-05-27
下一篇:
Python ip_lib.ensure_device_is_ready函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap