Skip to content

Commit

Permalink
Hardened loopback sub-if check and operational state validation
Browse files Browse the repository at this point in the history
  • Loading branch information
gjim83 committed Jan 19, 2018
1 parent 6e80953 commit 2383ed8
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions napalm_panos/panos.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,16 +524,23 @@ def get_interfaces(self):
interface_info_xml = xmltodict.parse(self.device.xml_root())
interface_info_json = json.dumps(interface_info_xml['response']['result']['hw'])
interface_info = json.loads(interface_info_json)
except KeyError:
# loopback sub-ifs don't return a 'hw' key
interface_dict[intf] = LOOPBACK_SUBIF_DEFAULTS
continue

state = interface_info.get('state') == 'up'
state_enabled = interface_info.get('state_c') != 'down' # up -> 'up' or 'auto'

interface['is_up'] = state
interface['is_enabled'] = state_enabled
except KeyError as err:
if 'loopback.' in interface and 'hw' in str(err):
# loopback sub-ifs don't return a 'hw' key
interface_dict[intf] = LOOPBACK_SUBIF_DEFAULTS
continue
raise

interface['is_up'] = interface_info.get('state') == 'up'

conf_state = interface_info.get('state_c')
if conf_state == 'down':
interface['is_enabled'] = False
elif conf_state in ('up', 'auto'):
interface['is_enabled'] = True
else:
msg = 'Unknown configured state {} for interface {}'.format(conf_state, name)
raise RuntimeError(msg)

interface['last_flapped'] = -1.0
interface['speed'] = interface_info.get('speed')
Expand Down

0 comments on commit 2383ed8

Please sign in to comment.