-
Notifications
You must be signed in to change notification settings - Fork 5
/
cpodctl
executable file
·207 lines (188 loc) · 3.97 KB
/
cpodctl
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash
CPODFACTORY=/root/cPodFactory
BACKUPDIR=${CPODFACTORY}/backup
show_help() {
echo "=== cpodctl help"
echo ""
echo "addfiler[cpod_name] [owner] : add cpodfiler to cpod"
echo "create [cpod_name] [#_esx] [owner] : create cpod with specs"
echo "delete [cpod_name] [owner] : delete cpod"
echo "list : list all cpods"
echo "password [owner] : retrieve cPod password from a owner, otherwise for 'admin'"
echo "vcsa [cpod_name] [owner] : deploy vcsa in cpod"
echo "expose [cpod_name] : expose cpod on Internet as a Public cPod, FWing any connectivity from cPod to Lab"
echo "lease [action] (i.e create, delete or debug) [cpod_name] [owner] : create a 15d lease on a cpod"
}
list_cpod() {
cd ${CPODFACTORY}
./list_cpod.sh
}
password_cpod() {
cd ${CPODFACTORY}
OWNER=${1}
if [ "${1}" == "" ]; then OWNER="admin"; fi
./password_cpod.sh ${OWNER}
}
create_cpod() {
cd ${CPODFACTORY}
NAME=${1}
NBESX=$( expr ${2} )
OWNER=${3}
NAME=$( echo $NAME | tr '[:lower:]' '[:upper:]' )
if [ "$NAME" == "X" ]; then
while :
do
NAME=$( ./extra/petname.sh )
grep "$NAME" /etc/hosts
if [ $? -eq 1 ]; then
break
fi
done
NAME=$( echo $NAME | tr '[:lower:]' '[:upper:]' )
fi
if [ $NBESX -gt 0 ] && [ $NBESX -lt 5 ] || [ "${FORCE}" == "1" ]; then
if [ "${2}" == "" ]; then OWNER="admin"; fi
./create_cpod.sh ${NAME} ${NBESX} ${OWNER}
else
echo "Please specify #ESX between 1 and 4."
fi
}
delete_cpod() {
cd ${CPODFACTORY}
NAME=${1}
OWNER=${2}
if [ "${NAME}" != "" ] && [ "${OWNER}" != "" ]; then
./delete_cpod.sh ${NAME} ${OWNER}
else
echo "Please specify cPod name and/or owner."
fi
}
vcsa() {
cd ${CPODFACTORY}
NAME=$( echo ${1} | tr '[:lower:]' '[:upper:]' )
OWNER=${2}
if [ "${NAME}" != "" ] && [ "${OWNER}" != "" ]; then
./extra/deploy_vcsa.sh ${NAME} ${OWNER}
else
echo "Please specify cPod name and/or owner."
fi
}
addfiler() {
cd ${CPODFACTORY}
NAME=${1}
OWNER=${2}
if [ "${NAME}" != "" ] && [ "${OWNER}" != "" ]; then
./extra/add_filer.sh ${NAME} ${OWNER}
else
echo "Please specify cPod name and/or owner."
fi
}
backup() {
cd ${CPODFACTORY}
cp env.passwd ${BACKUPDIR}
cp env-* ${BACKUPDIR}
cp extra/post_slack.sh ${BACKUPDIR}
echo "Backup done in ${BACKUPDIR}."
}
restore() {
echo "Backup file are in ${BACKUPDIR}. Restore by yourself."
}
expose() {
cd ${CPODFACTORY}
NAME=${1}
./expose_cpod.sh ${NAME}
}
lease() {
cd ${CPODFACTORY}
ACTION=${1}
NAME=${2}
OWNER=${3}
if [ "${ACTION}" == "list" ]; then
NAME="a"
OWNER="a"
./cpod_lease.sh ${ACTION} ${NAME} ${OWNER}
else
./cpod_lease.sh ${ACTION} ${NAME} ${OWNER}
fi
}
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
help)
show_help
shift # past argument
;;
list)
list_cpod
shift # past argument
;;
backup)
backup
shift # past argument
;;
restore)
restore
shift # past argument
;;
create)
shift # past argument
create_cpod ${1} ${2} ${3}
shift # past value
shift # past value
shift # past value
shift # past value
;;
delete)
shift # past argument
delete_cpod ${1} ${2}
shift # past value
shift # past value
shift # past value
;;
password)
shift # past argument
password_cpod ${1}
shift # past value
shift # past value
;;
vcsa)
shift # past argument
vcsa ${1} ${2}
shift # past value
shift # past value
shift # past value
;;
addfiler)
shift # past argument
addfiler ${1} ${2}
shift # past value
shift # past value
shift # past value
;;
expose)
shift # part argument
expose ${1}
shift # past value
shift # past value
;;
lease)
shift
lease ${1} ${2} ${3}
shift
shift
shift
shift
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
if [[ -n $1 ]]; then
echo "\"${1}\" is not an argument or command. Use \"help\" in order to list all verbs."
fi