Created
January 15, 2020 16:08
-
-
Save djoreilly/b9ae1b1a6fcfa42a096ad692635d3a91 to your computer and use it in GitHub Desktop.
Gather neutron info for VM connectivity problems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Script to gather neutron info for vm connectivity problems. | |
Gets the vm's ports, networks, subnets, security groups | |
and router, external networks and floatingips. | |
source .openrc admin | |
python dump-vm-neutrn-info.py VM_ID | |
""" | |
import sys | |
import os_client_config | |
from pprint import pprint | |
if len(sys.argv) != 2: | |
print("Usage: %s VM_ID" %argv[0]) | |
sys.exit() | |
vm_id = sys.argv[1] | |
nc = os_client_config.make_client('network', cloud='envvars') | |
ports = nc.list_ports(device_id=vm_id) | |
if len(ports['ports']) == 0: | |
print("Can't find port(s) for vm with id: %s" %vm_id) | |
sys.exit() | |
pprint(ports) | |
for port in ports['ports']: | |
net_id = port['network_id'] | |
pprint(nc.list_networks(id=net_id)) | |
pprint(nc.list_subnets(network_id=net_id)) | |
for sg_id in port['security_groups']: | |
#pprint(nc.list_security_groups(id=sg_id)) | |
pprint(nc.list_security_group_rules(security_group_id=sg_id)) | |
snat_ports = nc.list_ports(device_owner="network:router_centralized_snat", | |
network_id=net_id) | |
if len(snat_ports['ports']) > 0: | |
router_id = snat_ports['ports'][0]['device_id'] | |
routers = nc.list_routers(id=router_id) | |
pprint(routers) | |
if len(routers['routers']) > 0: | |
ext_info = routers['routers'][0]['external_gateway_info'] | |
if ext_info: | |
ext_net_id = ext_info['network_id'] | |
ext_nets = nc.list_networks(id=ext_net_id) | |
pprint(ext_nets) | |
pprint(nc.list_subnets(network_id=ext_net_id)) | |
pprint(nc.list_floatingips(port_id=port['id'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment