mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
add get_route function to network module
This commit is contained in:
parent
c8713f2d00
commit
f3d184c478
1 changed files with 26 additions and 0 deletions
|
@ -1108,3 +1108,29 @@ 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\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')
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue