blob: 9c910242115f4f2f3afba4572d8896030b3216f1 [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
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070032TROVE_AUTH_CACHE_DIR=${TROVE_AUTH_CACHE_DIR:-/var/cache/trove}
Michael Basnight0f9a1b02013-12-28 03:42:07 +000033
34# Support entry points installation of console scripts
35if [[ -d $TROVE_DIR/bin ]]; then
36 TROVE_BIN_DIR=$TROVE_DIR/bin
37else
38 TROVE_BIN_DIR=$(get_python_exec_prefix)
39fi
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070040
Dean Troyerfc744f92014-01-27 13:45:21 -060041# Functions
42# ---------
43
44# Test if any Trove services are enabled
45# is_trove_enabled
46function is_trove_enabled {
47 [[ ,${ENABLED_SERVICES} =~ ,"tr-" ]] && return 0
48 return 1
49}
50
Robert Myers674ee842013-11-25 13:15:35 -060051# setup_trove_logging() - Adds logging configuration to conf files
52function setup_trove_logging() {
53 local CONF=$1
54 iniset $CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
55 iniset $CONF DEFAULT use_syslog $SYSLOG
56 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
57 # Add color to logging output
58 setup_colorized_logging $CONF DEFAULT tenant user
59 fi
60}
61
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070062# create_trove_accounts() - Set up common required trove accounts
63
64# Tenant User Roles
65# ------------------------------------------------------------------
66# service trove admin # if enabled
67
68create_trove_accounts() {
69 # Trove
70 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
71 SERVICE_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
72
73 if [[ "$ENABLED_SERVICES" =~ "trove" ]]; then
Sean Dague101b4242013-10-22 08:47:11 -040074 TROVE_USER=$(keystone user-create \
75 --name=trove \
76 --pass="$SERVICE_PASSWORD" \
Dirk Mueller25049cd2014-01-09 13:53:52 +010077 --tenant-id $SERVICE_TENANT \
Sean Dague101b4242013-10-22 08:47:11 -040078 --email=trove@example.com \
79 | grep " id " | get_field 2)
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070080 keystone user-role-add --tenant-id $SERVICE_TENANT \
Sean Dague101b4242013-10-22 08:47:11 -040081 --user-id $TROVE_USER \
82 --role-id $SERVICE_ROLE
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070083 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
84 TROVE_SERVICE=$(keystone service-create \
85 --name=trove \
86 --type=database \
87 --description="Trove Service" \
88 | grep " id " | get_field 2)
89 keystone endpoint-create \
90 --region RegionOne \
91 --service_id $TROVE_SERVICE \
92 --publicurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
93 --adminurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
94 --internalurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s"
95 fi
96 fi
97}
98
99# stack.sh entry points
100# ---------------------
101
102# cleanup_trove() - Remove residual data files, anything left over from previous
103# runs that a clean run would need to clean up
104function cleanup_trove() {
105 #Clean up dirs
106 rm -fr $TROVE_AUTH_CACHE_DIR/*
107 rm -fr $TROVE_CONF_DIR/*
108}
109
110# configure_troveclient() - Set config files, create data dirs, etc
111function configure_troveclient() {
112 setup_develop $TROVECLIENT_DIR
113}
114
115# configure_trove() - Set config files, create data dirs, etc
116function configure_trove() {
117 setup_develop $TROVE_DIR
118
119 # Create the trove conf dir and cache dirs if they don't exist
120 sudo mkdir -p ${TROVE_CONF_DIR}
121 sudo mkdir -p ${TROVE_AUTH_CACHE_DIR}
122 sudo chown -R $STACK_USER: ${TROVE_CONF_DIR}
123 sudo chown -R $STACK_USER: ${TROVE_AUTH_CACHE_DIR}
124
125 # Copy api-paste file over to the trove conf dir and configure it
126 cp $TROVE_LOCAL_CONF_DIR/api-paste.ini $TROVE_CONF_DIR/api-paste.ini
127 TROVE_API_PASTE_INI=$TROVE_CONF_DIR/api-paste.ini
128 iniset $TROVE_API_PASTE_INI filter:tokenauth auth_host $KEYSTONE_AUTH_HOST
129 iniset $TROVE_API_PASTE_INI filter:tokenauth auth_port $KEYSTONE_AUTH_PORT
130 iniset $TROVE_API_PASTE_INI filter:tokenauth auth_protocol $KEYSTONE_AUTH_PROTOCOL
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000131 iniset $TROVE_API_PASTE_INI filter:tokenauth cafile $KEYSTONE_SSL_CA
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700132 iniset $TROVE_API_PASTE_INI filter:tokenauth admin_tenant_name $SERVICE_TENANT_NAME
133 iniset $TROVE_API_PASTE_INI filter:tokenauth admin_user trove
134 iniset $TROVE_API_PASTE_INI filter:tokenauth admin_password $SERVICE_PASSWORD
135 iniset $TROVE_API_PASTE_INI filter:tokenauth signing_dir $TROVE_AUTH_CACHE_DIR
136
137 # (Re)create trove conf files
138 rm -f $TROVE_CONF_DIR/trove.conf
139 rm -f $TROVE_CONF_DIR/trove-taskmanager.conf
Ed Cranford1089b3a2013-09-30 11:36:55 -0500140 rm -f $TROVE_CONF_DIR/trove-conductor.conf
141
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700142 iniset $TROVE_CONF_DIR/trove.conf DEFAULT rabbit_password $RABBIT_PASSWORD
143 iniset $TROVE_CONF_DIR/trove.conf DEFAULT sql_connection `database_connection_url trove`
144 iniset $TROVE_CONF_DIR/trove.conf DEFAULT add_addresses True
145
146 iniset $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample DEFAULT rabbit_password $RABBIT_PASSWORD
147 iniset $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample DEFAULT sql_connection `database_connection_url trove`
Ed Cranford1089b3a2013-09-30 11:36:55 -0500148 iniset $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample DEFAULT control_exchange trove
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700149 sed -i "s/localhost/$NETWORK_GATEWAY/g" $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample
150
Robert Myers674ee842013-11-25 13:15:35 -0600151 setup_trove_logging $TROVE_CONF_DIR/trove.conf
152 setup_trove_logging $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample
153
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700154 # (Re)create trove taskmanager conf file if needed
155 if is_service_enabled tr-tmgr; then
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000156 TROVE_AUTH_ENDPOINT=$KEYSTONE_AUTH_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT//v$IDENTITY_API_VERSION
157
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700158 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT rabbit_password $RABBIT_PASSWORD
159 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT sql_connection `database_connection_url trove`
160 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT taskmanager_manager trove.taskmanager.manager.Manager
161 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_user radmin
162 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_tenant_name trove
163 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
164 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
Robert Myers674ee842013-11-25 13:15:35 -0600165 setup_trove_logging $TROVE_CONF_DIR/trove-taskmanager.conf
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700166 fi
Ed Cranford1089b3a2013-09-30 11:36:55 -0500167
168 # (Re)create trove conductor conf file if needed
169 if is_service_enabled tr-cond; then
170 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT rabbit_password $RABBIT_PASSWORD
171 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT sql_connection `database_connection_url trove`
172 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_user radmin
173 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_tenant_name trove
174 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
175 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
176 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT control_exchange trove
Robert Myers674ee842013-11-25 13:15:35 -0600177 setup_trove_logging $TROVE_CONF_DIR/trove-conductor.conf
Ed Cranford1089b3a2013-09-30 11:36:55 -0500178 fi
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700179}
180
181# install_troveclient() - Collect source and prepare
182function install_troveclient() {
183 git_clone $TROVECLIENT_REPO $TROVECLIENT_DIR $TROVECLIENT_BRANCH
184}
185
186# install_trove() - Collect source and prepare
187function install_trove() {
188 git_clone $TROVE_REPO $TROVE_DIR $TROVE_BRANCH
189}
190
191# init_trove() - Initializes Trove Database as a Service
192function init_trove() {
193 #(Re)Create trove db
194 recreate_database trove utf8
195
196 #Initialize the trove database
Michael Basnight0f9a1b02013-12-28 03:42:07 +0000197 $TROVE_BIN_DIR/trove-manage db_sync
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700198}
199
200# start_trove() - Start running processes, including screen
201function start_trove() {
Michael Basnight0f9a1b02013-12-28 03:42:07 +0000202 screen_it tr-api "cd $TROVE_DIR; $TROVE_BIN_DIR/trove-api --config-file=$TROVE_CONF_DIR/trove.conf --debug 2>&1"
203 screen_it tr-tmgr "cd $TROVE_DIR; $TROVE_BIN_DIR/trove-taskmanager --config-file=$TROVE_CONF_DIR/trove-taskmanager.conf --debug 2>&1"
204 screen_it tr-cond "cd $TROVE_DIR; $TROVE_BIN_DIR/trove-conductor --config-file=$TROVE_CONF_DIR/trove-conductor.conf --debug 2>&1"
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700205}
206
207# stop_trove() - Stop running processes
208function stop_trove() {
209 # Kill the trove screen windows
Ed Cranford1089b3a2013-09-30 11:36:55 -0500210 for serv in tr-api tr-tmgr tr-cond; do
Dean Troyer9fc87922013-05-22 17:19:06 -0500211 screen_stop $serv
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700212 done
213}
214
215# Restore xtrace
216$XTRACE
217
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100218# Tell emacs to use shell-script-mode
219## Local variables:
220## mode: shell-script
221## End: