-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_up_new_node
executable file
·43 lines (32 loc) · 2.5 KB
/
start_up_new_node
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
#!/bin/bash
#This wrapper script parses all relevant information and triggers the node adding procedure
rc_file_path=$1 #Get OpenStack rc file path as cmd line input
#Check if rc_file_path has been entered and a file can be found
if [ -z "$1" ]
then
echo "You have not specified the path to the OpenStack RC File. Please specify the file path"
exit 1
elif ! [ -f "$1" ]
then
echo "You have specified a path to the OpenStack RC File, but no file can be found under this path. Plese check and enter the correct file path"
exit 1
else
echo "OpenStack RC File path is specififed and path is valid"
fi
sh ./get_next_compute_node_number.sh #Start script to parse out next node number
next_node_number=$(cat next_node_number) #Save next node number in variable
cd terraform_add_node/ #Change to add node directory
source $rc_file_path #Set path to rc file to source OpenStack API credentials
terraform init #Init terrafrom
terraform apply -auto-approve #Apply node start
cd .. #Change to repository root directory
search_line_number=$(grep -n "master-instance" terraform/terraform.tfstate | cut -f1 -d:) #Get line number, after master information starts
IP_MASTER_NODE=$(tail -n +$search_line_number terraform/terraform.tfstate | grep "access_ip_v4" | awk -F ': "' '{print $2}' | head -c -3) #Get public IP of master node
NEW_NODE_IP=$(grep -n "fixed_ip_v4" terraform_add_node/terraform.tfstate | awk -F ': "' '{print $2}' | head -c -3) #Get the IP of the node to be added
NEW_NODE_HOSTNAME=$(grep -n "unicore-compute-node-" terraform_add_node/terraform.tfstate | awk -F ': "' '{print $2}' | head -c -3) #Get the hostname of the node to be added
SSH_PATH_LOCAL="/home/centos/.ssh/connection_key.pem" #Get path to internal SSH key in master node
SSH_PATH_MASTER=$(awk '/private_key_path/{getline; print}' terraform/vars.tf | awk -F ' = "' '{print $2}' | head -c -2) #Get path to SSH key to master node
ssh -n -o StrictHostKeyChecking=no -i $SSH_PATH_MASTER centos@$IP_MASTER_NODE "add_node_to_cluster $NEW_NODE_IP $NEW_NODE_HOSTNAME $SSH_PATH_LOCAL" #Start new node over script on master node
terraform state mv -state=terraform_add_node/terraform.tfstate -state-out=terraform/terraform.tfstate openstack_compute_instance_v2.compute openstack_compute_instance_v2.compute[$next_node_number]
rm terraform_add_node/terraform.tfstate* #Remove terraform state file possibly start further nodes
rm terraform/terraform.tfstate.* #Remove terraform state file backups