Created
October 10, 2016 05:55
-
-
Save leoh0/eb8fee126563651f6c1bde813ed92619 to your computer and use it in GitHub Desktop.
Revisions
-
leoh0 created this gist
Oct 10, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ #!/opt/openstack/venv/bin/python import MySQLdb import sys import json connection = MySQLdb.connect( host=sys.argv[1], user="nova", passwd=sys.argv[2], db="nova") cursor = connection.cursor() cursor.execute("select network_info, instance_uuid from instance_info_caches where deleted=0") h = {} for f in cursor.fetchall(): d = json.loads(f[0])[0] d['details'].pop('ovs_hybrid_plug', None) net_prefix = d['network']['id'][:11] d['network']['bridge'] = "brq%s" % net_prefix d['network']['meta']['should_create_bridge'] = True d['ovs_interfaceid'] = None d['type'] = "bridge" h[f[1]] = json.dumps([d]) cursor.close() cursor = connection.cursor() for k in h.keys(): cursor.execute("update instance_info_caches set network_info='%s' where instance_uuid='%s'" % (h[k], k)) cursor.close() connection.commit() connection.close() connection = MySQLdb.connect( host=sys.argv[1], user="neutron", passwd=sys.argv[3], db="neutron") cursor = connection.cursor() cursor.execute("update ml2_port_bindings set vif_type='bridge', driver='linuxbridge', vif_details='{\"port_filter\": true}'") cursor.close() connection.commit() connection.close() This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ #!/bin/bash # 미래를 위한 투자.. chef-client 에서 안되는 부분 cp /opt/openstack/src/neutron/etc/neutron/rootwrap.d/linuxbridge-plugin.filters /etc/neutron/rootwrap.d/linuxbridge-plugin.filters source /root/openrc source /opt/openstack/venv/bin/activate GATHER_INFORMATION_PREFIX=/tmp/ovstobridge GATHER_INFORMATION=$GATHER_INFORMATION_PREFIX-if DHCP_GATHER_INFORMATION=$GATHER_INFORMATION_PREFIX-dhcp echo '' > $GATHER_INFORMATION echo '' > $DHCP_GATHER_INFORMATION # local 자원 수집 while read -r _ ID _ IP _ ; do IP=$(echo $IP | cut -d'=' -f2) NET_ID=$(neutron port-list --fixed-ips ip_address=$IP -c network_id | sed '2d' | grep '|' | cut -d' ' -f2) PORT_ID=$(neutron port-list --fixed-ips ip_address=$IP -c id | sed '2d' | grep '|' | cut -d' ' -f2) NET_ID_PREFIX=${NET_ID:0:11} PORT_ID_PREFIX=${PORT_ID:0:11} VLAN=$(neutron net-show $NET_ID -c provider:segmentation_id | sed '2d' | grep '|' | cut -d' ' -f4) echo $VLAN $NET_ID_PREFIX $PORT_ID_PREFIX >> $GATHER_INFORMATION done< <(nova list --all-tenants --fields Networks --host $HOSTNAME | sed '2d' | grep '|') # dhcp 자원 수집 while read -r DHCP_PORT_ID ; do DHCP_NET_ID=$(neutron port-show $DHCP_PORT_ID -F network_id | sed '2d' | grep '|' | cut -d' ' -f4) DHCP_NET_ID_PREFIX=${DHCP_NET_ID:0:11} DHCP_PORT_ID_PREFIX=${DHCP_PORT_ID:0:11} DHCP_VLAN=$(neutron net-show $DHCP_NET_ID -c provider:segmentation_id | sed '2d' | grep '|' | cut -d' ' -f4) echo $DHCP_VLAN $DHCP_NET_ID_PREFIX $DHCP_PORT_ID_PREFIX >> $DHCP_GATHER_INFORMATION done< <(neutron port-list --device-owner=network:dhcp --binding:host_id $HOSTNAME | sed '2d' | grep '|' | cut -d' ' -f2) # bridge 와 vlan 인터페이스 생성 while read -r VLAN NET_ID_PREFIX; do if [ "x$VLAN" == "x" ] ; then continue; fi brctl addbr brq${NET_ID_PREFIX} brctl setfd brq${NET_ID_PREFIX} '0' brctl stp brq${NET_ID_PREFIX} off ip link set brq${NET_ID_PREFIX} up ip link add link eth1 name eth1.$VLAN type vlan id $VLAN ip link set eth1.$VLAN up brctl addif brq${NET_ID_PREFIX} eth1.$VLAN done< <(cat $GATHER_INFORMATION_PREFIX-* | cut -d' ' -f-2 | sort | uniq) # vm vif 옮기기 while read -r VLAN NET_ID_PREFIX PORT_ID_PREFIX; do if [ "x$VLAN" == "x" ] ; then continue; fi brctl delif qbr${PORT_ID_PREFIX} tap${PORT_ID_PREFIX} brctl addif brq${NET_ID_PREFIX} tap${PORT_ID_PREFIX} done< <(cat $GATHER_INFORMATION) # dhcp 옮기기 while read -r DHCP_VLAN DHCP_NET_ID_PREFIX DHCP_PORT_ID_PREFIX; do if [ "x$DHCP_VLAN" == "x" ] ; then continue; fi ovs-vsctl del-port br-int tap$DHCP_PORT_ID_PREFIX brctl addif brq${DHCP_NET_ID_PREFIX} tap${DHCP_PORT_ID_PREFIX} done< <(cat $DHCP_GATHER_INFORMATION)