blob: 8e817f51450eb8927a86f2e3c7e4d84e4d5915c7 [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
Robert Myers674ee842013-11-25 13:15:35 -060041# setup_trove_logging() - Adds logging configuration to conf files
42function setup_trove_logging() {
43 local CONF=$1
44 iniset $CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
45 iniset $CONF DEFAULT use_syslog $SYSLOG
46 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
47 # Add color to logging output
48 setup_colorized_logging $CONF DEFAULT tenant user
49 fi
50}
51
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070052# create_trove_accounts() - Set up common required trove accounts
53
54# Tenant User Roles
55# ------------------------------------------------------------------
56# service trove admin # if enabled
57
58create_trove_accounts() {
59 # Trove
60 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
61 SERVICE_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
62
63 if [[ "$ENABLED_SERVICES" =~ "trove" ]]; then
Sean Dague101b4242013-10-22 08:47:11 -040064 TROVE_USER=$(keystone user-create \
65 --name=trove \
66 --pass="$SERVICE_PASSWORD" \
Dirk Mueller25049cd2014-01-09 13:53:52 +010067 --tenant-id $SERVICE_TENANT \
Sean Dague101b4242013-10-22 08:47:11 -040068 --email=trove@example.com \
69 | grep " id " | get_field 2)
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070070 keystone user-role-add --tenant-id $SERVICE_TENANT \
Sean Dague101b4242013-10-22 08:47:11 -040071 --user-id $TROVE_USER \
72 --role-id $SERVICE_ROLE
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070073 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
74 TROVE_SERVICE=$(keystone service-create \
75 --name=trove \
76 --type=database \
77 --description="Trove Service" \
78 | grep " id " | get_field 2)
79 keystone endpoint-create \
80 --region RegionOne \
81 --service_id $TROVE_SERVICE \
82 --publicurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
83 --adminurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
84 --internalurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s"
85 fi
86 fi
87}
88
89# stack.sh entry points
90# ---------------------
91
92# cleanup_trove() - Remove residual data files, anything left over from previous
93# runs that a clean run would need to clean up
94function cleanup_trove() {
95 #Clean up dirs
96 rm -fr $TROVE_AUTH_CACHE_DIR/*
97 rm -fr $TROVE_CONF_DIR/*
98}
99
100# configure_troveclient() - Set config files, create data dirs, etc
101function configure_troveclient() {
102 setup_develop $TROVECLIENT_DIR
103}
104
105# configure_trove() - Set config files, create data dirs, etc
106function configure_trove() {
107 setup_develop $TROVE_DIR
108
109 # Create the trove conf dir and cache dirs if they don't exist
110 sudo mkdir -p ${TROVE_CONF_DIR}
111 sudo mkdir -p ${TROVE_AUTH_CACHE_DIR}
112 sudo chown -R $STACK_USER: ${TROVE_CONF_DIR}
113 sudo chown -R $STACK_USER: ${TROVE_AUTH_CACHE_DIR}
114
115 # Copy api-paste file over to the trove conf dir and configure it
116 cp $TROVE_LOCAL_CONF_DIR/api-paste.ini $TROVE_CONF_DIR/api-paste.ini
117 TROVE_API_PASTE_INI=$TROVE_CONF_DIR/api-paste.ini
118 iniset $TROVE_API_PASTE_INI filter:tokenauth auth_host $KEYSTONE_AUTH_HOST
119 iniset $TROVE_API_PASTE_INI filter:tokenauth auth_port $KEYSTONE_AUTH_PORT
120 iniset $TROVE_API_PASTE_INI filter:tokenauth auth_protocol $KEYSTONE_AUTH_PROTOCOL
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000121 iniset $TROVE_API_PASTE_INI filter:tokenauth cafile $KEYSTONE_SSL_CA
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700122 iniset $TROVE_API_PASTE_INI filter:tokenauth admin_tenant_name $SERVICE_TENANT_NAME
123 iniset $TROVE_API_PASTE_INI filter:tokenauth admin_user trove
124 iniset $TROVE_API_PASTE_INI filter:tokenauth admin_password $SERVICE_PASSWORD
125 iniset $TROVE_API_PASTE_INI filter:tokenauth signing_dir $TROVE_AUTH_CACHE_DIR
126
127 # (Re)create trove conf files
128 rm -f $TROVE_CONF_DIR/trove.conf
129 rm -f $TROVE_CONF_DIR/trove-taskmanager.conf
Ed Cranford1089b3a2013-09-30 11:36:55 -0500130 rm -f $TROVE_CONF_DIR/trove-conductor.conf
131
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700132 iniset $TROVE_CONF_DIR/trove.conf DEFAULT rabbit_password $RABBIT_PASSWORD
133 iniset $TROVE_CONF_DIR/trove.conf DEFAULT sql_connection `database_connection_url trove`
134 iniset $TROVE_CONF_DIR/trove.conf DEFAULT add_addresses True
135
136 iniset $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample DEFAULT rabbit_password $RABBIT_PASSWORD
137 iniset $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample DEFAULT sql_connection `database_connection_url trove`
Ed Cranford1089b3a2013-09-30 11:36:55 -0500138 iniset $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample DEFAULT control_exchange trove
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700139 sed -i "s/localhost/$NETWORK_GATEWAY/g" $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample
140
Robert Myers674ee842013-11-25 13:15:35 -0600141 setup_trove_logging $TROVE_CONF_DIR/trove.conf
142 setup_trove_logging $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample
143
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700144 # (Re)create trove taskmanager conf file if needed
145 if is_service_enabled tr-tmgr; then
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000146 TROVE_AUTH_ENDPOINT=$KEYSTONE_AUTH_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT//v$IDENTITY_API_VERSION
147
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700148 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT rabbit_password $RABBIT_PASSWORD
149 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT sql_connection `database_connection_url trove`
150 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT taskmanager_manager trove.taskmanager.manager.Manager
151 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_user radmin
152 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_tenant_name trove
153 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
154 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
Robert Myers674ee842013-11-25 13:15:35 -0600155 setup_trove_logging $TROVE_CONF_DIR/trove-taskmanager.conf
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700156 fi
Ed Cranford1089b3a2013-09-30 11:36:55 -0500157
158 # (Re)create trove conductor conf file if needed
159 if is_service_enabled tr-cond; then
160 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT rabbit_password $RABBIT_PASSWORD
161 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT sql_connection `database_connection_url trove`
162 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_user radmin
163 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_tenant_name trove
164 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
165 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
166 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT control_exchange trove
Robert Myers674ee842013-11-25 13:15:35 -0600167 setup_trove_logging $TROVE_CONF_DIR/trove-conductor.conf
Ed Cranford1089b3a2013-09-30 11:36:55 -0500168 fi
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700169}
170
171# install_troveclient() - Collect source and prepare
172function install_troveclient() {
173 git_clone $TROVECLIENT_REPO $TROVECLIENT_DIR $TROVECLIENT_BRANCH
174}
175
176# install_trove() - Collect source and prepare
177function install_trove() {
178 git_clone $TROVE_REPO $TROVE_DIR $TROVE_BRANCH
179}
180
181# init_trove() - Initializes Trove Database as a Service
182function init_trove() {
183 #(Re)Create trove db
184 recreate_database trove utf8
185
186 #Initialize the trove database
Michael Basnight0f9a1b02013-12-28 03:42:07 +0000187 $TROVE_BIN_DIR/trove-manage db_sync
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700188}
189
190# start_trove() - Start running processes, including screen
191function start_trove() {
Michael Basnight0f9a1b02013-12-28 03:42:07 +0000192 screen_it tr-api "cd $TROVE_DIR; $TROVE_BIN_DIR/trove-api --config-file=$TROVE_CONF_DIR/trove.conf --debug 2>&1"
193 screen_it tr-tmgr "cd $TROVE_DIR; $TROVE_BIN_DIR/trove-taskmanager --config-file=$TROVE_CONF_DIR/trove-taskmanager.conf --debug 2>&1"
194 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 -0700195}
196
197# stop_trove() - Stop running processes
198function stop_trove() {
199 # Kill the trove screen windows
Ed Cranford1089b3a2013-09-30 11:36:55 -0500200 for serv in tr-api tr-tmgr tr-cond; do
Dean Troyer9fc87922013-05-22 17:19:06 -0500201 screen_stop $serv
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700202 done
203}
204
205# Restore xtrace
206$XTRACE
207
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100208# Tell emacs to use shell-script-mode
209## Local variables:
210## mode: shell-script
211## End: