From 2383ed82a1171a76952f5e1f235637d0ea71ee9b Mon Sep 17 00:00:00 2001 From: gjim83 Date: Thu, 18 Jan 2018 18:20:21 -0600 Subject: [PATCH] Hardened loopback sub-if check and operational state validation --- napalm_panos/panos.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/napalm_panos/panos.py b/napalm_panos/panos.py index 8685229..f6bdbe7 100644 --- a/napalm_panos/panos.py +++ b/napalm_panos/panos.py @@ -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')