It is always required to get the information like instance ID, the networks ID, router ID, tenant ID, port details etc... from an Floating IP during the troubleshooting time.
There is no straight forward a single command which can give all the informations at a time. How-ever I have customized and written script to collect all the infos. The script will use DataBase and the openstack client commands where-ever required. I have tried best to collect the information from the DB itself.
Download the below script to a file (check_fip_details.sh), save it and make executable. Execute the command as
# ./check_fip_details.sh 9.192.100.12
Device Type = Instance Floating ip
Instance ID / Name = 6xxxxxx7-bxxx8-6xxxx6-5xxa-xxxx / web_instance
Compute Node = comp02
Instance Flavor = x-mem
Tenant ID / Name = xxxx / Test
Fixed IP = 192.168.1.15
Fixed Network ID / Name = xxxxx-35b1-47bc-a502-xxxxx / private
Router ID / Name = xx-ac5e-48b8-9543-xx / ha_router
Secgroup ID/Name = 34ddcxxxx-43eb-4a45-b391-xxxxxx / default,
Subnet ID = xxxxx-f10c-427e-a63f-xxx
FloatingIP Port ID = xxxxx-e504-44ad-94db-xx
Fixed/Private IP Port ID = xxxxx-ad85-4692-8ca8-xx
Floating IP status = ACTIVE
==================================================================
############## Script starts here ###########
#!/bin/bash
source <openrc_admin_file>
if [ -z "$1" ]
then
echo "Floating IP required as an argument 1"
exit
fi
floatingip_details=$(mysql -B -e "select * from floatingips where floating_ip_address='$1'" neutron | head -n 2 | tail -n 1)
chk_fip=$(echo $floatingip_details | grep $1 | wc -l)
if [[ $chk_fip -eq 0 ]]; then
port_id=$(neutron port-list | grep -w $1 | awk {'print $2'})
if [[ ! -z $port_id ]]; then
device_type=$(neutron port-show $port_id | grep device_owner | cut -d ":" -f2 | awk {'print $1'})
if [[ $device_type -eq "router_gateway" ]]; then
Device_Type="Tenant Router"
echo $Device_Type
exit
fi
else
echo "A valid floating IP required ...."
exit
fi
elif [[ $chk_fip -eq 1 ]]; then
tenant_id=$(echo $floatingip_details | awk {'print $1'})
tenant_name=$(openstack project show $tenant_id | grep name | awk {'print $4'})
floatingip_id=$(echo $floatingip_details | awk {'print $2'})
floating_ip_address=$(echo $floatingip_details | awk {'print $3'})
floating_network_id=$(echo $floatingip_details | awk {'print $4'})
floating_port_id=$(echo $floatingip_details | awk {'print $5'})
fixed_port_id=$(echo $floatingip_details | awk {'print $6'})
fixed_ip_address=$(echo $floatingip_details | awk {'print $7'})
router_id=$(echo $floatingip_details | awk {'print $8'})
router_name=$(neutron router-show $router_id | grep name |awk {'print $4'} )
fip_status=$(echo $floatingip_details | awk {'print $10'})
if [[ $fixed_port_id == "NULL" ]]; then
Device_Type="Seems Floating IP only allocated to project"
else
Device_Type="Instance Floating ip"
port_details=$(neutron port-show $fixed_port_id)
fixed_subnet_id=$(echo $port_details | awk -F subnet_id {'print $2'} | awk {'print $2'} | sed "s/\"\,//g" |sed "s/\"//")
instance_id=$(echo $port_details |awk -F device_id {'print $2'} | awk {'print $2'})
fixed_network_id=$(echo $port_details | awk -F network_id {'print $2'} | awk {'print $2'})
fixed_network_name=$(mysql -B -e "select name from networks where id='$fixed_network_id'" neutron | head -n 2 | tail -n 1)
instance_name=$(mysql -B -e " select hostname from instances where uuid='$instance_id'" nova | head -n 2 | tail -n 1 )
secgoups=`nova list-secgroup $instance_id | tail -n +4 | awk {'print $2 " / " $4 "," '} | sed -e '$ d' | xargs`
# compute_node=$(nova show $instance_id | grep "OS-EXT-SRV-ATTR:host" | awk {'print $4'})
for i in `nova show $instance_id | grep -iw -eflavor -ehost | sed 's/ //g'`
do
if echo "$i" | grep -q "host"; then compute_node=`echo $i|cut -f 3 -d \|` ;fi
if echo "$i" | grep -q "flavor"; then flavor=`echo $i|cut -f 3 -d \| |cut -f 1 -d \(` ;fi
done
fi
fi
echo "Device Type = $Device_Type "
echo "Instance ID / Name = $instance_id / $instance_name "
echo "Compute Node = $compute_node "
echo "Instance Flavor = $flavor "
echo "Tenant ID / Name = $tenant_id / $tenant_name "
echo "Fixed IP = $fixed_ip_address "
echo "Fixed Network ID / Name = $fixed_network_id / $fixed_network_name"
echo "Router ID / Name = $router_id / $router_name "
echo "Secgroup ID/Name = $secgoups"
echo "Subnet ID = $fixed_subnet_id "
echo "FloatingIP Port ID = $floating_port_id "
echo "Fixed/Private IP Port ID = $fixed_port_id "
echo "Floating IP status = $fip_status "
echo "=================================================================="
############## End of Script ###########
There is no straight forward a single command which can give all the informations at a time. How-ever I have customized and written script to collect all the infos. The script will use DataBase and the openstack client commands where-ever required. I have tried best to collect the information from the DB itself.
Download the below script to a file (check_fip_details.sh), save it and make executable. Execute the command as
# ./check_fip_details.sh 9.192.100.12
Device Type = Instance Floating ip
Instance ID / Name = 6xxxxxx7-bxxx8-6xxxx6-5xxa-xxxx / web_instance
Compute Node = comp02
Instance Flavor = x-mem
Tenant ID / Name = xxxx / Test
Fixed IP = 192.168.1.15
Fixed Network ID / Name = xxxxx-35b1-47bc-a502-xxxxx / private
Router ID / Name = xx-ac5e-48b8-9543-xx / ha_router
Secgroup ID/Name = 34ddcxxxx-43eb-4a45-b391-xxxxxx / default,
Subnet ID = xxxxx-f10c-427e-a63f-xxx
FloatingIP Port ID = xxxxx-e504-44ad-94db-xx
Fixed/Private IP Port ID = xxxxx-ad85-4692-8ca8-xx
Floating IP status = ACTIVE
==================================================================
############## Script starts here ###########
#!/bin/bash
source <openrc_admin_file>
if [ -z "$1" ]
then
echo "Floating IP required as an argument 1"
exit
fi
floatingip_details=$(mysql -B -e "select * from floatingips where floating_ip_address='$1'" neutron | head -n 2 | tail -n 1)
chk_fip=$(echo $floatingip_details | grep $1 | wc -l)
if [[ $chk_fip -eq 0 ]]; then
port_id=$(neutron port-list | grep -w $1 | awk {'print $2'})
if [[ ! -z $port_id ]]; then
device_type=$(neutron port-show $port_id | grep device_owner | cut -d ":" -f2 | awk {'print $1'})
if [[ $device_type -eq "router_gateway" ]]; then
Device_Type="Tenant Router"
echo $Device_Type
exit
fi
else
echo "A valid floating IP required ...."
exit
fi
elif [[ $chk_fip -eq 1 ]]; then
tenant_id=$(echo $floatingip_details | awk {'print $1'})
tenant_name=$(openstack project show $tenant_id | grep name | awk {'print $4'})
floatingip_id=$(echo $floatingip_details | awk {'print $2'})
floating_ip_address=$(echo $floatingip_details | awk {'print $3'})
floating_network_id=$(echo $floatingip_details | awk {'print $4'})
floating_port_id=$(echo $floatingip_details | awk {'print $5'})
fixed_port_id=$(echo $floatingip_details | awk {'print $6'})
fixed_ip_address=$(echo $floatingip_details | awk {'print $7'})
router_id=$(echo $floatingip_details | awk {'print $8'})
router_name=$(neutron router-show $router_id | grep name |awk {'print $4'} )
fip_status=$(echo $floatingip_details | awk {'print $10'})
if [[ $fixed_port_id == "NULL" ]]; then
Device_Type="Seems Floating IP only allocated to project"
else
Device_Type="Instance Floating ip"
port_details=$(neutron port-show $fixed_port_id)
fixed_subnet_id=$(echo $port_details | awk -F subnet_id {'print $2'} | awk {'print $2'} | sed "s/\"\,//g" |sed "s/\"//")
instance_id=$(echo $port_details |awk -F device_id {'print $2'} | awk {'print $2'})
fixed_network_id=$(echo $port_details | awk -F network_id {'print $2'} | awk {'print $2'})
fixed_network_name=$(mysql -B -e "select name from networks where id='$fixed_network_id'" neutron | head -n 2 | tail -n 1)
instance_name=$(mysql -B -e " select hostname from instances where uuid='$instance_id'" nova | head -n 2 | tail -n 1 )
secgoups=`nova list-secgroup $instance_id | tail -n +4 | awk {'print $2 " / " $4 "," '} | sed -e '$ d' | xargs`
# compute_node=$(nova show $instance_id | grep "OS-EXT-SRV-ATTR:host" | awk {'print $4'})
for i in `nova show $instance_id | grep -iw -eflavor -ehost | sed 's/ //g'`
do
if echo "$i" | grep -q "host"; then compute_node=`echo $i|cut -f 3 -d \|` ;fi
if echo "$i" | grep -q "flavor"; then flavor=`echo $i|cut -f 3 -d \| |cut -f 1 -d \(` ;fi
done
fi
fi
echo "Device Type = $Device_Type "
echo "Instance ID / Name = $instance_id / $instance_name "
echo "Compute Node = $compute_node "
echo "Instance Flavor = $flavor "
echo "Tenant ID / Name = $tenant_id / $tenant_name "
echo "Fixed IP = $fixed_ip_address "
echo "Fixed Network ID / Name = $fixed_network_id / $fixed_network_name"
echo "Router ID / Name = $router_id / $router_name "
echo "Secgroup ID/Name = $secgoups"
echo "Subnet ID = $fixed_subnet_id "
echo "FloatingIP Port ID = $floating_port_id "
echo "Fixed/Private IP Port ID = $fixed_port_id "
echo "Floating IP status = $fip_status "
echo "=================================================================="
############## End of Script ###########
No comments:
Post a Comment