summaryrefslogtreecommitdiff
path: root/others/vm3/vm.sh
blob: a043f89e5bd0eb8891c3c8fd569f62c6cf3b5ca3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
# Main entry point for VM management
# also negotiator for executing scripts, so for storage 

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 <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 "$@"
        ;;
      ls)
        $SCRIPT_DIR/compute/ls.sh "$@"
        ;;
      shutdown)
        $SCRIPT_DIR/compute/shutdown.sh "$@"
        ;;
      rm)
        $SCRIPT_DIR/compute/rm.sh "$@"
        ;;
      *)
        echo -e "Available compute actions: \ncreate\nstart\nls\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