bug 10804 virtual router support for per-vm default network

This commit is contained in:
Chiradeep Vittal 2011-12-01 22:59:05 -08:00 committed by Jessica Wang
parent e2743c66cd
commit 89f13ad700
4 changed files with 110 additions and 45 deletions

View File

@ -27,9 +27,12 @@ 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() {
} }
@Override @Override
@ -44,37 +47,54 @@ public class DhcpEntryCommand extends NetworkElementCommand {
} }
public DhcpEntryCommand(String vmMac, String vmIpAddress, String vmName, String dns, String gateway) { public DhcpEntryCommand(String vmMac, String vmIpAddress, String vmName, String dns, String gateway) {
this(vmMac, vmIpAddress, vmName); this(vmMac, vmIpAddress, vmName);
this.dns = dns; this.dns = dns;
this.gateway = gateway; this.gateway = gateway;
} }
public String getDns() { public String getDns() {
return dns; return dns;
} }
public String getGateway() { public String getGateway() {
return gateway; return gateway;
} }
public String getVmMac() { public String getVmMac() {
return vmMac; return vmMac;
} }
public String getVmIpAddress() { public String getVmIpAddress() {
return vmIpAddress; return vmIpAddress;
} }
public String getVmName() { public String getVmName() {
return vmName; return vmName;
} }
public void setNextServer(String ip) { public void setNextServer(String ip) {
nextServer = ip; nextServer = ip;
} }
public String getNextServer() { public String getNextServer() {
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;
}
} }

View File

@ -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");

View File

@ -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)

View File

@ -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 $?