]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
net: Return both IPv4 and IPv6 addresses 463/head
authorWido den Hollander <wido@42on.com>
Mon, 29 Jan 2018 14:30:20 +0000 (15:30 +0100)
committerWido den Hollander <wido@42on.com>
Mon, 29 Jan 2018 14:30:20 +0000 (15:30 +0100)
When using ceph-deploy it will now also show the IPv6 addresses
it found for a node:

  IP addresses found: [u'192.168.153.10', u'2001:db8::100', u'10.0.2.15']

The resulting ceph.conf will use IPv6 addresses for the Monitors:

  ms_bind_ipv6 = true
  mon_host = [2001:db8::100],[2001:db8::101],[2001:db8::102]

Signed-off-by: Wido den Hollander <wido@42on.com>
ceph_deploy/util/net.py

index f23c6654a502388c297dbe1d0bfb58b828045004..73c39140d85a3e0a2cd64e2b4cb4c6a2ce6a4575 100644 (file)
@@ -70,14 +70,14 @@ def in_subnet(cidr, addrs=None):
 
 def ip_addresses(conn, interface=None, include_loopback=False):
     """
-    Returns a list of IPv4 addresses assigned to the host. 127.0.0.1 is
+    Returns a list of IPv4/IPv6 addresses assigned to the host. 127.0.0.1/::1 is
     ignored, unless 'include_loopback=True' is indicated. If 'interface' is
     provided, then only IP addresses from that interface will be returned.
 
     Example output looks like::
 
         >>> ip_addresses(conn)
-        >>> ['192.168.1.111', '10.0.1.12']
+        >>> ['192.168.1.111', '10.0.1.12', '2001:db8::100']
 
     """
     ret = set()
@@ -89,16 +89,25 @@ def ip_addresses(conn, interface=None, include_loopback=False):
                              if k == interface)
         if not target_ifaces:
             LOG.error('Interface {0} not found.'.format(interface))
-    for ipv4_info in target_ifaces.values():
-        for ipv4 in ipv4_info.get('inet', []):
+    for info in target_ifaces.values():
+        for ipv4 in info.get('inet', []):
             loopback = in_subnet('127.0.0.0/8', [ipv4.get('address')]) or ipv4.get('label') == 'lo'
             if not loopback or include_loopback:
                 ret.add(ipv4['address'])
-        for secondary in ipv4_info.get('secondary', []):
+        for secondary in info.get('secondary', []):
             addr = secondary.get('address')
             if addr and secondary.get('type') == 'inet':
                 if include_loopback or (not include_loopback and not in_subnet('127.0.0.0/8', [addr])):
                     ret.add(addr)
+        for ipv6 in info.get('inet6', []):
+            # When switching to Python 3 the IPAddress module can do all this work for us
+            if ipv6.get('address').startswith('fe80::'):
+                continue
+
+            if not include_loopback and '::1' == ipv6.get('address'):
+                continue
+
+            ret.add(ipv6['address'])
     if ret:
         conn.logger.debug('IP addresses found: %s' % str(list(ret)))
     return sorted(list(ret))