mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
bug 10804: add default dns provider
This commit is contained in:
parent
8de59166a4
commit
797836723d
@ -24,13 +24,15 @@
|
||||
# $ip : the associated ip address
|
||||
# $host : the hostname
|
||||
# $4 : default router
|
||||
# $5 : comma separated static routes
|
||||
# $5 : nameserver on default nic
|
||||
# $6 : comma separated static routes
|
||||
|
||||
mac=$1
|
||||
ip=$2
|
||||
host=$3
|
||||
dflt=$4
|
||||
routes=$5
|
||||
dns=$5
|
||||
routes=$6
|
||||
|
||||
DHCP_HOSTS=/etc/dhcphosts.txt
|
||||
DHCP_OPTS=/etc/dhcpopts.txt
|
||||
@ -99,6 +101,7 @@ echo "$ip $host" >> $HOSTS
|
||||
|
||||
if [ "$dflt" != "" ]
|
||||
then
|
||||
logger -t cloud "$0: setting default router to $dflt"
|
||||
#make sure dnsmasq looks into options file
|
||||
sed -i /dhcp-optsfile/d /etc/dnsmasq.conf
|
||||
echo "dhcp-optsfile=$DHCP_OPTS" >> /etc/dnsmasq.conf
|
||||
@ -106,6 +109,11 @@ then
|
||||
tag=$(echo $ip | tr '.' '_')
|
||||
sed -i /$tag/d $DHCP_OPTS
|
||||
echo "$tag,3,$dflt" >> $DHCP_OPTS
|
||||
if [ "$dns" != "" ]
|
||||
then
|
||||
logger -t cloud "$0: setting dns server to $dns"
|
||||
echo "$tag,6,$dns" >> $DHCP_OPTS
|
||||
fi
|
||||
[ "$routes" != "" ] && echo "$tag,121,$routes" >> $DHCP_OPTS
|
||||
#delete entry we just put in because we need a tag
|
||||
sed -i /$mac/d $DHCP_HOSTS
|
||||
|
||||
101
patches/systemvm/debian/config/root/edithosts.sh.orig
Executable file
101
patches/systemvm/debian/config/root/edithosts.sh.orig
Executable file
@ -0,0 +1,101 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
# This software is licensed under the GNU General Public License v3 or later.
|
||||
#
|
||||
# It is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
# edithosts.sh -- edit the dhcphosts file on the routing domain
|
||||
# $1 : the mac address
|
||||
# $2 : the associated ip address
|
||||
# $3 : the hostname
|
||||
|
||||
source /root/func.sh
|
||||
|
||||
lock="biglock"
|
||||
locked=$(getLockFile $lock)
|
||||
if [ "$locked" != "1" ]
|
||||
then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
lock_rr="rrouter"
|
||||
locked_rr=$(getLockFile $lock_rr)
|
||||
if [ "$locked_rr" != "1" ]
|
||||
then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
grep "redundant_router=1" /var/cache/cloud/cmdline > /dev/null
|
||||
no_redundant=$?
|
||||
|
||||
wait_for_dnsmasq () {
|
||||
local _pid=$(pidof dnsmasq)
|
||||
for i in 0 1 2 3 4 5 6 7 8 9 10
|
||||
do
|
||||
sleep 1
|
||||
_pid=$(pidof dnsmasq)
|
||||
[ "$_pid" != "" ] && break;
|
||||
done
|
||||
[ "$_pid" != "" ] && return 0;
|
||||
logger -t cloud "edithosts: timed out waiting for dnsmasq to start"
|
||||
return 1
|
||||
}
|
||||
|
||||
logger -t cloud "edithosts: update $1 $2 $3 to hosts"
|
||||
|
||||
[ ! -f /etc/dhcphosts.txt ] && touch /etc/dhcphosts.txt
|
||||
[ ! -f /var/lib/misc/dnsmasq.leases ] && touch /var/lib/misc/dnsmasq.leases
|
||||
|
||||
#delete any previous entries from the dhcp hosts file
|
||||
sed -i /$1/d /etc/dhcphosts.txt
|
||||
sed -i /$2,/d /etc/dhcphosts.txt
|
||||
sed -i /$3,/d /etc/dhcphosts.txt
|
||||
|
||||
#put in the new entry
|
||||
echo "$1,$2,$3,infinite" >>/etc/dhcphosts.txt
|
||||
|
||||
#delete leases to supplied mac and ip addresses
|
||||
sed -i /$1/d /var/lib/misc/dnsmasq.leases
|
||||
sed -i /"$2 "/d /var/lib/misc/dnsmasq.leases
|
||||
sed -i /"$3 "/d /var/lib/misc/dnsmasq.leases
|
||||
|
||||
#put in the new entry
|
||||
echo "0 $1 $2 $3 *" >> /var/lib/misc/dnsmasq.leases
|
||||
|
||||
#edit hosts file as well
|
||||
sed -i /"$2 "/d /etc/hosts
|
||||
sed -i /"$3"/d /etc/hosts
|
||||
echo "$2 $3" >> /etc/hosts
|
||||
|
||||
# make dnsmasq re-read files
|
||||
pid=$(pidof dnsmasq)
|
||||
if [ "$pid" != "" ]
|
||||
then
|
||||
service dnsmasq restart
|
||||
else
|
||||
if [ $no_redundant -eq 1 ]
|
||||
then
|
||||
wait_for_dnsmasq
|
||||
else
|
||||
logger -t cloud "edithosts: skip wait dnsmasq due to redundant virtual router"
|
||||
fi
|
||||
fi
|
||||
|
||||
ret=$?
|
||||
releaseLockFile $lock_rr $locked_rr
|
||||
unlock_exit $ret $lock $locked
|
||||
@ -38,8 +38,9 @@ add_dhcp_entry() {
|
||||
local ip=$3
|
||||
local vm=$4
|
||||
local dfltrt=$5
|
||||
local staticrt=$6
|
||||
ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domr "/root/edithosts.sh $mac $ip $vm $dfltrt $staticrt" >/dev/null
|
||||
local ns=$6
|
||||
local staticrt=$7
|
||||
ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domr "/root/edithosts.sh $mac $ip $vm $dfltrt $ns $staticrt" >/dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
@ -49,8 +50,9 @@ vmIp=
|
||||
vmName=
|
||||
staticrt=
|
||||
dfltrt=
|
||||
dns=
|
||||
|
||||
while getopts 'r:m:v:n:d:s:' OPTION
|
||||
while getopts 'r:m:v:n:d:s:N:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
r) domrIp="$OPTARG"
|
||||
@ -65,12 +67,14 @@ do
|
||||
;;
|
||||
d) dfltrt="$OPTARG"
|
||||
;;
|
||||
N) dns="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
add_dhcp_entry $domrIp $vmMac $vmIp $vmName $dfltrt $staticrt
|
||||
add_dhcp_entry $domrIp $vmMac $vmIp $vmName $dfltrt $dns $staticrt
|
||||
|
||||
exit $?
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user