summaryrefslogtreecommitdiff
path: root/others/vm3/vm.sh
diff options
context:
space:
mode:
authorYour Name <you@example.com>2024-12-22 19:03:49 +0800
committerYour Name <you@example.com>2024-12-22 19:03:49 +0800
commitf7f159a04671690786de2f84e34046c103521d58 (patch)
tree22b45e904c1aa6800250ec6e998d0022fd018ade /others/vm3/vm.sh
parent2916e3eff503473f6bf8b90e0921b0ccd347166f (diff)
vm.shupdate
Diffstat (limited to 'others/vm3/vm.sh')
-rwxr-xr-x[-rw-r--r--]others/vm3/vm.sh148
1 files changed, 112 insertions, 36 deletions
diff --git a/others/vm3/vm.sh b/others/vm3/vm.sh
index 1072569..30168ba 100644..100755
--- 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 <category> <action> [args...]\n"
+ echo -e "Categories: \ncompute\nnetwork\nstorage\ndevice\n"
+ echo "Run ./vm <category> 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