Commits

Audrius Kažukauskas committed dc57eb6

Add info command.

  • Participants
  • Parent commits c986db0

Comments (0)

Files changed (2)

usr/libexec/lxc-slack/info

+#!/bin/bash
+
+cmd_usage() {   # {{{
+  cat >&2 <<EOF
+Display the state of container.
+
+Usage: $MAIN $CMD -a|<CONTAINER_NAME>
+
+Options:
+
+  -a    display state of all containers
+
+EOF
+
+  exit 1
+}   # }}}
+
+# Initialize command.
+cmd_init() {   # {{{
+  CMD_OPT=":a"
+
+  return 0
+}   # }}}
+
+# Process command options.
+cmd_opt() {    # {{{
+  local opt="$1" optind="$2" optarg="$3"
+  case "$opt" in
+    a)
+      LIST_ALL=yes
+      ;;
+    \?)
+      echo "Invalid option: -$optarg" >&2
+      exit 1
+      ;;
+    :)
+      echo "Option -$optarg requires an argument." >&2
+      exit 1
+      ;;
+  esac
+
+  return 0
+}   # }}}
+
+# Process command parameters.
+cmd_param() {    # {{{
+  [ "$LIST_ALL" != "yes" -a -z "$CONTAINER_NAME" ] && CONTAINER_NAME="$1"
+
+  return 0
+}   # }}}
+
+cmd_main() {   # {{{
+  [ "$LIST_ALL" != "yes" -a -z "$CONTAINER_NAME" ] && cmd_usage
+
+  if [ "$LIST_ALL" = "yes" ]; then
+    for NAME in $( ${ROOT}/${MAIN} ls c ); do
+      lxc-info -n ${NAME}
+    done
+  else
+    CONTAINER=${BASE_PATH}/containers/${CONTAINER_NAME}
+
+    if [ ! -d "$CONTAINER" ]; then
+      echo "No such container: $CONTAINER_NAME" >&2
+      exit 1
+    fi
+
+    lxc-info -n ${CONTAINER_NAME}
+  fi
+
+  return 0
+}   # }}}

usr/sbin/lxc-slack

   rmc     remove a container
 
   ls      list all templates or containers
+  info    display the state of container
 
 Run "$MAIN COMMAND" to get help for COMMAND.
 EOF