Commit 495c525c authored by Vitaly Lipatov's avatar Vitaly Lipatov

improve vz list using (all, ALL for any cases)

parent 9d4aec7d
...@@ -88,15 +88,37 @@ case "$1" in ...@@ -88,15 +88,37 @@ case "$1" in
;; ;;
esac esac
line_filter()
{
# https://stackoverflow.com/questions/1251999/how-can-i-replace-a-newline-n-using-sed
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/ /g' -e "s| \+| |g" -e "s|^ ||g" -e "s| $||g"
}
list_all() list_all()
{ {
vzlist -1 "$@" vzlist -1 "$@" | line_filter
} }
list_ALL() list_ALL()
{ {
vzlist -1 -a "$@" vzlist -1 -a "$@" | line_filter
}
get_list()
{
if [ "$1" = "ALL" ] ; then
list_ALL
return
fi
if [ "$1" = "all" ] ; then
list_all
return
fi
if [ -n "$1" ] ; then
list_ALL "$@"
return
fi
list_all
} }
# TODO: add all support for all cases # TODO: add all support for all cases
...@@ -105,7 +127,8 @@ CMD=$1 ...@@ -105,7 +127,8 @@ CMD=$1
shift shift
case $CMD in case $CMD in
off) # HELPCMD: stop container(s) and disable start on boot off) # HELPCMD: stop container(s) and disable start on boot
for i in "$@" ; do LIST=$(get_list "$@")
for i in $LIST ; do
info "Stopping $i ..." info "Stopping $i ..."
vzctl stop $i vzctl stop $i
# TODO: check if enabled # TODO: check if enabled
...@@ -121,25 +144,29 @@ case $CMD in ...@@ -121,25 +144,29 @@ case $CMD in
done done
;; ;;
status) # HELPCMD: print container(s) status status) # HELPCMD: print container(s) status
info "Do $CMD for $* ..." LIST=$(get_list "$@")
for i in "$@" ; do info "Do $CMD for $LIST ..."
for i in $LIST ; do
vzctl $CMD $i vzctl $CMD $i
done done
;; ;;
compact) # HELPCMD: do named operation on container(s) compact) # HELPCMD: do named operation on container(s)
for i in "$@" ; do LIST=$(get_list "$@")
for i in $LIST ; do
info "Do $CMD on $i ..." info "Do $CMD on $i ..."
vzctl $CMD $i vzctl $CMD $i
done done
;; ;;
stop) # HELPCMD: stop container(s) stop) # HELPCMD: stop container(s)
LIST=$(get_list "$@")
for i in "$@" ; do for i in "$@" ; do
info "Stopping $i ..." info "Stopping $i ..."
vzctl stop $i vzctl stop $i
done done
;; ;;
start) # HELPCMD: start container(s) start) # HELPCMD: start container(s)
for i in "$@" ; do LIST=$(get_list "$@")
for i in $LIST ; do
info "Starting $i ..." info "Starting $i ..."
vzctl start $i vzctl start $i
done done
...@@ -148,12 +175,7 @@ case $CMD in ...@@ -148,12 +175,7 @@ case $CMD in
# if -q, just id list # if -q, just id list
if [ -z "$verbose" ] || [ "$1" = "-1" ] || [ "$1" = "-q" ] ; then if [ -z "$verbose" ] || [ "$1" = "-1" ] || [ "$1" = "-q" ] ; then
[ -z "$verbose" ] || shift [ -z "$verbose" ] || shift
# some hack, TODO: drop all args get_list "$@"
[ "$1" = "all" ] && shift
LIST="$(list_all "$@")"
[ "$1" = "ALL" ] && LIST="$(list_ALL)"
[ "$1" = "-a" ] && LIST="$(list_ALL)"
echo "$LIST"
exit exit
fi fi
vzlist "$@" vzlist "$@"
...@@ -161,9 +183,7 @@ case $CMD in ...@@ -161,9 +183,7 @@ case $CMD in
exec) # HELPCMD: execute command by list (all for all containers) exec) # HELPCMD: execute command by list (all for all containers)
INCMD="$1" INCMD="$1"
shift shift
LIST="$*" LIST=$(get_list "$@")
[ "$1" = "all" ] && LIST="$(list_all)"
[ "$1" = "ALL" ] && LIST="$(list_ALL)"
for i in $LIST ; do for i in $LIST ; do
#info "Executing on $i ..." #info "Executing on $i ..."
#printf "%3d: %s" $i "$(vzctl exec $i "$INCMD")" #printf "%3d: %s" $i "$(vzctl exec $i "$INCMD")"
...@@ -172,9 +192,7 @@ case $CMD in ...@@ -172,9 +192,7 @@ case $CMD in
done done
;; ;;
info) # HELPCMD: print containers(s) info (vzlist like) info) # HELPCMD: print containers(s) info (vzlist like)
LIST="$*" LIST=$(get_list "$@")
[ "$1" = "all" ] && LIST="$(list_all)"
[ "$1" = "ALL" ] && LIST="$(list_ALL)"
#for i in $LIST ; do #for i in $LIST ; do
#info "Executing on $i ..." #info "Executing on $i ..."
#printf "%3d: %s" $i "$(vzctl exec $i "$INCMD")" #printf "%3d: %s" $i "$(vzctl exec $i "$INCMD")"
...@@ -186,7 +204,7 @@ case $CMD in ...@@ -186,7 +204,7 @@ case $CMD in
;; ;;
destroy) # HELPCMD: destroy container(s) by list destroy) # HELPCMD: destroy container(s) by list
echo "You request to destroy follow containers:" echo "You request to destroy follow containers:"
vzlist "$@" vzlist -a "$@"
#local response #local response
read -r -p "Are you sure? [Yes/No]" response read -r -p "Are you sure? [Yes/No]" response
[ "$response" = "Yes" ] || fatal "Have no receive your accept." [ "$response" = "Yes" ] || fatal "Have no receive your accept."
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment