Skip to content

Commit 9300a02

Browse files
author
Sheng Yang
committed
IPv6: Update edithosts.sh accept parameters
1 parent 6169c1d commit 9300a02

3 files changed

Lines changed: 76 additions & 55 deletions

File tree

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

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,37 @@
2626
# $5 : nameserver on default nic
2727
# $6 : comma separated static routes
2828

29-
mac=$1
30-
ip=$2
31-
host=$3
32-
dflt=$4
33-
dns=$5
34-
routes=$6
29+
usage() {
30+
printf "Usage: %s: -m <MAC address> -4 <IPv4 address> -h <hostname> -d <default router> -n <name server address> -s <Routes> \n" $(basename $0) >&2
31+
}
32+
33+
mac=
34+
ipv4=
35+
host=
36+
dflt=
37+
dns=
38+
routes=
39+
40+
while getopts 'm:4:h:d:n:s:' OPTION
41+
do
42+
case $OPTION in
43+
m) mac="$OPTARG"
44+
;;
45+
4) ipv4="$OPTARG"
46+
;;
47+
h) host="$OPTARG"
48+
;;
49+
d) dflt="$OPTARG"
50+
;;
51+
n) dns="$OPTARG"
52+
;;
53+
s) routes="$OPTARG"
54+
;;
55+
?) usage
56+
exit 2
57+
;;
58+
esac
59+
done
3560

3661
DHCP_HOSTS=/etc/dhcphosts.txt
3762
DHCP_OPTS=/etc/dhcpopts.txt
@@ -71,52 +96,52 @@ logger -t cloud "edithosts: update $1 $2 $3 to hosts"
7196

7297
#delete any previous entries from the dhcp hosts file
7398
sed -i /$mac/d $DHCP_HOSTS
74-
sed -i /$ip,/d $DHCP_HOSTS
99+
sed -i /$ipv4,/d $DHCP_HOSTS
75100
sed -i /$host,/d $DHCP_HOSTS
76101

77102

78103
#put in the new entry
79-
echo "$mac,$ip,$host,infinite" >>$DHCP_HOSTS
104+
echo "$mac,$ipv4,$host,infinite" >>$DHCP_HOSTS
80105

81106
#delete leases to supplied mac and ip addresses
82107
sed -i /$mac/d $DHCP_LEASES
83-
sed -i /"$ip "/d $DHCP_LEASES
108+
sed -i /"$ipv4 "/d $DHCP_LEASES
84109
sed -i /"$host "/d $DHCP_LEASES
85110

86111
#put in the new entry
87-
echo "0 $mac $ip $host *" >> $DHCP_LEASES
112+
echo "0 $mac $ipv4 $host *" >> $DHCP_LEASES
88113

89114
#edit hosts file as well
90-
sed -i /"$ip "/d $HOSTS
115+
sed -i /"$ipv4 "/d $HOSTS
91116
sed -i /" $host$"/d $HOSTS
92-
echo "$ip $host" >> $HOSTS
117+
echo "$ipv4 $host" >> $HOSTS
93118

94119
if [ "$dflt" != "" ]
95120
then
96121
#make sure dnsmasq looks into options file
97122
sed -i /dhcp-optsfile/d /etc/dnsmasq.conf
98123
echo "dhcp-optsfile=$DHCP_OPTS" >> /etc/dnsmasq.conf
99124

100-
tag=$(echo $ip | tr '.' '_')
125+
tag=$(echo $ipv4 | tr '.' '_')
101126
sed -i /$tag/d $DHCP_OPTS
102127
if [ "$dflt" != "0.0.0.0" ]
103128
then
104-
logger -t cloud "$0: setting default router for $ip to $dflt"
129+
logger -t cloud "$0: setting default router for $ipv4 to $dflt"
105130
echo "$tag,3,$dflt" >> $DHCP_OPTS
106131
else
107-
logger -t cloud "$0: unset default router for $ip"
132+
logger -t cloud "$0: unset default router for $ipv4"
108133
echo "$tag,3," >> $DHCP_OPTS
109134
fi
110135
if [ "$dns" != "" ]
111136
then
112-
logger -t cloud "$0: setting dns server for $ip to $dns"
137+
logger -t cloud "$0: setting dns server for $ipv4 to $dns"
113138
echo "$tag,6,$dns" >> $DHCP_OPTS
114139
fi
115140
[ "$routes" != "" ] && echo "$tag,121,$routes" >> $DHCP_OPTS
116141
#delete entry we just put in because we need a tag
117-
sed -i /$mac/d $DHCP_HOSTS
142+
sed -i /$ipv4/d $DHCP_HOSTS
118143
#put it back with a tag
119-
echo "$mac,set:$tag,$ip,$host,infinite" >>$DHCP_HOSTS
144+
echo "$mac,set:$tag,$ipv4,$host,infinite" >>$DHCP_HOSTS
120145
fi
121146

122147
# make dnsmasq re-read files

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,20 +1629,20 @@ protected Answer execute(DhcpEntryCommand cmd) {
16291629
}
16301630

16311631
// ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domr "/root/edithosts.sh $mac $ip $vm $dfltrt $ns $staticrt" >/dev/null
1632-
String args = " " + cmd.getVmMac();
1633-
args += " " + cmd.getVmIpAddress();
1634-
args += " " + cmd.getVmName();
1632+
String args = " -m " + cmd.getVmMac();
1633+
args += " -4 " + cmd.getVmIpAddress();
1634+
args += " -h " + cmd.getVmName();
16351635

16361636
if (cmd.getDefaultRouter() != null) {
1637-
args += " " + cmd.getDefaultRouter();
1637+
args += " -d " + cmd.getDefaultRouter();
16381638
}
16391639

16401640
if (cmd.getDefaultDns() != null) {
1641-
args += " " + cmd.getDefaultDns();
1641+
args += " -n " + cmd.getDefaultDns();
16421642
}
16431643

16441644
if (cmd.getStaticRoutes() != null) {
1645-
args += " " + cmd.getStaticRoutes();
1645+
args += " -s " + cmd.getStaticRoutes();
16461646
}
16471647

16481648
if (s_logger.isDebugEnabled()) {

scripts/network/domr/dhcp_entry.sh

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,12 @@
2222
# @VERSION@
2323

2424
usage() {
25-
printf "Usage: %s: -r <domr-ip> -m <vm mac> -v <vm ip> -n <vm name>\n" $(basename $0) >&2
25+
printf "Usage: %s: -r <domr-ip> -m <vm mac> -v <vm ip> -n <vm name> -s <static route> -d <default router> -N <dns>\n" $(basename $0) >&2
2626
exit 2
2727
}
2828

2929
cert="/root/.ssh/id_rsa.cloud"
3030

31-
add_dhcp_entry() {
32-
local domr=$1
33-
local mac=$2
34-
local ip=$3
35-
local vm=$4
36-
local dfltrt=$5
37-
local ns=$6
38-
local staticrt=$7
39-
ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domr "/root/edithosts.sh $mac $ip $vm $dfltrt $ns $staticrt" >/dev/null
40-
return $?
41-
}
42-
4331
domrIp=
4432
vmMac=
4533
vmIp=
@@ -48,29 +36,37 @@ staticrt=
4836
dfltrt=
4937
dns=
5038

39+
opts=
40+
5141
while getopts 'r:m:v:n:d:s:N:' OPTION
5242
do
5343
case $OPTION in
54-
r) domrIp="$OPTARG"
55-
;;
56-
v) vmIp="$OPTARG"
57-
;;
58-
m) vmMac="$OPTARG"
59-
;;
60-
n) vmName="$OPTARG"
61-
;;
62-
s) staticrt="$OPTARG"
63-
;;
64-
d) dfltrt="$OPTARG"
65-
;;
66-
N) dns="$OPTARG"
67-
;;
68-
?) usage
69-
exit 1
70-
;;
44+
r) domrIp="$OPTARG"
45+
;;
46+
v) vmIp="$OPTARG"
47+
opts="$opts -4 $vmIp"
48+
;;
49+
m) vmMac="$OPTARG"
50+
opts="$opts -m $vmMac"
51+
;;
52+
n) vmName="$OPTARG"
53+
opts="$opts -h $vmName"
54+
;;
55+
s) staticrt="$OPTARG"
56+
opts="$opts -s $staticrt"
57+
;;
58+
d) dfltrt="$OPTARG"
59+
opts="$opts -d $dfltrt"
60+
;;
61+
N) dns="$OPTARG"
62+
opts="$opts -n $dns"
63+
;;
64+
?) usage
65+
exit 1
66+
;;
7167
esac
7268
done
7369

74-
add_dhcp_entry $domrIp $vmMac $vmIp $vmName $dfltrt $dns $staticrt
70+
ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domrIp "/root/edithosts.sh $opts " >/dev/null
7571

7672
exit $?

0 commit comments

Comments
 (0)