Merge "Add support for upgrading ec2-api"
[apex-tripleo-heat-templates.git] / deployed-server / scripts / get-occ-config.sh
1 #!/bin/bash
2
3 set -eux
4
5 SLEEP_TIME=5
6
7 CONTROLLER_HOSTS=${CONTROLLER_HOSTS:-""}
8 COMPUTE_HOSTS=${COMPUTE_HOSTS:-""}
9 BLOCKSTORAGE_HOSTS=${BLOCKSTORAGE_HOSTS:-""}
10 OBJECTSTORAGE_HOSTS=${OBJECTSTORAGE_HOSTS:-""}
11 CEPHSTORAGE_HOSTS=${CEPHSTORAGE_HOSTS:-""}
12 SUBNODES_SSH_KEY=${SUBNODES_SSH_KEY:-"~/.ssh/id_rsa"}
13 SSH_OPTIONS="-tt -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=Verbose -o PasswordAuthentication=no -o ConnectionAttempts=32"
14 OVERCLOUD_ROLES=${OVERCLOUD_ROLES:-"Controller Compute BlockStorage ObjectStorage CephStorage"}
15
16 # Set the _hosts vars for the default roles based on the old var names that
17 # were all caps for backwards compatibility.
18 Controller_hosts=${Controller_hosts:-"$CONTROLLER_HOSTS"}
19 Compute_hosts=${Compute_hosts:-"$COMPUTE_HOSTS"}
20 BlockStorage_hosts=${BlockStorage_hosts:-"$BLOCKSTORAGE_HOSTS"}
21 ObjectStorage_hosts=${ObjectStorage_hosts:-"$OBJECTSTORAGE_HOSTS"}
22 CephStorage_hosts=${CephStorage_hosts:-"$CEPHSTORAGE_HOSTS"}
23
24 # Set the _hosts_a vars for each role defined
25 for role in $OVERCLOUD_ROLES; do
26     eval hosts=\${${role}_hosts}
27     read -a ${role}_hosts_a <<< $hosts
28 done
29
30 admin_user_id=$(openstack user show admin -c id -f value)
31 admin_project_id=$(openstack project show admin -c id -f value)
32
33 function check_stack {
34     local stack_to_check=${1:-""}
35
36     if [ "$stack_to_check" = "" ]; then
37         echo Stack not created
38         return 1
39     fi
40
41     echo Checking if $1 stack is created
42     set +e
43     openstack stack resource list $stack_to_check
44     rc=$?
45     set -e
46
47     if [ ! "$rc" = "0" ]; then
48         echo Stack $1 not yet created
49     fi
50
51     return $rc
52 }
53
54
55 for role in $OVERCLOUD_ROLES; do
56     while ! check_stack overcloud; do
57         sleep $SLEEP_TIME
58     done
59
60     rg_stack=$(openstack stack resource show overcloud $role -c physical_resource_id -f value)
61     while ! check_stack $rg_stack; do
62         sleep $SLEEP_TIME
63         rg_stack=$(openstack stack resource show overcloud $role -c physical_resource_id -f value)
64     done
65
66     stacks=$(openstack stack resource list $rg_stack -c physical_resource_id -f value)
67
68     i=0
69
70     for stack in $stacks; do
71         server_resource_name=$role
72         if [ "$server_resource_name" = "Compute" ]; then
73             server_resource_name="NovaCompute"
74         fi
75
76         server_stack=$(openstack stack resource show $stack $server_resource_name -c physical_resource_id -f value)
77         while ! check_stack $server_stack; do
78             sleep $SLEEP_TIME
79             server_stack=$(openstack stack resource show $stack $server_resource_name -c physical_resource_id -f value)
80         done
81
82         while true; do
83             deployed_server_metadata_url=$(openstack stack resource metadata $server_stack deployed-server | jq -r '.["os-collect-config"].request.metadata_url')
84             if [ "$deployed_server_metadata_url" = "null" ]; then
85                 continue
86             else
87                 break
88             fi
89         done
90
91         echo "======================"
92         echo "$role$i os-collect-config.conf configuration:"
93
94         config="
95 [DEFAULT]
96 collectors=request
97 command=os-refresh-config
98 polling_interval=30
99
100 [request]
101 metadata_url=$deployed_server_metadata_url"
102
103         echo "$config"
104         echo "======================"
105         echo
106
107
108         host=
109         eval host=\${${role}_hosts_a[i]}
110         if [ -n "$host" ]; then
111             # Delete the os-collect-config.conf template so our file won't get
112             # overwritten
113             ssh $SSH_OPTIONS -i $SUBNODES_SSH_KEY $host sudo /bin/rm -f /usr/libexec/os-apply-config/templates/etc/os-collect-config.conf
114             ssh $SSH_OPTIONS -i $SUBNODES_SSH_KEY $host "echo \"$config\" > os-collect-config.conf"
115             ssh $SSH_OPTIONS -i $SUBNODES_SSH_KEY $host sudo cp os-collect-config.conf /etc/os-collect-config.conf
116             ssh $SSH_OPTIONS -i $SUBNODES_SSH_KEY $host sudo systemctl restart os-collect-config
117         fi
118
119         let i+=1
120
121     done
122
123 done