Created
March 10, 2022 06:18
-
-
Save ViKingIX/527e956ff099f3cafa67fa90c83ceca8 to your computer and use it in GitHub Desktop.
prints ovs port info for given ip[s]
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
#!/bin/bash | |
function port_neutron_obj { | |
cat neutron_port.json | jq ".[] | select(.fixed_ips | contains(\"$1\"))" | |
} | |
function port_ovs_obj { | |
IND_EXT_IDS=$(cat ovs_port.json | jq '.headings | index("external_ids")') | |
IND_OFPORT=$(cat ovs_port.json | jq '.headings | index("ofport")') | |
IND_DEVNAME=$(cat ovs_port.json | jq '.headings | index("name")') | |
cat ovs_port.json | jq ".data[] | select(.[13][1][] | contains([\"iface-id\", \"$1\"]))" | |
} | |
function port_uuid { | |
IP=$1 | |
obj=$(cat neutron_port.json | jq ".[] | select(.fixed_ips | contains(\"$IP\"))") | |
echo $obj | jq -r '.id' | |
} | |
function port_ovsid { | |
UUID=$1 | |
IND_EXT_IDS=$(cat ovs_port.json | jq '.headings | index("external_ids")') | |
IND_OFPORT=$(cat ovs_port.json | jq '.headings | index("ofport")') | |
IND_DEVNAME=$(cat ovs_port.json | jq '.headings | index("name")') | |
obj=$(cat ovs_port.json | jq ".data[] | select(.[13][1][] | contains([\"iface-id\", \"$UUID\"]))") | |
echo $obj | jq ".[$IND_OFPORT]" | |
} | |
IPs=$@ | |
for ip in $IPs | |
do | |
neutron_obj=$(port_neutron_obj $ip) | |
mac=$(echo $neutron_obj | jq -r '.mac_address') | |
ovs_obj=$(port_ovs_obj $(echo "$neutron_obj" | jq -r .id)) | |
port_uuid=$(port_uuid $ip) | |
port_ovsid=$(port_ovsid $port_uuid) | |
devname=$(echo "$ovs_obj" | jq -r ".[$IND_DEVNAME]") | |
echo $ip: uuid: $port_uuid, ovsid: $port_ovsid, mac: $mac 1>&2 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment