WIP - create netbox interfaces with IP
This commit is contained in:
parent
1063ec63e0
commit
d5673d4992
4 changed files with 75 additions and 24 deletions
|
@ -1,7 +1,8 @@
|
|||
# Originally from https://github.com/opencoff/useful-scripts/blob/master/linktest.py
|
||||
|
||||
# mapping fields from ethtool output to simple names
|
||||
field_map = { 'Supported ports': 'ports',
|
||||
field_map = {
|
||||
'Supported ports': 'ports',
|
||||
'Supported link modes': 'sup_link_modes',
|
||||
'Supports auto-negotiation': 'sup_autoneg',
|
||||
'Advertised link modes': 'adv_link_modes',
|
||||
|
@ -13,28 +14,29 @@ field_map = { 'Supported ports': 'ports',
|
|||
'Link detected': 'link',
|
||||
}
|
||||
|
||||
|
||||
def parse_ethtool_output(data):
|
||||
"""parse ethtool output"""
|
||||
"""
|
||||
parse ethtool output
|
||||
"""
|
||||
|
||||
fields = {}
|
||||
field = ""
|
||||
fields['speed'] = "-"
|
||||
fields['link'] = "-"
|
||||
field = ''
|
||||
fields['speed'] = '-'
|
||||
fields['link'] = '-'
|
||||
fields['duplex'] = '-'
|
||||
for line in data.split('\n')[1:]:
|
||||
line = line.rstrip()
|
||||
r = line.find(':')
|
||||
#verbose(" line=|%s|", line)
|
||||
r = line.find(':')
|
||||
if r > 0:
|
||||
field = line[:r].strip()
|
||||
if field not in field_map:
|
||||
continue
|
||||
field = field_map[field]
|
||||
data = line[r+1:].strip()
|
||||
data = line[r+1:].strip()
|
||||
fields[field] = data
|
||||
#verbose(" %s=%s", field, data)
|
||||
else:
|
||||
if len(field) > 0 and \
|
||||
field in field_map.keys():
|
||||
fields[field] += ' ' + line.strip()
|
||||
fields[field] += ' ' + line.strip()
|
||||
return fields
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue