Skip to content
Browse files

Simplify and enhance Windows ipconfig parsing

  • Loading branch information...
1 parent d62b80c commit e9b443aeea50203461819515e0e6de5cbd7cde03 @twinshadow committed
Showing with 54 additions and 52 deletions.
  1. +54 −52 salt/modules/interfaces.py
View
106 salt/modules/interfaces.py
@@ -54,22 +54,20 @@ def parse_network():
if 'secondary' not in cols:
ipaddr, netmask, broadcast = parse_network()
if type == 'inet':
- if 'addresses' not in data:
- data['addresses'] = list()
+ if 'inet' not in data:
+ data['inet'] = list()
addr_obj = dict()
- addr_obj['proto'] = 'inet'
addr_obj['address'] = ipaddr
addr_obj['netmask'] = netmask
addr_obj['broadcast'] = broadcast
- data['addresses'].append(addr_obj)
+ data['inet'].append(addr_obj)
elif type == 'inet6':
- if 'addresses' not in data:
- data['addresses'] = list()
+ if 'inet6' not in data:
+ data['inet6'] = list()
addr_obj = dict()
- addr_obj['proto'] = 'inet'
addr_obj['address'] = ipaddr
- addr_obj['netmask'] = netmask
- data['addresses'].append(addr_obj)
+ addr_obj['prefixlen'] = netmask
+ data['inet6'].append(addr_obj)
else:
if 'secondary' not in data:
data['secondary'] = []
@@ -122,10 +120,9 @@ def _interfaces_ifconfig(out):
if mmac:
data['hwaddr'] = mmac.group(1)
if mip:
- if not 'addresses' in data:
- data['addresses'] = list()
+ if 'inet' not in data:
+ data['inet'] = list()
addr_obj = dict()
- addr_obj['proto'] = 'inet'
addr_obj['address'] = mip.group(1)
mmask = pmask.match(line)
if mmask:
@@ -138,19 +135,18 @@ def _interfaces_ifconfig(out):
mbcast = pbcast.match(line)
if mbcast:
addr_obj['broadcast'] = mbcast.group(1)
- data['addresses'].append(addr_obj)
+ data['inet'].append(addr_obj)
if mupdown:
updown = True
if mip6:
- if not 'addresses' in data:
- data['addresses'] = list()
+ if 'inet6' not in data:
+ data['inet6'] = list()
addr_obj = dict()
- addr_obj['proto'] = 'inet6'
addr_obj['address'] = mip6.group(1) or mip6.group(2)
mmask6 = pmask6.match(line)
if mmask6:
addr_obj['prefixlen'] = mmask6.group(1) or mmask6.group(2)
- data['addresses'].append(addr_obj)
+ data['inet6'].append(addr_obj)
data['up'] = updown
ret[iface] = data
del data
@@ -166,50 +162,49 @@ def _interfaces_ipconfig(out):
salt '*' network.interfaces
'''
- ret = {}
- ifaces = []
- configstart = 0
- configname = ''
+ ifaces = {}
+ iface = None
for line in out.splitlines():
- if configstart == 3:
- ifaces.append(config)
- configstart = 0
- continue
if not line:
- configstart = configstart + 1
- continue
- if line.startswith(' '):
- comps = line.split(':', 1)
- config[configname][comps[0].rstrip(' .').strip()] = comps[1].strip()
continue
- if configstart == 1:
- configname = line.strip(' :')
- config = {configname: {}}
- configstart = configstart + 1
+ # TODO what does Windows call Infiniband and 10/40gige adapters
+ if line.startswith('Ethernet'):
+ iface = ifaces[re.search('adapter (\S.+):$').group(1)]
+ iface['up'] = True
+ addr = None
continue
- for iface in ifaces:
- for key, val in iface.items():
- item = {}
- itemdict = {'Physical Address': 'hwaddr',
- 'IPv4 Address': 'ipaddr',
- 'Link-local IPv6 Address': 'ipaddr6',
- 'Subnet Mask': 'netmask',
- }
- item['broadcast'] = None
- for k, v in itemdict.items():
- if k in val:
- item[v] = val[k].rstrip('(Preferred)')
- if 'IPv4 Address' in val:
- item['up'] = True
- else:
- item['up'] = False
- ret[key] = item
- return ret
+ if iface:
+ k, v = line.split(',', 1)
+ key = k.strip(' .')
+ val = v.strip()
+ if addr and key in ('Subnet Mask'):
+ addr['netmask'] = val
+ elif key in ('IP Address', 'IPv4 Address'):
+ if 'inet' not in iface:
+ iface['inet'] = list()
+ addr = {'address', val.rstrip('(Preferred)'),
+ 'netmask': None,
+ 'broadcast': None} # TODO find the broadcast
+ iface['inet'].append(addr)
+ elif 'IPv6 Address' in key:
+ if 'inet6' not in iface:
+ iface['inet'] = list()
+ # XXX What is the prefixlen!?
+ addr = {'address': val.rstrip('(Preferred)'),
+ 'prefixlen': None}
+ iface['inet6'].append(addr)
+ elif key in ('Physical Address'):
+ iface['hwaddr'] = val
+ elif key in ('Media State'):
+ # XXX seen used for tunnel adaptors
+ # might be useful
+ iface['up'] = (v != 'Media disconnected')
def _interfaces_ethtool(ifaces):
# parse offloading
'''
+ ethtool -k eth0
Offload parameters for eth0:
rx-checksumming: on
tx-checksumming: on
@@ -223,6 +218,13 @@ def _interfaces_ethtool(ifaces):
tx-vlan-offload: on
ntuple-filters: off
receive-hashing: off
+
+ Different output for 10gige cards as well
+ tx-checksumming: on
+ tx-checksum-ipv4: on
+ tx-checksum-ip-generic: off [fixed]
+ ...
+ scatter-gather: on
'''
return ifaces

0 comments on commit e9b443a

Please sign in to comment.
Something went wrong with that request. Please try again.