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

Python utils.ip_to_cidr函数代码示例

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

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



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

示例1: test_north_south_traffic

    def test_north_south_traffic(self):
        # This function creates an external network which is connected to
        # central_external_bridge and spawns an external_vm on it.
        # The external_vm is configured with the gateway_ip (both v4 & v6
        # addresses) of external subnet. Later, it creates a tenant router,
        # a tenant network and two tenant subnets (v4 and v6). The tenant
        # router is associated with tenant network and external network to
        # provide north-south connectivity to the VMs.
        # We validate the following in this testcase.
        # 1. SNAT support: using ping from tenant VM to external_vm
        # 2. Floating IP support: using ping from external_vm to VM floating ip
        # 3. IPv6 ext connectivity: using ping6 from tenant vm to external_vm.
        tenant_id = uuidutils.generate_uuid()
        ext_net, ext_sub = self._create_external_network_and_subnet(tenant_id)
        external_vm = self.useFixture(
            machine_fixtures.FakeMachine(
                self.environment.central_external_bridge,
                common_utils.ip_to_cidr(ext_sub['gateway_ip'], 24)))
        # Create an IPv6 subnet in the external network
        v6network = self.useFixture(
            ip_network.ExclusiveIPNetwork(
                "2001:db8:1234::1", "2001:db8:1234::10", "64")).network
        ext_v6sub = self.safe_client.create_subnet(
            tenant_id, ext_net['id'], v6network)

        router = self.safe_client.create_router(tenant_id,
                                                external_network=ext_net['id'])

        # Configure the gateway_ip of external v6subnet on the external_vm.
        external_vm.ipv6_cidr = common_utils.ip_to_cidr(
            ext_v6sub['gateway_ip'], 64)

        # Configure an IPv6 downstream route to the v6Address of router gw port
        for fixed_ip in router['external_gateway_info']['external_fixed_ips']:
            if netaddr.IPNetwork(fixed_ip['ip_address']).version == 6:
                external_vm.set_default_gateway(fixed_ip['ip_address'])

        vm = self._create_net_subnet_and_vm(
            tenant_id, ['20.0.0.0/24', '2001:db8:aaaa::/64'],
            self.environment.hosts[1], router)

        # ping external vm to test snat
        vm.block_until_ping(external_vm.ip)

        fip = self.safe_client.create_floatingip(
            tenant_id, ext_net['id'], vm.ip, vm.neutron_port['id'])

        # ping floating ip from external vm
        external_vm.block_until_ping(fip['floating_ip_address'])

        # Verify VM is able to reach the router interface.
        vm.block_until_ping(vm.gateway_ipv6)
        # Verify north-south connectivity using ping6 to external_vm.
        vm.block_until_ping(external_vm.ipv6)
开发者ID:AradhanaSingh,项目名称:neutron,代码行数:54,代码来源:test_l3_agent.py


示例2: test_snat_and_floatingip

    def test_snat_and_floatingip(self):
        # This function creates external network and boots an extrenal vm
        # on it with gateway ip and connected to central_external_bridge.
        # Later it creates a tenant vm on tenant network, with tenant router
        # connected to tenant network and external network.
        # To test snat and floatingip, try ping between tenant and external vms
        tenant_id = uuidutils.generate_uuid()
        ext_net, ext_sub = self._create_external_network_and_subnet(tenant_id)
        external_vm = self.useFixture(
            machine_fixtures.FakeMachine(
                self.environment.central_external_bridge,
                common_utils.ip_to_cidr(ext_sub['gateway_ip'], 24)))

        router = self.safe_client.create_router(tenant_id,
                                                external_network=ext_net['id'])
        vm = self._create_net_subnet_and_vm(
            tenant_id, '20.0.0.0/24',
            self.environment.hosts[1], router)

        # ping external vm to test snat
        vm.block_until_ping(external_vm.ip)

        fip = self.safe_client.create_floatingip(
            tenant_id, ext_net['id'], vm.ip, vm.neutron_port['id'])

        # ping floating ip from external vm
        external_vm.block_until_ping(fip['floating_ip_address'])
开发者ID:Jackwwg,项目名称:neutron,代码行数:27,代码来源:test_l3_agent.py


示例3: _snat_redirect_modify

 def _snat_redirect_modify(self, gateway, sn_port, sn_int, is_add):
     """Adds or removes rules and routes for SNAT redirection."""
     try:
         ns_ipr = ip_lib.IPRule(namespace=self.ns_name)
         ns_ipd = ip_lib.IPDevice(sn_int, namespace=self.ns_name)
         if is_add:
             ns_ipwrapr = ip_lib.IPWrapper(namespace=self.ns_name)
         for port_fixed_ip in sn_port["fixed_ips"]:
             # Find the first gateway IP address matching this IP version
             port_ip_addr = port_fixed_ip["ip_address"]
             port_ip_vers = netaddr.IPAddress(port_ip_addr).version
             for gw_fixed_ip in gateway["fixed_ips"]:
                 gw_ip_addr = gw_fixed_ip["ip_address"]
                 if netaddr.IPAddress(gw_ip_addr).version == port_ip_vers:
                     sn_port_cidr = common_utils.ip_to_cidr(port_ip_addr, port_fixed_ip["prefixlen"])
                     snat_idx = self._get_snat_idx(sn_port_cidr)
                     if is_add:
                         ns_ipd.route.add_gateway(gw_ip_addr, table=snat_idx)
                         ns_ipr.rule.add(sn_port_cidr, snat_idx, snat_idx)
                         ns_ipwrapr.netns.execute(["sysctl", "-w", "net.ipv4.conf.%s.send_redirects=0" % sn_int])
                     else:
                         self._snat_delete_device_gateway(ns_ipd, gw_ip_addr, snat_idx)
                         ns_ipr.rule.delete(sn_port_cidr, snat_idx, snat_idx)
                     break
     except Exception:
         if is_add:
             exc = _LE("DVR: error adding redirection logic")
         else:
             exc = _LE("DVR: removed snat failed")
         LOG.exception(exc)
开发者ID:kirajun,项目名称:neutron,代码行数:30,代码来源:dvr_router.py


示例4: add

 def add(self, device, cidr):
     table = device.route.table(self.name)
     cidr = netaddr.IPNetwork(cidr)
     # Get the network cidr (e.g. 192.168.5.135/23 -> 192.168.4.0/23)
     net = utils.ip_to_cidr(cidr.network, cidr.prefixlen)
     self._keep.add((net, device.name))
     table.add_onlink_route(net)
开发者ID:TonyChengTW,项目名称:OpenStack_Liberty_Control,代码行数:7,代码来源:rt_tables.py


示例5: test_floating_ip_added_dist

    def test_floating_ip_added_dist(self, mIPRule, mIPDevice, mock_adv_notif):
        router = mock.MagicMock()
        ri = self._create_router(router)
        ext_net_id = _uuid()
        subnet_id = _uuid()
        agent_gw_port = {'fixed_ips': [{'ip_address': '20.0.0.30',
                                        'prefixlen': 24,
                                        'subnet_id': subnet_id}],
                         'subnets': [{'id': subnet_id,
                                      'cidr': '20.0.0.0/24',
                                      'gateway_ip': '20.0.0.1'}],
                         'id': _uuid(),
                         'network_id': ext_net_id,
                         'mac_address': 'ca:fe:de:ad:be:ef'}

        fip = {'id': _uuid(),
               'host': HOSTNAME,
               'floating_ip_address': '15.1.2.3',
               'fixed_ip_address': '192.168.0.1',
               'floating_network_id': ext_net_id,
               'port_id': _uuid()}
        ri.fip_ns = mock.Mock()
        ri.fip_ns.agent_gateway_port = agent_gw_port
        ri.fip_ns.allocate_rule_priority.return_value = FIP_PRI
        ri.rtr_fip_subnet = lla.LinkLocalAddressPair('169.254.30.42/31')
        ri.dist_fip_count = 0
        ip_cidr = common_utils.ip_to_cidr(fip['floating_ip_address'])
        ri.floating_ip_added_dist(fip, ip_cidr)
        mIPRule().rule.add.assert_called_with('192.168.0.1', 16, FIP_PRI)
        self.assertEqual(1, ri.dist_fip_count)
开发者ID:bgxavier,项目名称:neutron,代码行数:30,代码来源:test_dvr_router.py


示例6: _list_floating_ip_cidrs

 def _list_floating_ip_cidrs(self):
     # Compute a list of addresses this router is supposed to have.
     # This avoids unnecessarily removing those addresses and
     # causing a momentarily network outage.
     floating_ips = self.get_floating_ips()
     return [common_utils.ip_to_cidr(ip['floating_ip_address'])
             for ip in floating_ips]
开发者ID:MODITDC,项目名称:neutron,代码行数:7,代码来源:router_info.py


示例7: test_ha_router_restart_agents_no_packet_lost

    def test_ha_router_restart_agents_no_packet_lost(self):
        tenant_id = uuidutils.generate_uuid()
        ext_net, ext_sub = self._create_external_network_and_subnet(tenant_id)
        router = self.safe_client.create_router(tenant_id, ha=True,
                                                external_network=ext_net['id'])

        external_vm = self.useFixture(
            machine_fixtures.FakeMachine(
                self.environment.central_external_bridge,
                common_utils.ip_to_cidr(ext_sub['gateway_ip'], 24)))

        common_utils.wait_until_true(
            lambda:
            len(self.client.list_l3_agent_hosting_routers(
                router['id'])['agents']) == 2,
            timeout=90)

        common_utils.wait_until_true(
            functools.partial(
                self._is_ha_router_active_on_one_agent,
                router['id']),
            timeout=90)

        router_ip = router['external_gateway_info'][
            'external_fixed_ips'][0]['ip_address']
        l3_agents = [host.agents['l3'] for host in self.environment.hosts]

        self._assert_ping_during_agents_restart(
            l3_agents, external_vm.namespace, [router_ip], count=60)
开发者ID:mmalchuk,项目名称:openstack-neutron,代码行数:29,代码来源:test_l3_agent.py


示例8: test_get_ip_addresses

    def test_get_ip_addresses(self):
        namespace = 'ns_test-' + uuidutils.generate_uuid()
        priv_ip_lib.create_netns(namespace)
        self.addCleanup(self._remove_ns, namespace)
        interfaces = {
            '20': {'cidr': '192.168.10.20/24', 'scope': 'link',
                   'add_broadcast': True},
            '30': {'cidr': '2001::1/64', 'scope': 'global',
                   'add_broadcast': False}}

        for int_name, int_parameters in interfaces.items():
            priv_ip_lib.create_interface(int_name, namespace, 'dummy',
                                         index=int(int_name))
            ip_lib.add_ip_address(
                int_parameters['cidr'], int_name, namespace,
                int_parameters['scope'], int_parameters['add_broadcast'])

        ip_addresses = priv_ip_lib.get_ip_addresses(namespace)
        for ip_address in ip_addresses:
            int_name = str(ip_address['index'])
            ip = _get_attr(ip_address, 'IFA_ADDRESS')
            mask = ip_address['prefixlen']
            cidr = common_utils.ip_to_cidr(ip, mask)
            self.assertEqual(interfaces[int_name]['cidr'], cidr)
            self.assertEqual(interfaces[int_name]['scope'],
                             ip_lib.IP_ADDRESS_SCOPE[ip_address['scope']])
开发者ID:noironetworks,项目名称:neutron,代码行数:26,代码来源:test_ip_lib.py


示例9: _ip_prefix_arg

    def _ip_prefix_arg(self, direction, ip_prefix):

        if not(ip_prefix):
            return []

        args = ['-%s' % direction, '%s' % utils.ip_to_cidr(ip_prefix)]
        return args
开发者ID:openstack,项目名称:neutron-fwaas,代码行数:7,代码来源:iptables_fwaas_v2.py


示例10: _list_centralized_floating_ip_cidrs

 def _list_centralized_floating_ip_cidrs(self):
     # Compute a list of addresses this gw is supposed to have.
     # This avoids unnecessarily removing those addresses and
     # causing a momentarily network outage.
     floating_ips = self.get_floating_ips()
     return [common_utils.ip_to_cidr(ip['floating_ip_address'])
             for ip in floating_ips
             if ip.get(lib_constants.DVR_SNAT_BOUND)]
开发者ID:openstack,项目名称:neutron,代码行数:8,代码来源:dvr_edge_router.py


示例11: add_floating_ip

    def add_floating_ip(self, fip, interface_name, device):
        if not self._add_fip_addr_to_device(fip, device):
            return l3_constants.FLOATINGIP_STATUS_ERROR

        # Special Handling for DVR - update FIP namespace
        ip_cidr = common_utils.ip_to_cidr(fip['floating_ip_address'])
        self.floating_ip_added_dist(fip, ip_cidr)
        return l3_constants.FLOATINGIP_STATUS_ACTIVE
开发者ID:liushengsoftman,项目名称:neutron_cds,代码行数:8,代码来源:dvr_router.py


示例12: _configure_port_for_rabbitmq

    def _configure_port_for_rabbitmq(self):
        self.env_desc.network_range = self._get_network_range()
        if not self.env_desc.network_range:
            return "127.0.0.1"
        rabbitmq_ip = str(self.env_desc.network_range[1])
        rabbitmq_port = ip_lib.IPDevice(self.central_data_bridge.br_name)
        rabbitmq_port.addr.add(common_utils.ip_to_cidr(rabbitmq_ip, 24))
        rabbitmq_port.link.set_up()

        return rabbitmq_ip
开发者ID:coreycb,项目名称:neutron,代码行数:10,代码来源:environment.py


示例13: connect_to_internal_network_via_tunneling

    def connect_to_internal_network_via_tunneling(self):
        veth_1, veth_2 = self.useFixture(
            net_helpers.VethFixture()).ports

        # NOTE: This sets an IP address on the host's root namespace
        # which is cleaned up when the device is deleted.
        veth_1.addr.add(common_utils.ip_to_cidr(self.local_ip, 32))

        veth_1.link.set_up()
        veth_2.link.set_up()
开发者ID:coreycb,项目名称:neutron,代码行数:10,代码来源:environment.py


示例14: _get_gw_ips_cidr

 def _get_gw_ips_cidr(self):
     gw_cidrs = set()
     ex_gw_port = self.get_ex_gw_port()
     if ex_gw_port:
         for ip_addr in ex_gw_port['fixed_ips']:
             ex_gw_ip = ip_addr['ip_address']
             addr = netaddr.IPAddress(ex_gw_ip)
             if addr.version == lib_constants.IP_VERSION_4:
                 gw_cidrs.add(common_utils.ip_to_cidr(ex_gw_ip))
     return gw_cidrs
开发者ID:2020human,项目名称:neutron,代码行数:10,代码来源:router_info.py


示例15: 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


示例16: _create_external_vm

 def _create_external_vm(self, network, subnet):
     vm = self.useFixture(
         machine_fixtures.FakeMachine(
             self.environment.central_bridge,
             common_utils.ip_to_cidr(subnet['gateway_ip'], 24)))
     # NOTE(slaweq): as ext_net is 'vlan' network type external_vm needs to
     # send packets with proper vlan also
     vm.bridge.set_db_attribute(
         "Port", vm.port.name,
         "tag", network.get("provider:segmentation_id"))
     return vm
开发者ID:openstack,项目名称:neutron,代码行数:11,代码来源:base.py


示例17: _internal_network_updated

 def _internal_network_updated(self, port, subnet_id, prefix, old_prefix, updated_cidrs):
     interface_name = self.get_internal_device_name(port["id"])
     if prefix != l3_constants.PROVISIONAL_IPV6_PD_PREFIX:
         fixed_ips = port["fixed_ips"]
         for fixed_ip in fixed_ips:
             if fixed_ip["subnet_id"] == subnet_id:
                 v6addr = common_utils.ip_to_cidr(fixed_ip["ip_address"], fixed_ip.get("prefixlen"))
                 if v6addr not in updated_cidrs:
                     self.driver.add_ipv6_addr(interface_name, v6addr, self.ns_name)
     else:
         self.driver.delete_ipv6_addr_with_prefix(interface_name, old_prefix, self.ns_name)
开发者ID:takeshineshiro,项目名称:neutron,代码行数:11,代码来源:router_info.py


示例18: _add_fip_addr_to_device

 def _add_fip_addr_to_device(self, fip, device):
     """Configures the floating ip address on the device.
     """
     try:
         ip_cidr = common_utils.ip_to_cidr(fip["floating_ip_address"])
         device.addr.add(ip_cidr)
         return True
     except RuntimeError:
         # any exception occurred here should cause the floating IP
         # to be set in error state
         LOG.warn(_LW("Unable to configure IP address for " "floating IP: %s"), fip["id"])
开发者ID:takeshineshiro,项目名称:neutron,代码行数:11,代码来源:router_info.py


示例19: external_gateway_removed

 def external_gateway_removed(self, ex_gw_port, interface_name):
     LOG.debug("External gateway removed: port(%s), interface(%s)",
               ex_gw_port, interface_name)
     device = ip_lib.IPDevice(interface_name, namespace=self.ns_name)
     for ip_addr in ex_gw_port['fixed_ips']:
         self.remove_external_gateway_ip(device,
                                         common_utils.ip_to_cidr(
                                             ip_addr['ip_address'],
                                             ip_addr['prefixlen']))
     self.driver.unplug(interface_name,
                        bridge=self.agent_conf.external_network_bridge,
                        namespace=self.ns_name,
                        prefix=EXTERNAL_DEV_PREFIX)
开发者ID:MODITDC,项目名称:neutron,代码行数:13,代码来源:router_info.py


示例20: _ip_prefix_arg

 def _ip_prefix_arg(self, direction, ip_prefix):
     #NOTE (nati) : source_group_id is converted to list of source_
     # ip_prefix in server side
     if ip_prefix:
         if '/' not in ip_prefix:
             # we need to convert it into a prefix to match iptables
             ip_prefix = c_utils.ip_to_cidr(ip_prefix)
         elif ip_prefix.endswith('/0'):
             # an allow for every address is not a constraint so
             # iptables drops it
             return []
         return ['-%s' % direction, ip_prefix]
     return []
开发者ID:promptworks,项目名称:neutron,代码行数:13,代码来源:iptables_firewall.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python utils.ip_version_from_int函数代码示例发布时间:2022-05-27
下一篇:
Python utils.get_random_string函数代码示例发布时间: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