Skip to content

Commit 89f13ad

Browse files
Chiradeep VittalJessica Wang
authored andcommitted
bug 10804 virtual router support for per-vm default network
1 parent e2743c6 commit 89f13ad

4 files changed

Lines changed: 110 additions & 45 deletions

File tree

api/src/com/cloud/agent/api/routing/DhcpEntryCommand.java

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ public class DhcpEntryCommand extends NetworkElementCommand {
2727
String dns;
2828
String gateway;
2929
String nextServer;
30+
String defaultRouter;
31+
String staticRoutes;
32+
3033

3134
protected DhcpEntryCommand() {
32-
35+
3336
}
3437

3538
@Override
@@ -44,37 +47,54 @@ public DhcpEntryCommand(String vmMac, String vmIpAddress, String vmName) {
4447
}
4548

4649
public DhcpEntryCommand(String vmMac, String vmIpAddress, String vmName, String dns, String gateway) {
47-
this(vmMac, vmIpAddress, vmName);
48-
this.dns = dns;
49-
this.gateway = gateway;
50+
this(vmMac, vmIpAddress, vmName);
51+
this.dns = dns;
52+
this.gateway = gateway;
5053
}
5154

5255
public String getDns() {
53-
return dns;
56+
return dns;
5457
}
5558

5659
public String getGateway() {
57-
return gateway;
60+
return gateway;
61+
}
62+
63+
public String getVmMac() {
64+
return vmMac;
65+
}
66+
67+
public String getVmIpAddress() {
68+
return vmIpAddress;
69+
}
70+
71+
public String getVmName() {
72+
return vmName;
73+
}
74+
75+
public void setNextServer(String ip) {
76+
nextServer = ip;
77+
}
78+
79+
public String getNextServer() {
80+
return nextServer;
81+
}
82+
83+
public String getDefaultRouter() {
84+
return defaultRouter;
85+
}
86+
87+
public void setDefaultRouter(String defaultRouter) {
88+
this.defaultRouter = defaultRouter;
5889
}
90+
91+
public String getStaticRoutes() {
92+
return staticRoutes;
93+
}
94+
95+
public void setStaticRoutes(String staticRoutes) {
96+
this.staticRoutes = staticRoutes;
97+
}
98+
5999

60-
public String getVmMac() {
61-
return vmMac;
62-
}
63-
64-
public String getVmIpAddress() {
65-
return vmIpAddress;
66-
}
67-
68-
public String getVmName() {
69-
return vmName;
70-
}
71-
72-
public void setNextServer(String ip) {
73-
nextServer = ip;
74-
}
75-
76-
public String getNextServer() {
77-
return nextServer;
78-
}
79-
80100
}

core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,12 @@ protected synchronized Answer execute(final DhcpEntryCommand cmd) {
14361436
args += " -v " + cmd.getVmIpAddress();
14371437
args += " -m " + cmd.getVmMac();
14381438
args += " -n " + cmd.getVmName();
1439+
if (cmd.getDefaultRouter() != null) {
1440+
args += " -d " + cmd.getDefaultRouter();
1441+
}
1442+
if (cmd.getStaticRoutes() != null) {
1443+
args += " -s " + cmd.getStaticRoutes();
1444+
}
14391445
String result = callHostPlugin(conn, "vmops", "saveDhcpEntry", "args", args);
14401446
if (result == null || result.isEmpty()) {
14411447
return new Answer(cmd, false, "DhcpEntry failed");

patches/systemvm/debian/config/root/edithosts.sh

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,22 @@
2020
#
2121

2222
# edithosts.sh -- edit the dhcphosts file on the routing domain
23-
# $1 : the mac address
24-
# $2 : the associated ip address
25-
# $3 : the hostname
23+
# $mac : the mac address
24+
# $ip : the associated ip address
25+
# $host : the hostname
26+
# $4 : default router
27+
# $5 : comma separated static routes
28+
29+
mac=$1
30+
ip=$2
31+
host=$3
32+
dflt=$4
33+
routes=$5
34+
35+
DHCP_HOSTS=/etc/dhcphosts.txt
36+
DHCP_OPTS=/etc/dhcpopts.txt
37+
DHCP_LEASES=/var/lib/misc/dnsmasq.leases
38+
HOSTS=/etc/hosts
2639

2740
source /root/func.sh
2841

@@ -58,29 +71,47 @@ wait_for_dnsmasq () {
5871

5972
logger -t cloud "edithosts: update $1 $2 $3 to hosts"
6073

61-
[ ! -f /etc/dhcphosts.txt ] && touch /etc/dhcphosts.txt
62-
[ ! -f /var/lib/misc/dnsmasq.leases ] && touch /var/lib/misc/dnsmasq.leases
74+
[ ! -f $DHCP_HOSTS ] && touch $DHCP_HOSTS
75+
[ ! -f $DHCP_OPTS ] && touch $DHCP_OPTS
76+
[ ! -f $DHCP_LEASES ] && touch $DHCP_LEASES
6377

6478
#delete any previous entries from the dhcp hosts file
65-
sed -i /$1/d /etc/dhcphosts.txt
66-
sed -i /$2,/d /etc/dhcphosts.txt
67-
sed -i /$3,/d /etc/dhcphosts.txt
79+
sed -i /$mac/d $DHCP_HOSTS
80+
sed -i /$ip,/d $DHCP_HOSTS
81+
sed -i /$host,/d $DHCP_HOSTS
82+
6883

6984
#put in the new entry
70-
echo "$1,$2,$3,infinite" >>/etc/dhcphosts.txt
85+
echo "$mac,$ip,$host,infinite" >>$DHCP_HOSTS
7186

7287
#delete leases to supplied mac and ip addresses
73-
sed -i /$1/d /var/lib/misc/dnsmasq.leases
74-
sed -i /"$2 "/d /var/lib/misc/dnsmasq.leases
75-
sed -i /"$3 "/d /var/lib/misc/dnsmasq.leases
88+
sed -i /$mac/d $DHCP_LEASES
89+
sed -i /"$ip "/d $DHCP_LEASES
90+
sed -i /"$host "/d $DHCP_LEASES
7691

7792
#put in the new entry
78-
echo "0 $1 $2 $3 *" >> /var/lib/misc/dnsmasq.leases
93+
echo "0 $mac $ip $host *" >> $DHCP_LEASES
7994

8095
#edit hosts file as well
81-
sed -i /"$2 "/d /etc/hosts
82-
sed -i /"$3"/d /etc/hosts
83-
echo "$2 $3" >> /etc/hosts
96+
sed -i /"$ip "/d $HOSTS
97+
sed -i /"$host "/d $HOSTS
98+
echo "$ip $host" >> $HOSTS
99+
100+
if [ "$dflt" != "" ]
101+
then
102+
#make sure dnsmasq looks into options file
103+
sed -i /dhcp-optsfile/d /etc/dnsmasq.conf
104+
echo "dhcp-optsfile=$DHCP_OPTS" >> /etc/dnsmasq.conf
105+
106+
tag=$(echo $ip | tr '.' '_')
107+
sed -i /$tag/d $DHCP_OPTS
108+
echo "$tag,3,$dflt" >> $DHCP_OPTS
109+
[ "$routes" != "" ] && echo "$tag,121,$routes" >> $DHCP_OPTS
110+
#delete entry we just put in because we need a tag
111+
sed -i /$mac/d $DHCP_HOSTS
112+
#put it back with a tag
113+
echo "$mac,set:$tag,$ip,$host,infinite" >>$DHCP_HOSTS
114+
fi
84115

85116
# make dnsmasq re-read files
86117
pid=$(pidof dnsmasq)

scripts/network/domr/dhcp_entry.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,20 @@ add_dhcp_entry() {
3737
local mac=$2
3838
local ip=$3
3939
local vm=$4
40-
ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domr "/root/edithosts.sh $mac $ip $vm" >/dev/null
40+
local dfltrt=$5
41+
local staticrt=$6
42+
ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domr "/root/edithosts.sh $mac $ip $vm $dfltrt $staticrt" >/dev/null
4143
return $?
4244
}
4345

4446
domrIp=
4547
vmMac=
4648
vmIp=
4749
vmName=
50+
staticrt=
51+
dfltrt=
4852

49-
while getopts 'r:m:v:n:' OPTION
53+
while getopts 'r:m:v:n:d:s:' OPTION
5054
do
5155
case $OPTION in
5256
r) domrIp="$OPTARG"
@@ -57,12 +61,16 @@ do
5761
;;
5862
n) vmName="$OPTARG"
5963
;;
64+
s) staticrt="$OPTARG"
65+
;;
66+
d) dfltrt="$OPTARG"
67+
;;
6068
?) usage
6169
exit 1
6270
;;
6371
esac
6472
done
6573

66-
add_dhcp_entry $domrIp $vmMac $vmIp $vmName
74+
add_dhcp_entry $domrIp $vmMac $vmIp $vmName $dfltrt $staticrt
6775

6876
exit $?

0 commit comments

Comments
 (0)