Advertisement
Guest User

Untitled

a guest
Mar 14th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. def ifacestartswith(cidr):
  2. '''
  3. Retrieve the interface name from a specific CIDR
  4.  
  5. CLI Example:
  6.  
  7. .. code-block:: bash
  8.  
  9. salt '*' customnetwork.ifacestartswith 10.0
  10. '''
  11. net_list = __salt__['network.interfaces']()
  12. intfnames = []
  13. pattern = str(cidr)
  14. size = len(pattern)
  15. for ifname,ifval in net_list.iteritems():
  16. if ifval.has_key('inet'):
  17. for inet in ifval['inet']:
  18. if inet['address'][0:size] == pattern:
  19. intfnames.append(inet['label'])
  20. return intfnames
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement