VPC : add nic hot plug script
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/d51e3443 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/d51e3443 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/d51e3443 Branch: refs/heads/vpc Commit: d51e3443cb4296368bdb0dd1c51b2991b5ce70ce Parents: 982562b Author: anthony <[email protected]> Authored: Tue Jun 12 11:55:48 2012 -0700 Committer: Alena Prokharchyk <[email protected]> Committed: Fri Jun 15 14:32:10 2012 -0700 ---------------------------------------------------------------------- patches/systemvm/debian/config/etc/cloud-nic.rules | 2 + .../debian/config/etc/init.d/cloud-early-config | 3 +- .../debian/config/opt/cloud/bin/cloud-nic.sh | 35 +++++++++++++++ 3 files changed, 39 insertions(+), 1 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d51e3443/patches/systemvm/debian/config/etc/cloud-nic.rules ---------------------------------------------------------------------- diff --git a/patches/systemvm/debian/config/etc/cloud-nic.rules b/patches/systemvm/debian/config/etc/cloud-nic.rules new file mode 100644 index 0000000..56e74ec --- /dev/null +++ b/patches/systemvm/debian/config/etc/cloud-nic.rules @@ -0,0 +1,2 @@ +SUBSYSTEM=="net" KERNEL=="eth*" RUN+="/opt/cloud/bin/cloud-nic.sh $env{ACTION} %k" + http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d51e3443/patches/systemvm/debian/config/etc/init.d/cloud-early-config ---------------------------------------------------------------------- diff --git a/patches/systemvm/debian/config/etc/init.d/cloud-early-config b/patches/systemvm/debian/config/etc/init.d/cloud-early-config index 210a066..d46a1e7 100755 --- a/patches/systemvm/debian/config/etc/init.d/cloud-early-config +++ b/patches/systemvm/debian/config/etc/init.d/cloud-early-config @@ -616,8 +616,9 @@ EOF chkconfig nfs-common off cp /etc/iptables/iptables-vpcrouter /etc/iptables/rules cp /etc/vpcdnsmasq.conf /etc/dnsmasq.conf + cp /etc/cloud-nic.rules /etc/udev/rules.d/cloud-nic.rules echo "" > /etc/dnsmasq.d/dhcphosts.txt - echo "dhcp-hostsfile=/etc/dnsmasq.d/dhcphosts.txt" > /etc/dnsmasq.d/cloud.conf + echo "dhcp-hostsfile=/etc/dhcphosts.txt" > /etc/dnsmasq.d/cloud.conf } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d51e3443/patches/systemvm/debian/config/opt/cloud/bin/cloud-nic.sh ---------------------------------------------------------------------- diff --git a/patches/systemvm/debian/config/opt/cloud/bin/cloud-nic.sh b/patches/systemvm/debian/config/opt/cloud/bin/cloud-nic.sh new file mode 100755 index 0000000..1f1e52e --- /dev/null +++ b/patches/systemvm/debian/config/opt/cloud/bin/cloud-nic.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + + +plug_nic() { + sudo iptables -t mangle -A PREROUTING -i $dev -m state --state NEW -j MARK --set-mark $tableNo 2>/dev/null + sudo iptables -t mangle -A PREROUTING -i $dev -m state --state NEW -j CONNMARK --save-mark 2>/dev/null + + sudo echo "$tableNo $tableName" >> /etc/iproute2/rt_tables 2>/dev/null + sudo ip rule add fwmark $tableNo table $tableName 2>/dev/null + sudo ip route flush table $tableName + sudo ip route flush cache +} + + +unplug_nic() { + sudo iptables -t mangle -D PREROUTING -i $dev -m state --state NEW -j MARK --set-mark $tableNo 2>/dev/null + sudo iptables -t mangle -D PREROUTING -i $dev -m state --state NEW -j CONNMARK --save-mark 2>/dev/null + + sudo sed -i '/"$tableNo $tableName"/d' /etc/iproute2/rt_tables 2>/dev/null + sudo ip rule delete fwmark $tableNo table $tableName 2>/dev/null + sudo ip route flush table $tableName + sudo ip route flush cache +} + +action=$1 +dev=$2 +tableNo=$(echo $dev | awk -F'eth' '{print $2}') +tableName="Table_$dev" + +if [ $action == 'add' ] +then + plug_nic +else + unplug_nic +fi
