mirror of
https://github.com/valitydev/salt.git
synced 2024-11-09 01:36:48 +00:00
update network.py (map removed). Using a more basic way
This commit is contained in:
parent
2b0d7562c6
commit
da70f91faa
@ -737,42 +737,6 @@ def interfaces():
|
||||
return salt.utils.network.interfaces()
|
||||
|
||||
|
||||
def ifacestartswith(cidr):
|
||||
'''
|
||||
Retrieve the interface name from a specific CIDR
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' network.ifacestartswith 10.0
|
||||
'''
|
||||
net_list = interfaces()
|
||||
intfnames = []
|
||||
pattern = str(cidr)
|
||||
size = len(pattern)
|
||||
for ifname,ifval in net_list.iteritems():
|
||||
if ifval.has_key('inet'):
|
||||
for inet in ifval['inet']:
|
||||
if inet['address'][0:size] == pattern:
|
||||
intfnames.append(inet['label'])
|
||||
return intfnames
|
||||
|
||||
|
||||
def iphexval(ip):
|
||||
'''
|
||||
Retrieve the interface name from a specific CIDR
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' network.iphexval 10.0.0.1
|
||||
'''
|
||||
a = ip.split('.')
|
||||
return '{:02X}{:02X}{:02X}{:02X}'.format(*map(int, a))
|
||||
|
||||
|
||||
def hw_addr(iface):
|
||||
'''
|
||||
Return the hardware address (a.k.a. MAC address) for a given interface
|
||||
@ -1491,3 +1455,42 @@ def get_route(ip):
|
||||
|
||||
else:
|
||||
raise CommandExecutionError('Not yet supported on this platform')
|
||||
|
||||
|
||||
def ifacestartswith(cidr):
|
||||
'''
|
||||
Retrieve the interface name from a specific CIDR
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' network.ifacestartswith 10.0
|
||||
'''
|
||||
net_list = interfaces()
|
||||
intfnames = []
|
||||
pattern = str(cidr)
|
||||
size = len(pattern)
|
||||
for ifname, ifval in net_list.iteritems():
|
||||
if 'inet' in ifval:
|
||||
for inet in ifval['inet']:
|
||||
if inet['address'][0:size] == pattern:
|
||||
intfnames.append(inet['label'])
|
||||
return intfnames
|
||||
|
||||
|
||||
def iphexval(ip):
|
||||
'''
|
||||
Retrieve the interface name from a specific CIDR
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' network.iphexval 10.0.0.1
|
||||
'''
|
||||
a = ip.split('.')
|
||||
hexval = ""
|
||||
for val in a:
|
||||
hexval = hexval.join(hex(int(val))[2:])
|
||||
return hexval.upper()
|
||||
|
Loading…
Reference in New Issue
Block a user