diff --git a/patches/systemvm/debian/config/root/edithosts.sh b/patches/systemvm/debian/config/root/edithosts.sh index 37c75a53022..acc421b8a67 100755 --- a/patches/systemvm/debian/config/root/edithosts.sh +++ b/patches/systemvm/debian/config/root/edithosts.sh @@ -26,12 +26,37 @@ # $5 : nameserver on default nic # $6 : comma separated static routes -mac=$1 -ip=$2 -host=$3 -dflt=$4 -dns=$5 -routes=$6 +usage() { + printf "Usage: %s: -m -4 -h -d -n -s \n" $(basename $0) >&2 +} + +mac= +ipv4= +host= +dflt= +dns= +routes= + +while getopts 'm:4:h:d:n:s:' OPTION +do + case $OPTION in + m) mac="$OPTARG" + ;; + 4) ipv4="$OPTARG" + ;; + h) host="$OPTARG" + ;; + d) dflt="$OPTARG" + ;; + n) dns="$OPTARG" + ;; + s) routes="$OPTARG" + ;; + ?) usage + exit 2 + ;; + esac +done DHCP_HOSTS=/etc/dhcphosts.txt DHCP_OPTS=/etc/dhcpopts.txt @@ -71,25 +96,25 @@ logger -t cloud "edithosts: update $1 $2 $3 to hosts" #delete any previous entries from the dhcp hosts file sed -i /$mac/d $DHCP_HOSTS -sed -i /$ip,/d $DHCP_HOSTS +sed -i /$ipv4,/d $DHCP_HOSTS sed -i /$host,/d $DHCP_HOSTS #put in the new entry -echo "$mac,$ip,$host,infinite" >>$DHCP_HOSTS +echo "$mac,$ipv4,$host,infinite" >>$DHCP_HOSTS #delete leases to supplied mac and ip addresses sed -i /$mac/d $DHCP_LEASES -sed -i /"$ip "/d $DHCP_LEASES +sed -i /"$ipv4 "/d $DHCP_LEASES sed -i /"$host "/d $DHCP_LEASES #put in the new entry -echo "0 $mac $ip $host *" >> $DHCP_LEASES +echo "0 $mac $ipv4 $host *" >> $DHCP_LEASES #edit hosts file as well -sed -i /"$ip "/d $HOSTS +sed -i /"$ipv4 "/d $HOSTS sed -i /" $host$"/d $HOSTS -echo "$ip $host" >> $HOSTS +echo "$ipv4 $host" >> $HOSTS if [ "$dflt" != "" ] then @@ -97,26 +122,26 @@ then sed -i /dhcp-optsfile/d /etc/dnsmasq.conf echo "dhcp-optsfile=$DHCP_OPTS" >> /etc/dnsmasq.conf - tag=$(echo $ip | tr '.' '_') + tag=$(echo $ipv4 | tr '.' '_') sed -i /$tag/d $DHCP_OPTS if [ "$dflt" != "0.0.0.0" ] then - logger -t cloud "$0: setting default router for $ip to $dflt" + logger -t cloud "$0: setting default router for $ipv4 to $dflt" echo "$tag,3,$dflt" >> $DHCP_OPTS else - logger -t cloud "$0: unset default router for $ip" + logger -t cloud "$0: unset default router for $ipv4" echo "$tag,3," >> $DHCP_OPTS fi if [ "$dns" != "" ] then - logger -t cloud "$0: setting dns server for $ip to $dns" + logger -t cloud "$0: setting dns server for $ipv4 to $dns" echo "$tag,6,$dns" >> $DHCP_OPTS fi [ "$routes" != "" ] && echo "$tag,121,$routes" >> $DHCP_OPTS #delete entry we just put in because we need a tag - sed -i /$mac/d $DHCP_HOSTS + sed -i /$ipv4/d $DHCP_HOSTS #put it back with a tag - echo "$mac,set:$tag,$ip,$host,infinite" >>$DHCP_HOSTS + echo "$mac,set:$tag,$ipv4,$host,infinite" >>$DHCP_HOSTS fi # make dnsmasq re-read files diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index dd917f75a6e..0ca25a888af 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -1629,20 +1629,20 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa } // ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domr "/root/edithosts.sh $mac $ip $vm $dfltrt $ns $staticrt" >/dev/null - String args = " " + cmd.getVmMac(); - args += " " + cmd.getVmIpAddress(); - args += " " + cmd.getVmName(); + String args = " -m " + cmd.getVmMac(); + args += " -4 " + cmd.getVmIpAddress(); + args += " -h " + cmd.getVmName(); if (cmd.getDefaultRouter() != null) { - args += " " + cmd.getDefaultRouter(); + args += " -d " + cmd.getDefaultRouter(); } if (cmd.getDefaultDns() != null) { - args += " " + cmd.getDefaultDns(); + args += " -n " + cmd.getDefaultDns(); } if (cmd.getStaticRoutes() != null) { - args += " " + cmd.getStaticRoutes(); + args += " -s " + cmd.getStaticRoutes(); } if (s_logger.isDebugEnabled()) { diff --git a/scripts/network/domr/dhcp_entry.sh b/scripts/network/domr/dhcp_entry.sh index c1bf3543dfb..b964eb4c292 100755 --- a/scripts/network/domr/dhcp_entry.sh +++ b/scripts/network/domr/dhcp_entry.sh @@ -22,24 +22,12 @@ # @VERSION@ usage() { - printf "Usage: %s: -r -m -v -n \n" $(basename $0) >&2 + printf "Usage: %s: -r -m -v -n -s -d -N \n" $(basename $0) >&2 exit 2 } cert="/root/.ssh/id_rsa.cloud" -add_dhcp_entry() { - local domr=$1 - local mac=$2 - local ip=$3 - local vm=$4 - local dfltrt=$5 - local ns=$6 - local staticrt=$7 - ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domr "/root/edithosts.sh $mac $ip $vm $dfltrt $ns $staticrt" >/dev/null - return $? -} - domrIp= vmMac= vmIp= @@ -48,29 +36,37 @@ staticrt= dfltrt= dns= +opts= + while getopts 'r:m:v:n:d:s:N:' OPTION do case $OPTION in - r) domrIp="$OPTARG" - ;; - v) vmIp="$OPTARG" - ;; - m) vmMac="$OPTARG" - ;; - n) vmName="$OPTARG" - ;; - s) staticrt="$OPTARG" - ;; - d) dfltrt="$OPTARG" - ;; - N) dns="$OPTARG" - ;; - ?) usage - exit 1 - ;; + r) domrIp="$OPTARG" + ;; + v) vmIp="$OPTARG" + opts="$opts -4 $vmIp" + ;; + m) vmMac="$OPTARG" + opts="$opts -m $vmMac" + ;; + n) vmName="$OPTARG" + opts="$opts -h $vmName" + ;; + s) staticrt="$OPTARG" + opts="$opts -s $staticrt" + ;; + d) dfltrt="$OPTARG" + opts="$opts -d $dfltrt" + ;; + N) dns="$OPTARG" + opts="$opts -n $dns" + ;; + ?) usage + exit 1 + ;; esac done -add_dhcp_entry $domrIp $vmMac $vmIp $vmName $dfltrt $dns $staticrt +ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domrIp "/root/edithosts.sh $opts " >/dev/null exit $?