I've managed to get vif-route working again, but it requires some changes.
Patch is attached below (posted for sake of discussion, I don't expect
all of this to be immediately applicable).
First, I've added a new tool "sxp_get", which extract data from sxp
formatted data and presents it in a format that is usable in shell
scripts.
Also, my scripts depend on an up-to-date version of vm-tools (vm-xs in
particular), to be able to extract data from xenstored.
Signed-off-by: Michal Ostrowski <mostrows@xxxxxxxxxxxxxx>
--- a/tools/examples/backend.hotplug Wed Aug 31 23:22:45 2005
+++ b/tools/examples/backend.hotplug Thu Sep 1 22:14:10 2005
@@ -3,15 +3,37 @@
#DEVPATH=/devices/xen-backend/vif-1-0
#ACTION=add
-PATH=/etc/xen/scripts:$PATH
+export PATH=/etc/xen/scripts:$PATH
+
+CONFIG_FILE=/etc/xen/xend-config.sxp
+SCRIPT=/bin/false
+if [ -r $CONFIG_FILE ]; then
+ tmp=$(sxp_get vif-script <$CONFIG_FILE)
+ SCRIPT=${tmp#*=}
+fi
+
+if [ -z "$(which $SCRIPT)" ] ; then
+ # not in path, should probably log an error
+ exit
+fi
DEV=$(basename "$DEVPATH")
+
+# DEV is of the form vif-x-y. This extracts "x"
+idx=${DEV%-*}
+idx=${idx#*-}
+
+dom0_uuid=$(vm-xs -f /domain id 0)
+domU_uuid=$(vm-xs -f /domain/${dom0_uuid}/backend/vif 0/frontend-id $idx)
+
+domain=$(vm-xs -g /domain/$domU_uuid/id)
+
case "$ACTION" in
add)
case "$DEV" in
vif-*)
vif=$(echo "$DEV" | sed 's/-\([0-9]*\)-\([0-9]*\)/\1.\2/')
- vif-bridge up domain=unknown vif="$vif" mac=fe:ff:ff:ff:ff:ff
bridge=xen-br0 >/dev/null 2>&1
+ $SCRIPT up domain=$domain vif="$vif" mac=fe:ff:ff:ff:ff:ff
bridge=xen-br0 >/dev/null 2>&1
;;
esac
;;
diff -r f0dc15fd3c1b tools/examples/init.d/xend
--- a/tools/examples/vif-route Wed Aug 31 23:22:45 2005
+++ b/tools/examples/vif-route Thu Sep 1 22:14:10 2005
@@ -41,12 +44,28 @@
# Optional parameters. Set defaults.
ip=${ip:-''} # default to null (do nothing)
-main_ip=`ifconfig eth0 | grep "inet addr:" | sed -e 's/.*inet
addr:\(\w\w*\.\w\w*\.\w\w*\.\w\w*\).*/\1/'`
+id=$(echo -n $vif | sed -e 's/vif\(.*\)\..*/\1/')
+
+if [ -z "${ip}" ] ; then
+ # Finds "x" such that /domain/x/id == $id i.e., identifies uuid
+ uuid=$(vm-xs -f /domain id $id)
+ tmp=$(vm-xs -g /domain/$uuid/config | sxp_get.py vm device vif ip)
+ if [ "${tmp%=*}" = "vm_device_vif_ip" ] ; then
+ ip=${tmp#*=}
+ fi
+fi
+
+
+if [ -z "${netdev}" ] ; then
+ netdev=`ip route | sed -e '/default/!d' -e 's/^.*dev \(.*\)$/\1/'`
+fi
+
+main_ip=`ifconfig ${netdev} | grep "inet addr:" | sed -e 's/.*inet
addr:\(\w\w*\.\w\w*\.\w\w*\.\w\w*\).*/\1/'`
# Are we going up or down?
case $OP in
up)
- ifconfig ${vif} 169.254.1.0 netmask 255.255.255.255 up
+ ifconfig ${vif} ${main_ip} netmask 255.255.255.255 up
echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
iptcmd='-A'
ipcmd='a'
diff -r f0dc15fd3c1b tools/examples/xend-config.sxp
--- a/tools/misc/Makefile Wed Aug 31 23:22:45 2005
+++ b/tools/misc/Makefile Thu Sep 1 22:14:10 2005
@@ -15,7 +15,7 @@
TARGETS = xenperf xc_shadow
-INSTALL_BIN = $(TARGETS) xencons
+INSTALL_BIN = $(TARGETS) xencons sxp_get
INSTALL_SBIN = netfix xm xend xenperf
all: build
diff -r f0dc15fd3c1b tools/misc/sxp_get
--- /dev/null Wed Aug 31 23:22:45 2005
+++ b/tools/misc/sxp_get Thu Sep 1 22:17:24 2005
@@ -0,0 +1,98 @@
+#!/usr/bin/env python2.3
+#
+# (C) Copyright IBM Corp. 2005 Michal Ostrowski <mostrows at watson ibm com>
+#
+# 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
+import sys
+import re
+sys.path.append('/usr/lib/python')
+sys.path.append('/usr/lib64/python')
+from xen.xend import sxp
+
+def usage():
+ help = """Usage: sxp_get [key1] [key2] ....
+ Parse the sxp file from stdin and print selected key values in a format
+ that is easily handled by shell scripts.
+
+ Keys specified on the command line provide a filtering mechanism.
+ Example:
+ echo (a (b (c d) (e f)) (g h)) |sxp_get a b
+ a_b_c=d
+ a_b_e=f
+
+ echo (a (b (c d) (e f)) (g h)) |sxp_get a
+ a_b_c=d
+ a_b_e=f
+ a_g=h
+ """
+ print help;
+
+
+def __show_val(prefix1, prefix2, sxpr, match, out=sys.stdout):
+ """Print an sxpr in key1.key2.key3 = value format.
+ 'match' is a list of keys, and if non-empty will restrict
+ printing to those key prefixes that match this list.
+ """
+
+ prefix = (prefix1 + "_" + prefix2).lstrip("_")
+
+ if isinstance(sxpr, sxp.types.ListType):
+ element = sxp.name(sxpr)
+ for attr in sxp.attributes(sxpr):
+ out.write("%s_%s_%s=%s\n" % (prefix, element, attr[0], attr[1]))
+ for x in sxp.children(sxpr):
+ if len(match) > 0 :
+ item = match[0]
+ else:
+ item = element
+
+ if item == element:
+ __show_val(prefix, element, x, match[1:], out)
+ elif isinstance(sxpr, sxp.types.StringType) and sxp.atomp(sxpr):
+ out.write('%s=%s\n' % (prefix, sxpr))
+ else:
+ out.write("%s=%s\n" % (prefix,str(sxpr)))
+
+def show_val(sxpr, match, out=sys.stdout):
+ """Print an sxpr in key1.key2.key3 = value format.
+ 'match' is a list of keys, and if non-empty will restrict
+ printing to those key prefixes that match this list.
+ """
+ __show_val("", "", sxpr, match, out)
+
+
+def main(argv=sys.argv):
+ if len(argv) > 1:
+ print len(argv);
+ if re.compile('-*help').match(argv[1]):
+ usage();
+ sys.exit(0)
+
+ if len(argv) > 0:
+ match = argv[1:]
+ pin = sxp.Parser()
+ while 1:
+ buf = sys.stdin.read(1024)
+ #buf = sys.stdin.readline()
+ pin.input(buf)
+ while pin.ready():
+ val = pin.get_val()
+ show_val(val, match)
+ if len(buf) == 0:
+ break
+
+
+
+if __name__ == "__main__":
+ main()
pgpAnLQIKNSI9.pgp
Description: PGP signature
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|