mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
bug 10804 virtual router support for per-vm default network
This commit is contained in:
parent
e2743c66cd
commit
89f13ad700
@ -27,6 +27,9 @@ public class DhcpEntryCommand extends NetworkElementCommand {
|
|||||||
String dns;
|
String dns;
|
||||||
String gateway;
|
String gateway;
|
||||||
String nextServer;
|
String nextServer;
|
||||||
|
String defaultRouter;
|
||||||
|
String staticRoutes;
|
||||||
|
|
||||||
|
|
||||||
protected DhcpEntryCommand() {
|
protected DhcpEntryCommand() {
|
||||||
|
|
||||||
@ -77,4 +80,21 @@ public class DhcpEntryCommand extends NetworkElementCommand {
|
|||||||
return nextServer;
|
return nextServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDefaultRouter() {
|
||||||
|
return defaultRouter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultRouter(String defaultRouter) {
|
||||||
|
this.defaultRouter = defaultRouter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStaticRoutes() {
|
||||||
|
return staticRoutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStaticRoutes(String staticRoutes) {
|
||||||
|
this.staticRoutes = staticRoutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1436,6 +1436,12 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||||||
args += " -v " + cmd.getVmIpAddress();
|
args += " -v " + cmd.getVmIpAddress();
|
||||||
args += " -m " + cmd.getVmMac();
|
args += " -m " + cmd.getVmMac();
|
||||||
args += " -n " + cmd.getVmName();
|
args += " -n " + cmd.getVmName();
|
||||||
|
if (cmd.getDefaultRouter() != null) {
|
||||||
|
args += " -d " + cmd.getDefaultRouter();
|
||||||
|
}
|
||||||
|
if (cmd.getStaticRoutes() != null) {
|
||||||
|
args += " -s " + cmd.getStaticRoutes();
|
||||||
|
}
|
||||||
String result = callHostPlugin(conn, "vmops", "saveDhcpEntry", "args", args);
|
String result = callHostPlugin(conn, "vmops", "saveDhcpEntry", "args", args);
|
||||||
if (result == null || result.isEmpty()) {
|
if (result == null || result.isEmpty()) {
|
||||||
return new Answer(cmd, false, "DhcpEntry failed");
|
return new Answer(cmd, false, "DhcpEntry failed");
|
||||||
|
|||||||
@ -20,9 +20,22 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# edithosts.sh -- edit the dhcphosts file on the routing domain
|
# edithosts.sh -- edit the dhcphosts file on the routing domain
|
||||||
# $1 : the mac address
|
# $mac : the mac address
|
||||||
# $2 : the associated ip address
|
# $ip : the associated ip address
|
||||||
# $3 : the hostname
|
# $host : the hostname
|
||||||
|
# $4 : default router
|
||||||
|
# $5 : comma separated static routes
|
||||||
|
|
||||||
|
mac=$1
|
||||||
|
ip=$2
|
||||||
|
host=$3
|
||||||
|
dflt=$4
|
||||||
|
routes=$5
|
||||||
|
|
||||||
|
DHCP_HOSTS=/etc/dhcphosts.txt
|
||||||
|
DHCP_OPTS=/etc/dhcpopts.txt
|
||||||
|
DHCP_LEASES=/var/lib/misc/dnsmasq.leases
|
||||||
|
HOSTS=/etc/hosts
|
||||||
|
|
||||||
source /root/func.sh
|
source /root/func.sh
|
||||||
|
|
||||||
@ -58,29 +71,47 @@ wait_for_dnsmasq () {
|
|||||||
|
|
||||||
logger -t cloud "edithosts: update $1 $2 $3 to hosts"
|
logger -t cloud "edithosts: update $1 $2 $3 to hosts"
|
||||||
|
|
||||||
[ ! -f /etc/dhcphosts.txt ] && touch /etc/dhcphosts.txt
|
[ ! -f $DHCP_HOSTS ] && touch $DHCP_HOSTS
|
||||||
[ ! -f /var/lib/misc/dnsmasq.leases ] && touch /var/lib/misc/dnsmasq.leases
|
[ ! -f $DHCP_OPTS ] && touch $DHCP_OPTS
|
||||||
|
[ ! -f $DHCP_LEASES ] && touch $DHCP_LEASES
|
||||||
|
|
||||||
#delete any previous entries from the dhcp hosts file
|
#delete any previous entries from the dhcp hosts file
|
||||||
sed -i /$1/d /etc/dhcphosts.txt
|
sed -i /$mac/d $DHCP_HOSTS
|
||||||
sed -i /$2,/d /etc/dhcphosts.txt
|
sed -i /$ip,/d $DHCP_HOSTS
|
||||||
sed -i /$3,/d /etc/dhcphosts.txt
|
sed -i /$host,/d $DHCP_HOSTS
|
||||||
|
|
||||||
|
|
||||||
#put in the new entry
|
#put in the new entry
|
||||||
echo "$1,$2,$3,infinite" >>/etc/dhcphosts.txt
|
echo "$mac,$ip,$host,infinite" >>$DHCP_HOSTS
|
||||||
|
|
||||||
#delete leases to supplied mac and ip addresses
|
#delete leases to supplied mac and ip addresses
|
||||||
sed -i /$1/d /var/lib/misc/dnsmasq.leases
|
sed -i /$mac/d $DHCP_LEASES
|
||||||
sed -i /"$2 "/d /var/lib/misc/dnsmasq.leases
|
sed -i /"$ip "/d $DHCP_LEASES
|
||||||
sed -i /"$3 "/d /var/lib/misc/dnsmasq.leases
|
sed -i /"$host "/d $DHCP_LEASES
|
||||||
|
|
||||||
#put in the new entry
|
#put in the new entry
|
||||||
echo "0 $1 $2 $3 *" >> /var/lib/misc/dnsmasq.leases
|
echo "0 $mac $ip $host *" >> $DHCP_LEASES
|
||||||
|
|
||||||
#edit hosts file as well
|
#edit hosts file as well
|
||||||
sed -i /"$2 "/d /etc/hosts
|
sed -i /"$ip "/d $HOSTS
|
||||||
sed -i /"$3"/d /etc/hosts
|
sed -i /"$host "/d $HOSTS
|
||||||
echo "$2 $3" >> /etc/hosts
|
echo "$ip $host" >> $HOSTS
|
||||||
|
|
||||||
|
if [ "$dflt" != "" ]
|
||||||
|
then
|
||||||
|
#make sure dnsmasq looks into options file
|
||||||
|
sed -i /dhcp-optsfile/d /etc/dnsmasq.conf
|
||||||
|
echo "dhcp-optsfile=$DHCP_OPTS" >> /etc/dnsmasq.conf
|
||||||
|
|
||||||
|
tag=$(echo $ip | tr '.' '_')
|
||||||
|
sed -i /$tag/d $DHCP_OPTS
|
||||||
|
echo "$tag,3,$dflt" >> $DHCP_OPTS
|
||||||
|
[ "$routes" != "" ] && echo "$tag,121,$routes" >> $DHCP_OPTS
|
||||||
|
#delete entry we just put in because we need a tag
|
||||||
|
sed -i /$mac/d $DHCP_HOSTS
|
||||||
|
#put it back with a tag
|
||||||
|
echo "$mac,set:$tag,$ip,$host,infinite" >>$DHCP_HOSTS
|
||||||
|
fi
|
||||||
|
|
||||||
# make dnsmasq re-read files
|
# make dnsmasq re-read files
|
||||||
pid=$(pidof dnsmasq)
|
pid=$(pidof dnsmasq)
|
||||||
|
|||||||
@ -37,7 +37,9 @@ add_dhcp_entry() {
|
|||||||
local mac=$2
|
local mac=$2
|
||||||
local ip=$3
|
local ip=$3
|
||||||
local vm=$4
|
local vm=$4
|
||||||
ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domr "/root/edithosts.sh $mac $ip $vm" >/dev/null
|
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
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,8 +47,10 @@ domrIp=
|
|||||||
vmMac=
|
vmMac=
|
||||||
vmIp=
|
vmIp=
|
||||||
vmName=
|
vmName=
|
||||||
|
staticrt=
|
||||||
|
dfltrt=
|
||||||
|
|
||||||
while getopts 'r:m:v:n:' OPTION
|
while getopts 'r:m:v:n:d:s:' OPTION
|
||||||
do
|
do
|
||||||
case $OPTION in
|
case $OPTION in
|
||||||
r) domrIp="$OPTARG"
|
r) domrIp="$OPTARG"
|
||||||
@ -57,12 +61,16 @@ do
|
|||||||
;;
|
;;
|
||||||
n) vmName="$OPTARG"
|
n) vmName="$OPTARG"
|
||||||
;;
|
;;
|
||||||
|
s) staticrt="$OPTARG"
|
||||||
|
;;
|
||||||
|
d) dfltrt="$OPTARG"
|
||||||
|
;;
|
||||||
?) usage
|
?) usage
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
add_dhcp_entry $domrIp $vmMac $vmIp $vmName
|
add_dhcp_entry $domrIp $vmMac $vmIp $vmName $dfltrt $staticrt
|
||||||
|
|
||||||
exit $?
|
exit $?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user