[Ovirt-devel] [PATCH] ovirt-mod-xml.sh: more robust; update from ovirt-web--devel
Jim Meyering
meyering at redhat.com
Fri Apr 4 12:31:27 UTC 2008
I noticed today that ovirt-mod-xml.sh is in ovirt.git.
Now that there's an improved version in the web repo (ovirt-web--devel),
I've just updated this version to match:
ovirt-mod-xml.sh: more robust; update from ovirt-web--devel
* wui-appliance/ovirt-mod-xml.sh: Exit nonzero for any failure.
Now, running multiple times does not insert multiple <interface> blocks.
More reliable clean-up.
diff --git a/wui-appliance/ovirt-mod-xml.sh b/wui-appliance/ovirt-mod-xml.sh
index 5cd385e..cc8bb82 100755
--- a/wui-appliance/ovirt-mod-xml.sh
+++ b/wui-appliance/ovirt-mod-xml.sh
@@ -1,14 +1,26 @@
#!/bin/bash
-TMPFILE=`mktemp`
+# Remove the temporary file on exit or signal.
+trap 'st=$?; rm -rf "$tmpfile" && exit $st' 0
+trap 'exit $?' 1 2 13 15
-virsh -c qemu:///system dumpxml developer > $TMPFILE &&
+tmpfile=`mktemp` || exit 1
-perl -ni -e '$m = m!</interface>!; print; $m and print ' \
- -e 'qq( <interface type="bridge">\n) .' \
- -e 'qq( <mac address="00:16:3e:12:34:56"/>\n) .' \
- -e 'qq( <source bridge="dummybridge"/>\n) .' \
- -e 'qq( </interface>\n)' $TMPFILE &&
+virsh -c qemu:///system dumpxml developer > "$tmpfile" || exit 1
-virsh -c qemu:///system define $TMPFILE
-rm -f $TMPFILE
+mac=00:16:3e:12:34:56
+
+# If this MAC address is already in the XML, stop now.
+grep $mac "$tmpfile" > /dev/null &&
+ { echo 1>&2 "$0: you seem to have already run this script"; exit 1; }
+
+err=1
+# Add an interface block right after the only existing one.
+perl -ni -e '$m = m!</interface>!; print; $m and print ' \
+ -e 'qq( <interface type="bridge">\n) .' \
+ -e 'qq( <mac address="'$mac'"/>\n) .' \
+ -e 'qq( <source bridge="dummybridge"/>\n) .' \
+ -e 'qq( </interface>\n)' "$tmpfile" &&
+virsh -c qemu:///system define "$tmpfile" && err=0
+
+exit $err
--
1.5.5.rc3.1.gaece
More information about the ovirt-devel
mailing list