Merge pull request #24857 from gtmanfred/develop

add interfaces to subnets
This commit is contained in:
Thomas S Hatch 2015-06-22 16:37:33 -04:00
commit bc08ee3e32
2 changed files with 16 additions and 6 deletions

View File

@ -671,7 +671,7 @@ def interface_ip(iface):
return salt.utils.network.interface_ip(iface)
def subnets():
def subnets(interfaces=None):
'''
Returns a list of IPv4 subnets to which the host belongs
@ -680,8 +680,9 @@ def subnets():
.. code-block:: bash
salt '*' network.subnets
salt '*' network.subnets interfaces=eth1
'''
return salt.utils.network.subnets()
return salt.utils.network.subnets(interfaces)
def subnets6():

View File

@ -848,11 +848,20 @@ def interface_ip(iface):
return error
def _subnets(proto='inet'):
def _subnets(proto='inet', interfaces_=None):
'''
Returns a list of subnets to which the host belongs
'''
ifaces = interfaces()
if interfaces_ is None:
ifaces = interfaces()
elif isinstance(interfaces_, list):
ifaces = {}
for key, value in six.iteritems(interfaces()):
if key in interfaces_:
ifaces[key] = value
else:
ifaces = {interfaces_: interfaces().get(interfaces_, {})}
ret = set()
if proto == 'inet':
@ -874,11 +883,11 @@ def _subnets(proto='inet'):
return [str(net) for net in sorted(ret)]
def subnets():
def subnets(interfaces=None):
'''
Returns a list of IPv4 subnets to which the host belongs
'''
return _subnets('inet')
return _subnets('inet', interfaces_=interfaces)
def subnets6():