From f7f159a04671690786de2f84e34046c103521d58 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 22 Dec 2024 19:03:49 +0800 Subject: vm.shupdate --- others/vm3/vm.sh | 148 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 112 insertions(+), 36 deletions(-) mode change 100644 => 100755 others/vm3/vm.sh (limited to 'others/vm3/vm.sh') diff --git a/others/vm3/vm.sh b/others/vm3/vm.sh old mode 100644 new mode 100755 index 1072569..30168ba --- a/others/vm3/vm.sh +++ b/others/vm3/vm.sh @@ -1,42 +1,118 @@ #!/bin/bash +# Main entry point for VM management +if [ "$(id -u)" != "0" ]; then + echo "This script must be run as root" + exit 1 +fi -case "$1" in - "compute") - shift - case "$1" in - "create") - VM_NAME=$2 - shift 2 - while [[ $# -gt 0 ]]; do - case "$1" in - -vcpu) - VCPU=$2 - shift 2 - ;; - -ram) - RAM_GB=$(($2*1000)) - shift 2 - ;; - -disk) - DISK_GB=$2 - shift 2 - ;; - *) - echo "Unknown argument: $1" - exit 1 - ;; - esac - done - ;; - *) - echo "Unknown compute command: $1" - exit 1 - ;; - esac - ;; - *) - echo "Unknown command: $1" +# 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 -- cgit v1.2.3-70-g09d2