[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Added xen-script-common.sh, for functions common to all scripts, not just the



# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID 4722eae11abb5743e4b7c66f7fb8990f5ff4b43a
# Parent  6304291cf08ba476b5e8260a21e9e702b7a327ab
Added xen-script-common.sh, for functions common to all scripts, not just the
hotplug ones.  Added evalVariables and findCommand functions to that, which we
use to clarify the handling of variables being passed in as command line
variables.

Make vif-bridge able to find the bridge for itself if only one bridge is in
use.  This means that it is not necessary to specify a bridge in many
configurations.  Allow the bridge to be specified on the command line, meaning
that a default may be provided in the xend-config.sxp if desired.

Added xenstore_read_default to xen-hotplug-common.sh, which reads from the
store but uses a given default if the path in the store is not present.  This
is used by vif-bridge to allow the store details (i.e. those given to xm create)
to override the default value given in the xend-config.sxp.

Remove vif-bridge setting -- the value can be specified on the vif-script
command line if necessary.

Added examples for network-nat/vif-nat.

Added lots of big comments.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>

diff -r 6304291cf08b -r 4722eae11abb tools/examples/Makefile
--- a/tools/examples/Makefile   Sun Oct 30 12:24:45 2005
+++ b/tools/examples/Makefile   Sun Oct 30 12:33:17 2005
@@ -25,6 +25,7 @@
 XEN_SCRIPTS += network-nat vif-nat
 XEN_SCRIPTS += block
 XEN_SCRIPTS += block-enbd block-nbd
+XEN_SCRIPTS += xen-script-common.sh
 XEN_SCRIPTS += xen-hotplug-common.sh xen-network-common.sh vif-common.sh
 XEN_SCRIPTS += block-common.sh
 
diff -r 6304291cf08b -r 4722eae11abb tools/examples/network-bridge
--- a/tools/examples/network-bridge     Sun Oct 30 12:24:45 2005
+++ b/tools/examples/network-bridge     Sun Oct 30 12:33:17 2005
@@ -42,18 +42,13 @@
 #
 #============================================================================
 
+
 dir=$(dirname "$0")
+. "$dir/xen-script-common.sh"
 . "$dir/xen-network-common.sh"
 
-# Exit if anything goes wrong.
-set -e 
-
-# First arg is the operation.
-OP=$1
-shift
-
-# Pull variables in args in to environment.
-for arg ; do export "${arg}" ; done
+findCommand "$@"
+evalVariables "$@"
 
 vifnum=${vifnum:-0}
 bridge=${bridge:-xenbr${vifnum}}
@@ -289,7 +284,7 @@
     brctl delbr ${bridge}
 }
 
-case ${OP} in
+case "$command" in
     start)
        op_start
        ;;
@@ -303,7 +298,7 @@
        ;;
 
     *)
-       echo 'Unknown command: ' ${OP} >&2
+       echo "Unknown command: $command" >&2
        echo 'Valid commands are: start, stop, status' >&2
        exit 1
 esac
diff -r 6304291cf08b -r 4722eae11abb tools/examples/vif-bridge
--- a/tools/examples/vif-bridge Sun Oct 30 12:24:45 2005
+++ b/tools/examples/vif-bridge Sun Oct 30 12:33:17 2005
@@ -16,7 +16,8 @@
 # XENBUS_PATH path to this device's details in the XenStore (required).
 #
 # Read from the store:
-# bridge  bridge to add the vif to (required).
+# bridge  bridge to add the vif to (optional).  Defaults to searching for the
+#         bridge itself.
 # ip      list of IP networks for the vif, space-separated (optional).
 #
 # up:
@@ -31,7 +32,19 @@
 dir=$(dirname "$0")
 . "$dir/vif-common.sh"
 
-bridge=$(xenstore_read "$XENBUS_PATH/bridge")
+bridge=${bridge:-}
+bridge=$(xenstore_read_default "$XENBUS_PATH/bridge" "$bridge")
+
+if [ -z "$bridge" ]
+then
+  bridge=$(brctl show | cut -d "
+" -f 2 | cut -f 1)
+
+  if [ -z "$bridge" ]
+  then
+     fatal "Could not find bridge, and none was specified"
+  fi
+fi
 
 case "$command" in
     up)
@@ -54,4 +67,4 @@
 
 handle_iptable
 
-log debug "vif-bridge operation for $vif successful."
+log debug "Successful vif-bridge operation for $vif, bridge $bridge."
diff -r 6304291cf08b -r 4722eae11abb tools/examples/vif-common.sh
--- a/tools/examples/vif-common.sh      Sun Oct 30 12:24:45 2005
+++ b/tools/examples/vif-common.sh      Sun Oct 30 12:33:17 2005
@@ -20,7 +20,7 @@
 . "$dir/xen-hotplug-common.sh"
 . "$dir/xen-network-common.sh"
 
-command="$1"
+findCommand "$@"
 
 if [ "$command" != "up" ] && [ "$command" != "down" ]
 then
@@ -29,10 +29,19 @@
 fi
 
 
+# Parameters may be read from the environment, the command line arguments, and
+# the store, with overriding in that order.  The environment is given by the
+# driver, the command line is given by the Xend global configuration, and
+# store details are given by the per-domain or per-device configuration.
+
+evalVariables "$@"
+
+ip=${ip:-}
+ip=$(xenstore_read_default "$XENBUS_PATH/ip" "$ip")
+
+# Check presence of compulsory args.
 XENBUS_PATH="${XENBUS_PATH:?}"
 vif="${vif:?}"
-
-ip=$(xenstore-read "$XENBUS_PATH/ip" >&/dev/null || true)
 
 
 function frob_iptable()
diff -r 6304291cf08b -r 4722eae11abb tools/examples/xen-hotplug-common.sh
--- a/tools/examples/xen-hotplug-common.sh      Sun Oct 30 12:24:45 2005
+++ b/tools/examples/xen-hotplug-common.sh      Sun Oct 30 12:33:17 2005
@@ -16,7 +16,8 @@
 #
 
 
-set -e
+dir=$(dirname "$0")
+. "$dir/xen-script-common.sh"
 
 export PATH="/sbin:/bin:/usr/bin:/usr/sbin:$PATH"
 export LANG="POSIX"
@@ -33,15 +34,39 @@
   exit 1
 }
 
+##
+# xenstore_read <path>+
+#
+# Read each of the given paths, returning each result on a separate line, or
+# exit this script if any of the paths is missing.
+#
 xenstore_read() {
   local v=$(xenstore-read "$@" || true)
   [ "$v" != "" ] || fatal "xenstore-read $@ failed."
   echo "$v"
 }
 
+
+##
+# xenstore_read_default <path> <default>
+#
+# Read the given path, returning the value there or the given default if the
+# path is not present.
+#
+xenstore_read_default() {
+  xenstore-read "$1" || echo "$2"
+}
+
+
+##
+# xenstore_write (<path> <value>)+
+#
+# Write each of the key/value pairs to the store, and exit this script if any
+# such writing fails.
+#
 xenstore_write() {
   log debug "Writing $@ to xenstore."
-  xenstore-write "$@" || log err "Writing $@ to xenstore failed."
+  xenstore-write "$@" || fatal "Writing $@ to xenstore failed."
 }
 
 log debug "$@" "XENBUS_PATH=$XENBUS_PATH"
diff -r 6304291cf08b -r 4722eae11abb tools/examples/xend-config.sxp
--- a/tools/examples/xend-config.sxp    Sun Oct 30 12:24:45 2005
+++ b/tools/examples/xend-config.sxp    Sun Oct 30 12:33:17 2005
@@ -48,19 +48,62 @@
 # The limit (in kilobytes) on the size of the console buffer
 #(console-limit 1024)
 
-## Use the following if VIF traffic is routed.
-# The script used to start/stop networking for xend.
-#(network-script     network-route)
-# The default script used to control virtual interfaces.
-#(vif-script         vif-route)
+##
+# To bridge network traffic, like this:
+#
+# dom0: fake eth0 -> vif0.0 -+
+#                            |
+#                          bridge -> real eth0 -> the network
+#                            |
+# domU: fake eth0 -> vifN.0 -+
+#
+# use
+#
+# (network-script network-bridge)
+#
+# Your eth0 is used as the outgoing interface, by default.  To use a different
+# one (e.g. eth1) use
+#
+# (network-script 'network-bridge netdev=eth1')
+#
+# The bridge is named xenbr0, by default.  To rename the bridge, use
+#
+# (network-script 'network-bridge bridge=<name>')
+#
+# It is possible to use the network-bridge script in more complicated
+# scenarios, such as having two outgoing interfaces, with two bridges, and
+# two fake interfaces per guest domain.  To do things like this, write
+# yourself a wrapper script, and call network-bridge from it, as appropriate.
+#
+(network-script network-bridge)
 
-## Use the following if VIF traffic is bridged.
-# The script used to start/stop networking for xend.
-(network-script    network-bridge)
-# The default bridge that virtual interfaces should be connected to.
-(vif-bridge        xenbr0)
-# The default script used to control virtual interfaces.
-(vif-script        vif-bridge)
+# The script used to control virtual interfaces.  This can be overridden on a
+# per-vif basis when creating a domain or a configuring a new vif.  The
+# vif-bridge script is designed for use with the network-bridge script, or
+# similar configurations.
+#
+# If you have overridden the bridge name using
+# (network-script 'network-bridge bridge=<name>') then you may wish to do the
+# same here.  The bridge name can also be set when creating a domain or
+# configuring a new vif, but a value specified here would act as a default.
+#
+# If you are using only one bridge, the vif-bridge script will discover that,
+# so there is no need to specify it explicitly.
+#
+(vif-script vif-bridge)
+
+
+## Use the following if network traffic is routed, as an alternative to the
+# settings for bridged networking given above.
+#(network-script network-route)
+#(vif-script     vif-route)
+
+
+## Use the following if network traffic is routed with NAT, as an alternative
+# to the settings for bridged networking given above.
+#(network-script network-nat)
+#(vif-script     vif-nat)
+
 
 # Dom0 will balloon out when needed to free memory for domU.
 # dom0-min-mem is the lowest memory level (in MB) dom0 will get down to.
diff -r 6304291cf08b -r 4722eae11abb tools/examples/xen-script-common.sh
--- /dev/null   Sun Oct 30 12:24:45 2005
+++ b/tools/examples/xen-script-common.sh       Sun Oct 30 12:33:17 2005
@@ -0,0 +1,44 @@
+#
+# Copyright (c) 2005 XenSource Ltd.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+
+
+set -e
+
+
+evalVariables()
+{
+  for arg in "$@"
+  do
+    if expr 'index' "$arg" '=' '>' '1' >/dev/null
+    then
+      eval "$arg"
+    fi
+  done
+}
+
+
+findCommand()
+{
+  for arg in "$@"
+  do
+    if ! expr 'index' "$arg" '=' >/dev/null
+    then
+      command="$arg"
+      return
+    fi
+  done
+}

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.