blob: 3f9b1be5f9a762974e47ce63ef60ec6ef21c07e5 [file] [log] [blame]
Nikhil Manchanda0cccad42012-12-03 18:15:09 -07001# lib/trove
2# Functions to control the configuration and operation of the **Trove** service
3
4# Dependencies:
5# ``functions`` file
6# ``DEST``, ``STACK_USER`` must be defined
7# ``SERVICE_{HOST|PROTOCOL|TOKEN}`` must be defined
8
9# ``stack.sh`` calls the entry points in this order:
10#
11# install_trove
12# configure_trove
13# init_trove
14# start_trove
15# stop_trove
16# cleanup_trove
17
18# Save trace setting
19XTRACE=$(set +o | grep xtrace)
20set +o xtrace
21
22# Defaults
23# --------
24
25NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
26
27# Set up default configuration
28TROVE_DIR=$DEST/trove
29TROVECLIENT_DIR=$DEST/python-troveclient
30TROVE_CONF_DIR=/etc/trove
31TROVE_LOCAL_CONF_DIR=$TROVE_DIR/etc/trove
32TROVE_AUTH_ENDPOINT=$KEYSTONE_AUTH_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT//v$IDENTITY_API_VERSION
33TROVE_AUTH_CACHE_DIR=${TROVE_AUTH_CACHE_DIR:-/var/cache/trove}
34TROVE_BIN_DIR=/usr/local/bin
35
Robert Myers674ee842013-11-25 13:15:35 -060036# setup_trove_logging() - Adds logging configuration to conf files
37function setup_trove_logging() {
38 local CONF=$1
39 iniset $CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
40 iniset $CONF DEFAULT use_syslog $SYSLOG
41 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
42 # Add color to logging output
43 setup_colorized_logging $CONF DEFAULT tenant user
44 fi
45}
46
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070047# create_trove_accounts() - Set up common required trove accounts
48
49# Tenant User Roles
50# ------------------------------------------------------------------
51# service trove admin # if enabled
52
53create_trove_accounts() {
54 # Trove
55 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
56 SERVICE_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
57
58 if [[ "$ENABLED_SERVICES" =~ "trove" ]]; then
Sean Dague101b4242013-10-22 08:47:11 -040059 TROVE_USER=$(keystone user-create \
60 --name=trove \
61 --pass="$SERVICE_PASSWORD" \
62 --tenant_id $SERVICE_TENANT \
63 --email=trove@example.com \
64 | grep " id " | get_field 2)
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070065 keystone user-role-add --tenant-id $SERVICE_TENANT \
Sean Dague101b4242013-10-22 08:47:11 -040066 --user-id $TROVE_USER \
67 --role-id $SERVICE_ROLE
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070068 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
69 TROVE_SERVICE=$(keystone service-create \
70 --name=trove \
71 --type=database \
72 --description="Trove Service" \
73 | grep " id " | get_field 2)
74 keystone endpoint-create \
75 --region RegionOne \
76 --service_id $TROVE_SERVICE \
77 --publicurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
78 --adminurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
79 --internalurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s"
80 fi
81 fi
82}
83
84# stack.sh entry points
85# ---------------------
86
87# cleanup_trove() - Remove residual data files, anything left over from previous
88# runs that a clean run would need to clean up
89function cleanup_trove() {
90 #Clean up dirs
91 rm -fr $TROVE_AUTH_CACHE_DIR/*
92 rm -fr $TROVE_CONF_DIR/*
93}
94
95# configure_troveclient() - Set config files, create data dirs, etc
96function configure_troveclient() {
97 setup_develop $TROVECLIENT_DIR
98}
99
100# configure_trove() - Set config files, create data dirs, etc
101function configure_trove() {
102 setup_develop $TROVE_DIR
103
104 # Create the trove conf dir and cache dirs if they don't exist
105 sudo mkdir -p ${TROVE_CONF_DIR}
106 sudo mkdir -p ${TROVE_AUTH_CACHE_DIR}
107 sudo chown -R $STACK_USER: ${TROVE_CONF_DIR}
108 sudo chown -R $STACK_USER: ${TROVE_AUTH_CACHE_DIR}
109
110 # Copy api-paste file over to the trove conf dir and configure it
111 cp $TROVE_LOCAL_CONF_DIR/api-paste.ini $TROVE_CONF_DIR/api-paste.ini
112 TROVE_API_PASTE_INI=$TROVE_CONF_DIR/api-paste.ini
113 iniset $TROVE_API_PASTE_INI filter:tokenauth auth_host $KEYSTONE_AUTH_HOST
114 iniset $TROVE_API_PASTE_INI filter:tokenauth auth_port $KEYSTONE_AUTH_PORT
115 iniset $TROVE_API_PASTE_INI filter:tokenauth auth_protocol $KEYSTONE_AUTH_PROTOCOL
116 iniset $TROVE_API_PASTE_INI filter:tokenauth admin_tenant_name $SERVICE_TENANT_NAME
117 iniset $TROVE_API_PASTE_INI filter:tokenauth admin_user trove
118 iniset $TROVE_API_PASTE_INI filter:tokenauth admin_password $SERVICE_PASSWORD
119 iniset $TROVE_API_PASTE_INI filter:tokenauth signing_dir $TROVE_AUTH_CACHE_DIR
120
121 # (Re)create trove conf files
122 rm -f $TROVE_CONF_DIR/trove.conf
123 rm -f $TROVE_CONF_DIR/trove-taskmanager.conf
Ed Cranford1089b3a2013-09-30 11:36:55 -0500124 rm -f $TROVE_CONF_DIR/trove-conductor.conf
125
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700126 iniset $TROVE_CONF_DIR/trove.conf DEFAULT rabbit_password $RABBIT_PASSWORD
127 iniset $TROVE_CONF_DIR/trove.conf DEFAULT sql_connection `database_connection_url trove`
128 iniset $TROVE_CONF_DIR/trove.conf DEFAULT add_addresses True
129
130 iniset $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample DEFAULT rabbit_password $RABBIT_PASSWORD
131 iniset $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample DEFAULT sql_connection `database_connection_url trove`
Ed Cranford1089b3a2013-09-30 11:36:55 -0500132 iniset $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample DEFAULT control_exchange trove
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700133 sed -i "s/localhost/$NETWORK_GATEWAY/g" $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample
134
Robert Myers674ee842013-11-25 13:15:35 -0600135 setup_trove_logging $TROVE_CONF_DIR/trove.conf
136 setup_trove_logging $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample
137
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700138 # (Re)create trove taskmanager conf file if needed
139 if is_service_enabled tr-tmgr; then
140 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT rabbit_password $RABBIT_PASSWORD
141 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT sql_connection `database_connection_url trove`
142 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT taskmanager_manager trove.taskmanager.manager.Manager
143 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_user radmin
144 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_tenant_name trove
145 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
146 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
Robert Myers674ee842013-11-25 13:15:35 -0600147 setup_trove_logging $TROVE_CONF_DIR/trove-taskmanager.conf
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700148 fi
Ed Cranford1089b3a2013-09-30 11:36:55 -0500149
150 # (Re)create trove conductor conf file if needed
151 if is_service_enabled tr-cond; then
152 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT rabbit_password $RABBIT_PASSWORD
153 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT sql_connection `database_connection_url trove`
154 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_user radmin
155 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_tenant_name trove
156 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
157 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
158 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT control_exchange trove
Robert Myers674ee842013-11-25 13:15:35 -0600159 setup_trove_logging $TROVE_CONF_DIR/trove-conductor.conf
Ed Cranford1089b3a2013-09-30 11:36:55 -0500160 fi
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700161}
162
163# install_troveclient() - Collect source and prepare
164function install_troveclient() {
165 git_clone $TROVECLIENT_REPO $TROVECLIENT_DIR $TROVECLIENT_BRANCH
166}
167
168# install_trove() - Collect source and prepare
169function install_trove() {
170 git_clone $TROVE_REPO $TROVE_DIR $TROVE_BRANCH
171}
172
173# init_trove() - Initializes Trove Database as a Service
174function init_trove() {
175 #(Re)Create trove db
176 recreate_database trove utf8
177
178 #Initialize the trove database
179 $TROVE_DIR/bin/trove-manage db_sync
180}
181
182# start_trove() - Start running processes, including screen
183function start_trove() {
184 screen_it tr-api "cd $TROVE_DIR; bin/trove-api --config-file=$TROVE_CONF_DIR/trove.conf --debug 2>&1"
185 screen_it tr-tmgr "cd $TROVE_DIR; bin/trove-taskmanager --config-file=$TROVE_CONF_DIR/trove-taskmanager.conf --debug 2>&1"
Ed Cranford1089b3a2013-09-30 11:36:55 -0500186 screen_it tr-cond "cd $TROVE_DIR; bin/trove-conductor --config-file=$TROVE_CONF_DIR/trove-conductor.conf --debug 2>&1"
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700187}
188
189# stop_trove() - Stop running processes
190function stop_trove() {
191 # Kill the trove screen windows
Ed Cranford1089b3a2013-09-30 11:36:55 -0500192 for serv in tr-api tr-tmgr tr-cond; do
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700193 screen -S $SCREEN_NAME -p $serv -X kill
194 done
195}
196
197# Restore xtrace
198$XTRACE
199
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100200# Tell emacs to use shell-script-mode
201## Local variables:
202## mode: shell-script
203## End: