diff options
| author | Your Name <you@example.com> | 2024-12-22 19:03:49 +0800 |
|---|---|---|
| committer | Your Name <you@example.com> | 2024-12-22 19:03:49 +0800 |
| commit | f7f159a04671690786de2f84e34046c103521d58 (patch) | |
| tree | 22b45e904c1aa6800250ec6e998d0022fd018ade /others/vm3/vm.sh | |
| parent | 2916e3eff503473f6bf8b90e0921b0ccd347166f (diff) | |
vm.shupdate
Diffstat (limited to 'others/vm3/vm.sh')
| -rwxr-xr-x[-rw-r--r--] | others/vm3/vm.sh | 148 |
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 @@ | |||
| 1 | #!/bin/bash | 1 | #!/bin/bash |
| 2 | # Main entry point for VM management | ||
| 2 | 3 | ||
| 4 | if [ "$(id -u)" != "0" ]; then | ||
| 5 | echo "This script must be run as root" | ||
| 6 | exit 1 | ||
| 7 | fi | ||
| 3 | 8 | ||
| 4 | case "$1" in | 9 | # Get script directory for relative paths |
| 5 | "compute") | 10 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 6 | shift | 11 | |
| 7 | case "$1" in | 12 | # First argument is the category (compute, network, storage, etc) |
| 8 | "create") | 13 | category=$1 |
| 9 | VM_NAME=$2 | 14 | shift |
| 10 | shift 2 | 15 | |
| 11 | while [[ $# -gt 0 ]]; do | 16 | # Exit if no category specified |
| 12 | case "$1" in | 17 | if [ -z "$category" ]; then |
| 13 | -vcpu) | 18 | echo -e "Usage: ./vm <category> <action> [args...]\n" |
| 14 | VCPU=$2 | 19 | echo -e "Categories: \ncompute\nnetwork\nstorage\ndevice\n" |
| 15 | shift 2 | 20 | echo "Run ./vm <category> for available subactions or tree for all available actions." |
| 16 | ;; | 21 | exit 1 |
| 17 | -ram) | 22 | fi |
| 18 | RAM_GB=$(($2*1000)) | 23 | |
| 19 | shift 2 | 24 | # Second argument is the action |
| 20 | ;; | 25 | action=$1 |
| 21 | -disk) | 26 | shift |
| 22 | DISK_GB=$2 | 27 | |
| 23 | shift 2 | 28 | # Handle each category |
| 24 | ;; | 29 | case $category in |
| 25 | *) | 30 | compute) |
| 26 | echo "Unknown argument: $1" | 31 | case $action in |
| 27 | exit 1 | 32 | create) |
| 28 | ;; | 33 | $SCRIPT_DIR/compute/create.sh "$@" |
| 29 | esac | 34 | ;; |
| 30 | done | 35 | start) |
| 31 | ;; | 36 | $SCRIPT_DIR/compute/start.sh "$@" |
| 32 | *) | 37 | ;; |
| 33 | echo "Unknown compute command: $1" | 38 | list) |
| 34 | exit 1 | 39 | $SCRIPT_DIR/compute/list.sh "$@" |
| 35 | ;; | 40 | ;; |
| 36 | esac | 41 | shutdown) |
| 37 | ;; | 42 | $SCRIPT_DIR/compute/shutdown.sh "$@" |
| 38 | *) | 43 | ;; |
| 39 | echo "Unknown command: $1" | 44 | delete) |
| 45 | $SCRIPT_DIR/compute/delete.sh "$@" | ||
| 46 | ;; | ||
| 47 | *) | ||
| 48 | echo -e "Available compute actions: \ncreate\nstart\nlist\nshutdown\ndelete" | ||
| 49 | exit 1 | ||
| 50 | ;; | ||
| 51 | esac | ||
| 52 | ;; | ||
| 53 | |||
| 54 | network) | ||
| 55 | case $action in | ||
| 56 | attach) | ||
| 57 | $SCRIPT_DIR/network/attach.sh "$@" | ||
| 58 | ;; | ||
| 59 | detach) | ||
| 60 | $SCRIPT_DIR/network/detach.sh "$@" | ||
| 61 | ;; | ||
| 62 | list) | ||
| 63 | $SCRIPT_DIR/network/list.sh "$@" | ||
| 64 | ;; | ||
| 65 | create) | ||
| 66 | $SCRIPT_DIR/network/create.sh "$@" | ||
| 67 | ;; | ||
| 68 | delete) | ||
| 69 | $SCRIPT_DIR/network/delete.sh "$@" | ||
| 70 | ;; | ||
| 71 | *) | ||
| 72 | echo "Available network actions: \ncreate\nattach\ndetach\nlist\ndelete" | ||
| 73 | exit 1 | ||
| 74 | ;; | ||
| 75 | esac | ||
| 76 | ;; | ||
| 77 | |||
| 78 | disk) | ||
| 79 | case $action in | ||
| 80 | attach) | ||
| 81 | $SCRIPT_DIR/disk/attach.sh "$@" | ||
| 82 | ;; | ||
| 83 | list) | ||
| 84 | $SCRIPT_DIR/disk/list.sh "$@" | ||
| 85 | ;; | ||
| 86 | *) | ||
| 87 | echo "Available disk actions: \ncreate\nattach\ndetach\nlist\ndelete" | ||
| 40 | exit 1 | 88 | exit 1 |
| 41 | ;; | 89 | ;; |
| 90 | esac | ||
| 91 | ;; | ||
| 92 | |||
| 93 | storage-pool) | ||
| 94 | case $action in | ||
| 95 | create) # using a directory as a storage pool | ||
| 96 | $SCRIPT_DIR/storage-pool/create.sh "$@" | ||
| 97 | ;; | ||
| 98 | list) | ||
| 99 | $SCRIPT_DIR/storage-pool/list.sh "$@" | ||
| 100 | ;; | ||
| 101 | create-from-device) # initialise and use a devcie as storage pool | ||
| 102 | $SCRIPT_DIR/storage-pool/create-from-device.sh "$@" | ||
| 103 | ;; | ||
| 104 | |||
| 105 | *) | ||
| 106 | echo "Available disk actions: \ncreate\nlist\ncreate-from-device\ndelete" | ||
| 107 | exit 1 | ||
| 108 | ;; | ||
| 109 | esac | ||
| 110 | ;; | ||
| 111 | |||
| 112 | |||
| 113 | *) | ||
| 114 | echo "Unknown category: $category" | ||
| 115 | echo "Available categories: compute, network, storage" | ||
| 116 | exit 1 | ||
| 117 | ;; | ||
| 42 | esac | 118 | esac |
