Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions portAuto
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ TRANSPORT = 'socket'
SWITCH_IP = '127.0.0.1'
USERNAME = 'test'
PASSWORD = 'test'
#----------------------------------------------------------------

DESC_DELIMITER = '==>'


# ----------------------------------------------------------------

def log(msg):
'''Log message to stdout and logging file
Expand Down Expand Up @@ -177,6 +181,7 @@ def get_lldp_info(eapi):
output = _parse_raw_neighbor(neigh)
if output:
output['port'] = intf
output['staticDescription'] = _get_static_description(eapi, intf)
lldp_info.append(output)

return lldp_info
Expand All @@ -196,6 +201,15 @@ def _get_lldp_detail(eapi, intf):
return run_cmds(eapi, ['show lldp neighbors %s detail' % intf],
format='text')[0]['output']

def _get_static_description(eapi, intf):
"""Use the JSON output of show interface ethernet XX description
to check for an existing description. If delineated by a set value,
preserve the existing value before updating.
"""
output = run_cmds(eapi, ['show interfaces %s description' % intf], format='json')[0]
description = str.split(output['interfaceDescriptions'][intf]['description'], DESC_DELIMITER)[0]
return description

def _search(data, regex):
if data and regex:
reg = re.compile(r'%s' % regex)
Expand Down Expand Up @@ -279,8 +293,10 @@ def main():

for i in neighbors:
localIntf = i['port']
intfDesc = '*** Link to %s(%s)' % (i['neighborDevice'],
i['neighborPort'])
intfDesc = '%s %s %s(%s)' % (i['staticDescription'],
DESC_DELIMITER,
i['neighborDevice'],
i['neighborPort'])
rc = run_cmds(eapi, ['enable',
'configure',
'interface %s' % localIntf,
Expand Down