[Pkg-xen-changes] r985 - in trunk/xen/debian: . scripts
Bastian Blank
waldi at alioth.debian.org
Sun Apr 22 19:21:26 UTC 2012
Author: waldi
Date: Sun Apr 22 19:21:25 2012
New Revision: 985
Log:
* debian/scripts/Makefile: Add script.
* debian/scripts/xen-init-list: Add helper script.
* debian/xen-utils-common.xendomains.init
- Use helper script for domain list.
- Use toolstack wrapper.
Added:
trunk/xen/debian/scripts/xen-init-list (contents, props changed)
Modified:
trunk/xen/debian/scripts/Makefile
trunk/xen/debian/xen-utils-common.xendomains.init
Modified: trunk/xen/debian/scripts/Makefile
==============================================================================
--- trunk/xen/debian/scripts/Makefile Sun Apr 22 18:36:01 2012 (r984)
+++ trunk/xen/debian/scripts/Makefile Sun Apr 22 19:21:25 2012 (r985)
@@ -25,6 +25,7 @@
PRIVATE_SCRIPTS = \
xen-dir \
+ xen-init-list \
xen-toolstack \
xen-version \
$(GLOBAL_TOOLSTACK_WRAPPER) \
Added: trunk/xen/debian/scripts/xen-init-list
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/xen/debian/scripts/xen-init-list Sun Apr 22 19:21:25 2012 (r985)
@@ -0,0 +1,46 @@
+#!/usr/bin/python
+
+import re
+import subprocess
+
+
+class SXPParser(object):
+ tokenizer_rules = r""" (?P<open> \( ) | (?P<close> \) ) | (?P<whitespace> \s+ ) | [^()^\s]+ """
+ tokenizer_re = re.compile(tokenizer_rules, re.X)
+
+ def __init__(self):
+ self.stack = []
+ self.data = []
+
+ def __call__(self, input):
+ for match in self.tokenizer_re.finditer(input):
+ if match.group('open'):
+ self.stack.append([])
+ elif match.group('close'):
+ top = self.stack.pop()
+ if self.stack:
+ self.stack[-1].append(top)
+ else:
+ self.data.append(top)
+ elif match.group('whitespace'):
+ pass
+ else:
+ if self.stack:
+ self.stack[-1].append(match.group())
+ return self.data
+
+
+if __name__ == '__main__':
+ p = subprocess.check_output(('xen', 'list', '-l'))
+ s = SXPParser()(p)
+ for i in s:
+ if i and i[0] == 'domain':
+ try:
+ data = dict(i[1:])
+ domid = int(data['domid'])
+ name = data['name']
+ if domid == 0:
+ continue
+ print domid, name
+ except (KeyError, ValueError) as e:
+ pass
Modified: trunk/xen/debian/xen-utils-common.xendomains.init
==============================================================================
--- trunk/xen/debian/xen-utils-common.xendomains.init Sun Apr 22 18:36:01 2012 (r984)
+++ trunk/xen/debian/xen-utils-common.xendomains.init Sun Apr 22 19:21:25 2012 (r985)
@@ -10,14 +10,7 @@
# boots / shuts down.
### END INIT INFO
-CMD=xm
-$CMD list &> /dev/null
-if test $? -ne 0
-then
- CMD=xl
-fi
-
-$CMD list &> /dev/null
+xen list &> /dev/null
if test $? -ne 0
then
exit 0;
@@ -164,7 +157,7 @@
# read name from xen config file
rdname()
{
- NM=$($CMD create --quiet --dryrun --defconfig "$1" |
+ NM=$(xen create --quiet --dryrun --defconfig "$1" |
sed -n 's/^.*(name \(.*\))$/\1/p')
}
@@ -185,38 +178,17 @@
done
}
-LIST_GREP='((domain\|(domid\|(name\|^{$\|"name":\|"domid":'
-parseln()
-{
- if [[ "$1" =~ '(domain' ]] || [[ "$1" = "{" ]]; then
- name=;id=
- elif [[ "$1" =~ '(name' ]]; then
- name=$(echo $1 | sed -e 's/^.*(name \(.*\))$/\1/')
- elif [[ "$1" =~ '(domid' ]]; then
- id=$(echo $1 | sed -e 's/^.*(domid \(.*\))$/\1/')
- elif [[ "$1" =~ '"name":' ]]; then
- name=$(echo $1 | sed -e 's/^.*"name": "\(.*\)",$/\1/')
- elif [[ "$1" =~ '"domid":' ]]; then
- id=$(echo $1 | sed -e 's/^.*"domid": \(.*\),$/\1/')
- fi
-
- [ -n "$name" -a -n "$id" ] && return 0 || return 1
-}
-
is_running()
{
rdname $1
RC=1
- name=;id=
- while read LN; do
- parseln "$LN" || continue
- if test $id = 0; then continue; fi
+ while read id name rest; do
case $name in
($NM)
RC=0
;;
esac
- done < <($CMD list -l | grep $LIST_GREP)
+ done < <(/usr/lib/xen-common/bin/xen-init-list)
return $RC
}
@@ -240,7 +212,7 @@
HEADER=`head -c 16 $dom | head -n 1 2> /dev/null`
if [ $HEADER = "LinuxGuestRecord" ]; then
echo -n " ${dom##*/}"
- XMR=`$CMD restore $dom 2>&1 1>/dev/null`
+ XMR=`xen restore $dom 2>&1 1>/dev/null`
#$CMD restore $dom
if [ $? -ne 0 ]; then
echo -e "\nAn error occurred while restoring domain ${dom##*/}:\n$XMR"
@@ -276,7 +248,7 @@
if [ $? -eq 0 ] || is_running $dom; then
echo -n "(skip)"
else
- XMC=`$CMD create --quiet --defconfig $dom`
+ XMC=`xen create --quiet --defconfig $dom`
if [ $? -ne 0 ]; then
echo -e "\nAn error occurred while creating domain ${dom##*/}: $XMC\n"
rc_failed $?
@@ -291,14 +263,11 @@
all_zombies()
{
- name=;id=
- while read LN; do
- parseln "$LN" || continue
- if test $id = 0; then continue; fi
+ while read id name rest; do
if test "$state" != "-b---d" -a "$state" != "-----d"; then
return 1;
fi
- done < <($CMD list -l | grep $LIST_GREP)
+ done < <(/usr/lib/xen-common/bin/xen-init-list)
return 0
}
@@ -317,7 +286,7 @@
usleep 20000
for no in `seq 0 $XENDOMAINS_STOP_MAXWAIT`; do
# exit if $CMD save/migrate/shutdown is finished
- PSAX=`ps axlw | grep "$CMD $1" | grep -v grep`
+ PSAX=`ps axlw | grep "xen $1" | grep -v grep`
if test -z "$PSAX"; then exit; fi
if ! test -n "$3"; then echo -n '.'; fi
sleep 1
@@ -341,10 +310,7 @@
rdnames
fi
echo -n "Shutting down Xen domains:"
- name=;id=
- while read LN; do
- parseln "$LN" || continue
- if test $id = 0; then continue; fi
+ while read id name rest; do
echo -n " $name"
if test "$XENDOMAINS_AUTO_ONLY" = "true"; then
eval "
@@ -365,7 +331,7 @@
if test -n "$XENDOMAINS_SYSRQ"; then
for sysrq in $XENDOMAINS_SYSRQ; do
echo -n "(SR-$sysrq)"
- XMR=`$CMD sysrq $id $sysrq 2>&1 1>/dev/null`
+ XMR=`xen sysrq $id $sysrq 2>&1 1>/dev/null`
if test $? -ne 0; then
echo -e "\nAn error occurred while doing sysrq on domain:\n$XMR\n"
rc_failed $?
@@ -383,7 +349,7 @@
echo -n "(migr)"
watchdog_xencmd migrate &
WDOG_PID=$!
- XMR=`$CMD migrate $id $XENDOMAINS_MIGRATE 2>&1 1>/dev/null`
+ XMR=`xen migrate $id $XENDOMAINS_MIGRATE 2>&1 1>/dev/null`
if test $? -ne 0; then
echo -e "\nAn error occurred while migrating domain:\n$XMR\n"
rc_failed $?
@@ -403,7 +369,7 @@
watchdog_xencmd save &
WDOG_PID=$!
mkdir -p "$XENDOMAINS_SAVE"
- XMR=`$CMD save $id $XENDOMAINS_SAVE/$name 2>&1 1>/dev/null`
+ XMR=`xen save $id $XENDOMAINS_SAVE/$name 2>&1 1>/dev/null`
if test $? -ne 0; then
echo -e "\nAn error occurred while saving domain:\n$XMR\n"
rc_failed $?
@@ -421,7 +387,7 @@
echo -n "(shut)"
watchdog_xencmd shutdown &
WDOG_PID=$!
- XMR=`$CMD shutdown $id $XENDOMAINS_SHUTDOWN 2>&1 1>/dev/null`
+ XMR=`xen shutdown $id $XENDOMAINS_SHUTDOWN 2>&1 1>/dev/null`
if test $? -ne 0; then
echo -e "\nAn error occurred while shutting down domain:\n$XMR\n"
rc_failed $?
@@ -429,7 +395,7 @@
fi
kill $WDOG_PID >/dev/null 2>&1
fi
- done < <($CMD list -l | grep $LIST_GREP)
+ done < <(/usr/lib/xen-common/bin/xen-init-list)
# NB. this shuts down ALL Xen domains (politely), not just the ones in
# AUTODIR/*
@@ -440,7 +406,7 @@
echo -n " SHUTDOWN_ALL "
watchdog_xencmd shutdown 1 false &
WDOG_PID=$!
- XMR=`$CMD shutdown $XENDOMAINS_SHUTDOWN_ALL 2>&1 1>/dev/null`
+ XMR=`xen shutdown $XENDOMAINS_SHUTDOWN_ALL 2>&1 1>/dev/null`
if test $? -ne 0; then
echo -e "\nAn error occurred while shutting down all domains: $XMR\n"
rc_failed $?
@@ -458,15 +424,13 @@
check_domain_up()
{
name=;id=
- while read LN; do
- parseln "$LN" || continue
- if test $id = 0; then continue; fi
+ while read id name rest; do
case $name in
($1)
return 0
;;
esac
- done < <($CMD list -l | grep $LIST_GREP)
+ done < <(/usr/lib/xen-common/bin/xen-init-list)
return 1
}
More information about the Pkg-xen-changes
mailing list