3 COMPUTE_USER=${COMPUTE_USER:-$(whoami)}
4 ssh_opts_cpu="$ssh_opts"
6 function installer_get_ssh_keys {
7 echo "INSTALLER_TYPE set to 'local'. Assuming SSH keys already exchanged with $COMPUTE_HOST"
11 function installer_apply_patches {
14 echo "### apply patches (installer=local)"
15 np_conf=/etc/nova/policy.json
16 if [ -e $np_conf ]; then
17 entry="os_compute_api:servers:show:host_status"
18 new="rule:admin_or_owner"
19 np_backup="${np_conf}-doctor-saved"
20 if grep -q "${entry}.*${new}" $np_conf; then
21 echo "Not modifying nova policy"
22 elif grep -q "${entry}" $np_conf; then
23 echo "modify nova policy"
24 cp $np_conf $np_backup
25 oldline=$(grep "$entry" $np_conf)
26 newline=$(echo "$oldline" | sed "s/rule.*\"/$new\"/")
27 sed -i "s/$oldline/$newline/" $np_conf
28 # TODO(umar): Update to systemd when screen is no more used for devstack
29 screen -S stack -p n-api -X stuff "^C^M^[[A^M" # restart n-api service
31 echo "add nova policy"
32 cp $np_conf $np_backup
33 sed -i "/{/a \ \"${entry}\": \"$new\"" $np_conf
34 screen -S stack -p n-api -X stuff "^C^M^[[A^M"
37 # policy.json does not exist in Ocata.
38 echo "$np_conf does not exist. Creating a new one"
39 echo -e '{\n "context_is_admin": "role:admin",' > $np_conf
40 echo -e ' "owner" : "user_id:%(user_id)s",' >> $np_conf
41 echo -e ' "admin_or_owner": "rule:context_is_admin or rule:owner",' >> $np_conf
42 echo -e ' "os_compute_api:servers:show:host_status": "rule:admin_or_owner"\n}' >> $np_conf
43 np_rm="${np_conf}-doctor-rm"
45 screen -S stack -p n-api -X stuff "^C^M^[[A^M"
51 function setup_installer {
52 installer_get_ssh_keys
53 installer_apply_patches
56 function get_compute_ip_from_hostname {
59 if is_set COMPUTE_IP; then
60 echo "Using pre-configured COMPUTE_IP=$COMPUTE_IP ..."
63 COMPUTE_IP=$(getent hosts "$compute_host" | awk '{ print $1 }')
64 die_if_not_set $LINENO COMPUTE_IP \
65 "Could not resolve $compute_host. Either manually set COMPUTE_IP or enable DNS resolution."
68 function cleanup_installer {
70 echo "### revert patches (installer=local)"
73 np_conf=/etc/nova/policy.json
74 np_backup="${np_conf}-doctor-saved"
75 np_rm="${np_conf}-doctor-rm"
76 if [ -e $np_backup ]; then
77 cp -f $np_backup $np_conf
79 screen -S stack -p n-api -X stuff "^C^M^[[A^M"
80 elif [ -e $np_rm ]; then
83 screen -S stack -p n-api -X stuff "^C^M^[[A^M"