-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcluster-control
executable file
·75 lines (64 loc) · 1.95 KB
/
cluster-control
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
#!/bin/bash
INVENTORY_FILE=$1
ACTION=$2
export ANSIBLE_DISPLAY_SKIPPED_HOSTS=false
export ANSIBLE_CONFIG=./ansible.cfg
function show_usage () {
echo "usage: $ bash cluster-control <inventory-file> <action: start|suspend|stop|destroy>"
echo
echo "eg."
echo
echo "$ bash cluster-control ids/k8s1 suspend"
echo
echo "$ bash cluster-control ids/k8s1 start"
echo
exit 1
}
if [ -z $INVENTORY_FILE ]; then
echo
echo "Cluster specification folder not specified!"
echo
show_usage
fi
INVENTORY_FILE=./clusters/$INVENTORY_FILE/hosts
if [ ! -f $INVENTORY_FILE ]; then
echo
echo "Unable to find inventory file @: ${INVENTORY_FILE}"
exit 1
fi
if [ -z $ACTION ]; then
echo
echo "Action not specified!"
echo
show_usage
fi
PLATFORM=`uname -ra`
VMRUN_CMD=vmrun
if [[ $PLATFORM == *"Microsoft"* ]]; then
export ANSIBLE_CONFIG=$PWD/ansible.cfg
VMRUN_CMD=vmrun.exe
fi
CLUSTER_TYPE=`sed -n '/^cluster_type=/ {s///p;q;}' $INVENTORY_FILE | tr -d '\n' | tr -d '\r'`
DEPLOY_TARGET=`sed -n '/^deploy_target=/ {s///p;q;}' $INVENTORY_FILE | tr -d '\n' | tr -d '\r'`
CLUSTER_PROTECTED=`sed -n '/^protected=/ {s///p;q;}' $INVENTORY_FILE | tr -d '\n' | tr -d '\r'`
if [ "$DEPLOY_TARGET" == "fusion" ]; then
DEPLOY_TARGET=desktop
fi
if [ "$ACTION" == "destroy" ] && [ "$CLUSTER_PROTECTED" == "true" ]; then
echo
echo "Destroy Blocked!"
echo "Cluster Protected: destroy may not be used on clusters where protected=true"
echo "Remove this flag from the cluster hosts file to delete the cluster when all jobs have been transitioned."
echo
exit 1
fi
if [ "$ACTION" == "start" ] || [ "$ACTION" == "stop" ] || [ "$ACTION" == "suspend" ] || [ "$ACTION" == "destroy" ]; then
ansible-playbook -i $INVENTORY_FILE ansible/$DEPLOY_TARGET-control-vms.yml --e "vm_action=$ACTION"
if [ "$DEPLOY_TARGET" == "desktop" ]; then
${VMRUN_CMD} list
fi
else
echo
echo "Invalid: You must specify an action that is one of: start, stop, suspend or destroy"
echo
fi