]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add IP_ANY dict to ease choosing between IPv4 and IPv6 "any" address
authorCarl Baldwin <carl.baldwin@hp.com>
Tue, 7 Jul 2015 16:41:03 +0000 (16:41 +0000)
committerCarl Baldwin <carl.baldwin@hp.com>
Tue, 7 Jul 2015 16:41:03 +0000 (16:41 +0000)
I'm working on a new patch that will add one more case where we need
to choose between 0.0.0.0/0 and ::/0 based on the ip version.  I
thought I'd add a new constant and simplify a couple of existing uses.

Change-Id: I376d60c7de4bafcaf2387685ddcc1d98978ce446

neutron/agent/l3/ha_router.py
neutron/agent/linux/ip_lib.py
neutron/common/constants.py

index b430f44e5a3cbc0e693ff053f19fb5eb1d71b681..31a2c18dc583aa06226113b5ea7656ec5cee1a39 100644 (file)
@@ -191,9 +191,7 @@ class HaRouter(router.RouterInfo):
         for gw_ip in gateway_ips:
                 # TODO(Carl) This is repeated everywhere.  A method would
                 # be nice.
-                default_gw = (n_consts.IPv4_ANY if
-                              netaddr.IPAddress(gw_ip).version == 4 else
-                              n_consts.IPv6_ANY)
+                default_gw = n_consts.IP_ANY[netaddr.IPAddress(gw_ip).version]
                 instance = self._get_keepalived_instance()
                 default_gw_rts.append(keepalived.KeepalivedVirtualRoute(
                     default_gw, gw_ip, interface_name))
index edb35d5a7d766047bb24e4800accdc32b5beb68b..36d2b09523b5dc1458a1d582a3d93866d60a64f9 100644 (file)
@@ -282,8 +282,6 @@ class IPRule(SubProcessBase):
 class IpRuleCommand(IpCommandBase):
     COMMAND = 'rule'
 
-    ALL = {4: constants.IPv4_ANY, 6: constants.IPv6_ANY}
-
     def _parse_line(self, ip_version, line):
         # Typical rules from 'ip rule show':
         # 4030201:  from 1.2.3.4/24 lookup 10203040
@@ -299,7 +297,7 @@ class IpRuleCommand(IpCommandBase):
 
         # Canonicalize some arguments
         if settings.get('from') == "all":
-            settings['from'] = self.ALL[ip_version]
+            settings['from'] = constants.IP_ANY[ip_version]
         if 'lookup' in settings:
             settings['table'] = settings.pop('lookup')
 
index d935273e52764b85a3f8bce656c37d7e50266652..fc9c4b246332a7d778854689fffe7dbb01dcf4bd 100644 (file)
@@ -74,6 +74,7 @@ IPv6_BITS = 128
 
 IPv4_ANY = '0.0.0.0/0'
 IPv6_ANY = '::/0'
+IP_ANY = {IP_VERSION_4: IPv4_ANY, IP_VERSION_6: IPv6_ANY}
 
 DHCP_RESPONSE_PORT = 68