From c91c8da4cf936dae2eddae31132c9a847026cc68 Mon Sep 17 00:00:00 2001 From: Dave Boucha Date: Mon, 15 Oct 2012 13:22:51 -0600 Subject: [PATCH 1/2] Add include_loopback to network.ip_addrs setting include_loopback to True will cause network.ip_addrs and network.ip_addrs6 to include the local loopback address in the list of IP addresses. --- salt/modules/network.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/salt/modules/network.py b/salt/modules/network.py index 66cc677afc..a3189b58c0 100644 --- a/salt/modules/network.py +++ b/salt/modules/network.py @@ -311,7 +311,7 @@ def in_subnet(cidr): return False -def ip_addrs(): +def ip_addrs(include_loopback=False): ''' Returns a list of IPv4 addresses assigned to the host. (127.0.0.1 is ignored) @@ -321,10 +321,12 @@ def ip_addrs(): for ipv4_info in ifaces.values(): for ipv4 in ipv4_info.get('inet',[]): if ipv4['address'] != '127.0.0.1': ret.append(ipv4['address']) + else: + if include_loopback: ret.append(ipv4['address']) return ret -def ip_addrs6(): +def ip_addrs6(include_loopback=False): ''' Returns a list of IPv6 addresses assigned to the host. (::1 is ignored) ''' @@ -333,6 +335,8 @@ def ip_addrs6(): for ipv6_info in ifaces.values(): for ipv6 in ipv6_info.get('inet6',[]): if ipv6['address'] != '::1': ret.append(ipv6['address']) + else: + if include_loopback: ret.append(ipv6['address']) return ret From 7c02026a6b9be71d2a9b38540352b77460ef53c4 Mon Sep 17 00:00:00 2001 From: Dave Boucha Date: Mon, 15 Oct 2012 15:46:59 -0600 Subject: [PATCH 2/2] Add documentation to network.ip_addrs Add note to the documentation that include_loopback=True will add the loopback address to returned results --- salt/modules/network.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/salt/modules/network.py b/salt/modules/network.py index a3189b58c0..9f21c80891 100644 --- a/salt/modules/network.py +++ b/salt/modules/network.py @@ -314,7 +314,7 @@ def in_subnet(cidr): def ip_addrs(include_loopback=False): ''' Returns a list of IPv4 addresses assigned to the host. (127.0.0.1 is - ignored) + ignored, unless 'include_loopback=True' is indicated) ''' ret = [] ifaces = interfaces() @@ -328,7 +328,8 @@ def ip_addrs(include_loopback=False): def ip_addrs6(include_loopback=False): ''' - Returns a list of IPv6 addresses assigned to the host. (::1 is ignored) + Returns a list of IPv6 addresses assigned to the host. (::1 is ignored, + unless 'include_loopback=True' is indicated) ''' ret = [] ifaces = interfaces()