Merge pull request #24747 from msciciel/2015.5

add get_route function to network module
This commit is contained in:
Justin Findlay 2015-06-29 10:51:42 -06:00
commit 28c87cab17

View file

@ -1124,3 +1124,28 @@ def default_route(family=None):
ret.append(route)
return ret
def get_route(ip):
'''
Return routing information for given destination ip
CLI Example::
salt '*' network.get_route 10.10.10.10
'''
if __grains__['kernel'] == 'Linux':
cmd = 'ip route get {0}'.format(ip)
out = __salt__['cmd.run'](cmd, python_shell=True)
regexp = re.compile(r'(via\s+(?P<gateway>[\w\.:]+))?\s+dev\s+(?P<interface>[\w\.\:]+)\s+.*src\s+(?P<source>[\w\.:]+)')
m = regexp.search(out.splitlines()[0])
ret = {
'destination': ip,
'gateway': m.group('gateway'),
'interface': m.group('interface'),
'source': m.group('source')}
return ret
else:
raise CommandExecutionError('Not yet supported on this platform')