- ext_net = router['external_gateway_info']['network_id']
- for port in ports:
- if port['device_id'] == router_id and port['network_id'] == ext_net:
- ip_address = port['fixed_ips'][0]['ip_address']
+ if router and router.get('external_gateway_info'):
+ ext_net = router['external_gateway_info']['network_id']
+ for port in ports:
+ if port['device_id'] == router_id and port['network_id'] == ext_net:
+ ip_address = port['fixed_ips'][0]['ip_address']