You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ki...@apache.org on 2013/02/01 07:11:34 UTC

[4/48] git commit: refs/heads/regions - IPv6: Update edithosts.sh accept parameters

IPv6: Update edithosts.sh accept parameters


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/9300a02b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/9300a02b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/9300a02b

Branch: refs/heads/regions
Commit: 9300a02ba4ec8f926f4f579bc1d4b2d4e4475062
Parents: 6169c1d
Author: Sheng Yang <sh...@citrix.com>
Authored: Thu Jan 24 20:09:37 2013 -0800
Committer: Sheng Yang <sh...@citrix.com>
Committed: Sat Jan 26 23:14:27 2013 -0800

----------------------------------------------------------------------
 patches/systemvm/debian/config/root/edithosts.sh   |   61 ++++++++++----
 .../hypervisor/vmware/resource/VmwareResource.java |   12 ++--
 scripts/network/domr/dhcp_entry.sh                 |   58 +++++++--------
 3 files changed, 76 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9300a02b/patches/systemvm/debian/config/root/edithosts.sh
----------------------------------------------------------------------
diff --git a/patches/systemvm/debian/config/root/edithosts.sh b/patches/systemvm/debian/config/root/edithosts.sh
index 37c75a5..acc421b 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 <MAC address> -4 <IPv4 address>  -h <hostname> -d <default router> -n <name server address> -s <Routes> \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

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9300a02b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
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 dd917f7..0ca25a8 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()) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9300a02b/scripts/network/domr/dhcp_entry.sh
----------------------------------------------------------------------
diff --git a/scripts/network/domr/dhcp_entry.sh b/scripts/network/domr/dhcp_entry.sh
index c1bf354..b964eb4 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 <domr-ip> -m <vm mac> -v <vm ip> -n <vm name>\n" $(basename $0) >&2
+  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
   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 $?