#!/bin/bash # Main entry point for VM management if [ "$(id -u)" != "0" ]; then echo "This script must be run as root" exit 1 fi # Get script directory for relative paths SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # First argument is the category (compute, network, storage, etc) category=$1 shift # Exit if no category specified if [ -z "$category" ]; then echo -e "Usage: ./vm [args...]\n" echo -e "Categories: \ncompute\nnetwork\nstorage\ndevice\n" echo "Run ./vm for available subactions or tree for all available actions." exit 1 fi # Second argument is the action action=$1 shift # Handle each category case $category in compute) case $action in create) $SCRIPT_DIR/compute/create.sh "$@" ;; start) $SCRIPT_DIR/compute/start.sh "$@" ;; list) $SCRIPT_DIR/compute/list.sh "$@" ;; shutdown) $SCRIPT_DIR/compute/shutdown.sh "$@" ;; delete) $SCRIPT_DIR/compute/delete.sh "$@" ;; *) echo -e "Available compute actions: \ncreate\nstart\nlist\nshutdown\ndelete" exit 1 ;; esac ;; network) case $action in attach) $SCRIPT_DIR/network/attach.sh "$@" ;; detach) $SCRIPT_DIR/network/detach.sh "$@" ;; list) $SCRIPT_DIR/network/list.sh "$@" ;; create) $SCRIPT_DIR/network/create.sh "$@" ;; delete) $SCRIPT_DIR/network/delete.sh "$@" ;; *) echo "Available network actions: \ncreate\nattach\ndetach\nlist\ndelete" exit 1 ;; esac ;; disk) case $action in attach) $SCRIPT_DIR/disk/attach.sh "$@" ;; list) $SCRIPT_DIR/disk/list.sh "$@" ;; *) echo "Available disk actions: \ncreate\nattach\ndetach\nlist\ndelete" exit 1 ;; esac ;; storage-pool) case $action in create) # using a directory as a storage pool $SCRIPT_DIR/storage-pool/create.sh "$@" ;; list) $SCRIPT_DIR/storage-pool/list.sh "$@" ;; create-from-device) # initialise and use a devcie as storage pool $SCRIPT_DIR/storage-pool/create-from-device.sh "$@" ;; *) echo "Available disk actions: \ncreate\nlist\ncreate-from-device\ndelete" exit 1 ;; esac ;; *) echo "Unknown category: $category" echo "Available categories: compute, network, storage" exit 1 ;; esac