from neutron.agent.linux import ip_lib
from neutron.agent.linux import keepalived
from neutron.agent.metadata import driver as metadata_driver
+from neutron.common import constants as n_consts
from neutron.common import utils as common_utils
from neutron.openstack.common import log as logging
instance = self._get_keepalived_instance()
# Filter out all of the old routes while keeping only the default route
- default_gw = ('::/0', '0.0.0.0/0')
+ default_gw = (n_consts.IPv6_ANY, n_consts.IPv4_ANY)
instance.virtual_routes = [route for route in instance.virtual_routes
if route.destination in default_gw]
for route in new_routes:
gw_ip = ex_gw_port['subnet']['gateway_ip']
if gw_ip:
# TODO(Carl) This is repeated everywhere. A method would be nice.
- default_gw = ('0.0.0.0/0' if netaddr.IPAddress(gw_ip).version == 4
- else '::/0')
+ default_gw = (n_consts.IPv4_ANY if
+ netaddr.IPAddress(gw_ip).version == 4 else
+ n_consts.IPv6_ANY)
instance = self._get_keepalived_instance()
instance.virtual_routes = (
[route for route in instance.virtual_routes
gateway = subnet.gateway_ip
host_routes = []
for hr in subnet.host_routes:
- if hr.destination == "0.0.0.0/0":
+ if hr.destination == constants.IPv4_ANY:
if not gateway:
gateway = hr.nexthop
else:
if host_routes:
if gateway:
- host_routes.append("%s,%s" % ("0.0.0.0/0", gateway))
+ host_routes.append("%s,%s" % (constants.IPv4_ANY,
+ gateway))
options.append(
self._format_option(subnet.ip_version, i,
'classless-static-route',
IPv4_BITS = 32
IPv6_BITS = 128
+IPv4_ANY = '0.0.0.0/0'
+IPv6_ANY = '::/0'
+
DHCP_RESPONSE_PORT = 68
MIN_VLAN_TAG = 1
from oslo_utils import excutils
import six
+from neutron.common import constants
from neutron.common import log as call_log
from neutron.common import utils
from neutron.i18n import _LE, _LW
def _process_gw_port(self, gw_info, routes):
if gw_info and gw_info['gateway_ip']:
- routes.append({'destination': '0.0.0.0/0',
+ routes.append({'destination': constants.IPv4_ANY,
'nexthop': gw_info['gateway_ip']})
@call_log.log
import testtools
from neutron.agent.linux import keepalived
+from neutron.common import constants as n_consts
from neutron.tests import base
# Keepalived user guide:
instance1.vips.append(vip_address3)
instance1.vips.append(vip_address_ex)
- virtual_route = keepalived.KeepalivedVirtualRoute("0.0.0.0/0",
+ virtual_route = keepalived.KeepalivedVirtualRoute(n_consts.IPv4_ANY,
"192.168.1.1",
"eth1")
instance1.virtual_routes.append(virtual_route)
class KeepalivedVirtualRouteTestCase(base.BaseTestCase):
def test_virtual_route_with_dev(self):
- route = keepalived.KeepalivedVirtualRoute('0.0.0.0/0', '1.2.3.4',
+ route = keepalived.KeepalivedVirtualRoute(n_consts.IPv4_ANY, '1.2.3.4',
'eth0')
self.assertEqual('0.0.0.0/0 via 1.2.3.4 dev eth0',
route.build_config())
from neutron.api import extensions
from neutron.common import config
+from neutron.common import constants as n_consts
from neutron import context
import neutron.extensions
from neutron.extensions import metering
excluded),
self.metering_label_rule(metering_label_id,
direction,
- '0.0.0.0/0',
+ n_consts.IPv4_ANY,
False)) as metering_label_rule:
self._test_list_resources('metering-label-rule',
def test_create_subnet_bad_V4_cidr_prefix_len(self):
with self.network() as network:
data = {'subnet': {'network_id': network['network']['id'],
- 'cidr': '0.0.0.0/0',
+ 'cidr': constants.IPv4_ANY,
'ip_version': '4',
'tenant_id': network['network']['tenant_id'],
'gateway_ip': '0.0.0.1'}}
class FakeV4HostRouteGateway(object):
- destination = '0.0.0.0/0'
+ destination = constants.IPv4_ANY
nexthop = '10.0.0.1'