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 gateway;
String nextServer;
String defaultRouter;
String staticRoutes;
protected DhcpEntryCommand() {
}
@Override
@ -44,37 +47,54 @@ public class DhcpEntryCommand extends NetworkElementCommand {
}
public DhcpEntryCommand(String vmMac, String vmIpAddress, String vmName, String dns, String gateway) {
this(vmMac, vmIpAddress, vmName);
this.dns = dns;
this.gateway = gateway;
this(vmMac, vmIpAddress, vmName);
this.dns = dns;
this.gateway = gateway;
}
public String getDns() {
return dns;
return dns;
}
public String getGateway() {
return gateway;
return gateway;
}
public String getVmMac() {
return vmMac;
}
public String getVmIpAddress() {
return vmIpAddress;
}
public String getVmName() {
return vmName;
}
public void setNextServer(String ip) {
nextServer = ip;
}
public String getNextServer() {
return nextServer;
}
public String getVmMac() {
return vmMac;
}
public String getVmIpAddress() {
return vmIpAddress;
}
public String getVmName() {
return vmName;
}
public void setNextServer(String ip) {
nextServer = ip;
}
public String getNextServer() {
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 += " -m " + cmd.getVmMac();
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);
if (result == null || result.isEmpty()) {
return new Answer(cmd, false, "DhcpEntry failed");

View File

@ -20,9 +20,22 @@
#
# edithosts.sh -- edit the dhcphosts file on the routing domain
# $1 : the mac address
# $2 : the associated ip address
# $3 : the hostname
# $mac : the mac address
# $ip : the associated ip address
# $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
@ -58,29 +71,47 @@ wait_for_dnsmasq () {
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
[ ! -f $DHCP_HOSTS ] && touch $DHCP_HOSTS
[ ! -f $DHCP_OPTS ] && touch $DHCP_OPTS
[ ! -f $DHCP_LEASES ] && touch $DHCP_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
sed -i /$mac/d $DHCP_HOSTS
sed -i /$ip,/d $DHCP_HOSTS
sed -i /$host,/d $DHCP_HOSTS
#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
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
sed -i /$mac/d $DHCP_LEASES
sed -i /"$ip "/d $DHCP_LEASES
sed -i /"$host "/d $DHCP_LEASES
#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
sed -i /"$2 "/d /etc/hosts
sed -i /"$3"/d /etc/hosts
echo "$2 $3" >> /etc/hosts
sed -i /"$ip "/d $HOSTS
sed -i /"$host "/d $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
pid=$(pidof dnsmasq)

View File

@ -37,7 +37,9 @@ add_dhcp_entry() {
local mac=$2
local ip=$3
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 $?
}
@ -45,8 +47,10 @@ domrIp=
vmMac=
vmIp=
vmName=
staticrt=
dfltrt=
while getopts 'r:m:v:n:' OPTION
while getopts 'r:m:v:n:d:s:' OPTION
do
case $OPTION in
r) domrIp="$OPTARG"
@ -57,12 +61,16 @@ do
;;
n) vmName="$OPTARG"
;;
s) staticrt="$OPTARG"
;;
d) dfltrt="$OPTARG"
;;
?) usage
exit 1
;;
esac
done
add_dhcp_entry $domrIp $vmMac $vmIp $vmName
add_dhcp_entry $domrIp $vmMac $vmIp $vmName $dfltrt $staticrt
exit $?