I am trying to pull out some specific values from this output:
{'GigabitEthernet': [{'name': '1', 'ip': {'address': {'primary': {'address': '192.168.200.200', 'mask': '255.255.255.0'}}, 'Cisco-IOS-XE-ospf:router-ospf': {'ospf': {'authentication': {'key-chain': 'sv-10599'}, 'message-digest-key': [{'id': 1, 'md5': {'auth-key': 'cisco'}}], 'network': {'point-to-point': [None]}}}}, 'mop': {'enabled': False, 'sysid': False}, 'Cisco-IOS-XE-ethernet:negotiation': {'auto': True}}, {'name': '2', 'shutdown': [None], 'mop': {'enabled': False, 'sysid': False}, 'Cisco-IOS-XE-ethernet:negotiation': {'auto': True}}, {'name': '3', 'shutdown': [None], 'mop': {'enabled': False, 'sysid': False}, 'Cisco-IOS-XE-ethernet:negotiation': {'auto': True}}]}
Ideally I would like to get the following values:
GigabitEthernet 1 192.168.200.200
GigabitEthernet 2 Shutdown
# determine interface IP addresses
for interface_type_gig in device_config['Cisco-IOS-XE-native:native']['interface']['GigabitEthernet']:
interface_name = 'GigabitEthernet ' + interface_type_gig['name']
print(interface_name)
interface_address = interface_type_gig['ip']['address']['primary']['address']
print(interface_address)
I am able to get the ['name'] but not the IP address. Interface_address returns a KeyError: 1
I am not able to get figure out.