-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvm
More file actions
executable file
·141 lines (117 loc) · 1.92 KB
/
Copy pathvm
File metadata and controls
executable file
·141 lines (117 loc) · 1.92 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
umask 077
. /etc/vmdefaults.conf
. /usr/local/lib/vmfunctions.sh
################################################################################
# check parameters
if [ -z "$1" ]; then
err_usage "$0"
exit -1
fi
CMD=$1
shift
if [ "${CMD}" != "list" ]; then
if [ -z "$1" ]; then
err_usage "$0"
exit -1
fi
VM_NAME="$1"
shift
# check vm
vm_check "${VM_NAME}" || {
err_vm "${VM_NAME}" "$?"
exit -2
}
fi
################################################################################
# subroutines
case "${CMD}" in
list)
for i in "${IMAGE_BASEPATH}"/*; do
VM_NAME=$(basename $i)
unset VM_RAM
unset VM_CPUS
. $i/vm.conf
if vm_isrunning ${VM_NAME}; then
echo "up ${VM_NAME} - RAM: ${VM_RAM} - CPUs: ${VM_CPUS}"
else
echo "down ${VM_NAME} - RAM: ${VM_RAM} - CPUs: ${VM_CPUS}"
fi
done
exit 0
;;
up)
. "${IMAGE_BASEPATH}/${VM_NAME}/vm.conf"
if vm_isrunning ${VM_NAME}; then
err_vm "${VM_NAME}" ${ERR_VMALREADYRUNNING}
exit ${ERR_VMALREADYRUNNING}
fi
VM_PARAM="$(vm_buildparam)"
vm_up $@ $VM_PARAM
exit 0
;;
esac
if [ -f "${IMAGE_BASEPATH}/${VM_NAME}/vm.conf.running" ]; then
. "${IMAGE_BASEPATH}/${VM_NAME}/vm.conf.running"
else
. "${IMAGE_BASEPATH}/${VM_NAME}/vm.conf"
fi
if ! vm_isrunning ${VM_NAME}; then
err_vm "${VM_NAME}" ${ERR_VMNOTRUNNING}
exit ${ERR_VMNOTRUNNING}
fi
case "${CMD}" in
down)
vm_down $@ $VM_PARAM
exit 0
;;
reset)
vm_reset $@ $VM_PARAM
exit 0
;;
reboot)
vm_reboot $@ $VM_PARAM
exit 0
;;
pause)
vm_pause $@ $VM_PARAM
exit 0
;;
resume)
vm_resume $@ $VM_PARAM
exit 0
;;
wait)
vm_wait $@ $VM_PARAM
exit 0
;;
console)
vm_console $@ $VM_PARAM
exit 0
;;
listsnap)
vm_listsnap $@ $VM_PARAM
exit 0
;;
esac
if [ -z "$1" ]; then
err_usage $0
exit -1
fi
SNAPTAG="$1"
shift
case "${CMD}" in
addsnap)
vm_addsnap $@ $VM_PARAM
;;
delsnap)
vm_delsnap $@ $VM_PARAM
;;
runsnap)
vm_runsnap $@ $VM_PARAM
;;
*)
err_usage $0
exit -1
esac
exit 0