Created
March 3, 2016 08:55
-
-
Save tiewei/c24c4ec4af26edac9c82 to your computer and use it in GitHub Desktop.
hack_qvo_tap_ovs_tags
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
--- | |
- hosts: tenant_compute* | |
gather_facts: no | |
tasks: | |
- shell: ovs-vsctl list-ports br-int | egrep "tap" | sed "s/^tap//" | |
register: qvo | |
- shell: ovs-vsctl get Port qvo{{item}} tag | |
with_items: qvo.stdout_lines | |
register: qvo_tags | |
- shell: ovs-vsctl get Port tap{{item}} tag | |
with_items: qvo.stdout_lines | |
register: tap_tags | |
- debug: msg="{{item.0.stdout}} not match "{{item.1.stdout}}"" | |
with_together: | |
- qvo_tags.results | |
- tap_tags.results | |
when: "item.0.rc ==0 and item.1.rc ==0 and item.0.stdout != '[]' and ( item.0.stdout != item.1.stdout)" |
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 | |
if [ -z "$1" ]; then | |
echo 'qvo_tag_add.sh <vm-uuid>' | |
exit 1 | |
fi | |
echo $1 | |
port_ids=$(nova interface-list $1 |depipe|grep -v ^Port|awk '{print $2}') | |
for p in $port_ids; do | |
net_id=$(neutron port-show $p |depipe|grep network_id | awk '{print $2}') | |
vlan_id=$(neutron net-show $net_id | depipe|grep segmentation_id|awk '{print $2}') | |
host=$(neutron port-show $p |depipe|grep host_id | awk '{print $2}') | |
qvo_dev='qvo'${p:0:11} | |
ssh $host /usr/bin/ovs-vsctl show |grep -q $qvo_dev | |
qvo_on_br=$? | |
ssh $host /usr/bin/ovs-vsctl show |grep -A2 'Port \"$qvo_dev\"' |grep -q tag | |
qvo_has_tag=$? | |
tap_dev='tap'${p:0:11} | |
ssh $host /usr/bin/ovs-vsctl show |grep -q $tap_dev | |
tap_on_br=$? | |
if [[ $qvo_on_br == 1 && $tap_on_br == 0 && $qvo_has_tag == 0 ]];then | |
tag_id=$(ssh $host "/usr/bin/ovs-ofctl dump-flows br-int|grep $vlan_id" |awk -F, '{print $10}' |awk -F: '{print $2}' ) | |
echo $tag_id | |
ssh $host "/usr/bin/ovs-vsctl --timeout=10 set Port $qvo_dev tag=$tag_id" | |
else | |
echo "qvo on bridge $qvo_on_br" | |
echo "tap on bridge $tap_on_br" | |
echo "qvo has tag $qvo_has_tag" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment