blob: 75e3dd053df1b5a9386d1b68b7744fe296739ed5 [file] [log] [blame]
Dean Troyer73f6f252012-09-17 11:22:21 -05001# lib/glance
Dean Troyer6d04fd72012-12-21 11:03:37 -06002# Functions to control the configuration and operation of the **Glance** service
Dean Troyer73f6f252012-09-17 11:22:21 -05003
4# Dependencies:
5# ``functions`` file
Attila Fazekas91b8d132013-01-06 22:40:09 +01006# ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined
Dean Troyer73f6f252012-09-17 11:22:21 -05007# ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined
8# ``SERVICE_HOST``
Dean Troyerbc071bc2012-10-01 14:06:44 -05009# ``KEYSTONE_TOKEN_FORMAT`` must be defined
Dean Troyer73f6f252012-09-17 11:22:21 -050010
11# ``stack.sh`` calls the entry points in this order:
12#
13# install_glance
14# configure_glance
15# init_glance
16# start_glance
17# stop_glance
18# cleanup_glance
19
20# Save trace setting
21XTRACE=$(set +o | grep xtrace)
22set +o xtrace
23
24
25# Defaults
26# --------
27
Dean Troyer73f6f252012-09-17 11:22:21 -050028# Set up default directories
29GLANCE_DIR=$DEST/glance
30GLANCECLIENT_DIR=$DEST/python-glanceclient
31GLANCE_CACHE_DIR=${GLANCE_CACHE_DIR:=$DATA_DIR/glance/cache}
32GLANCE_IMAGE_DIR=${GLANCE_IMAGE_DIR:=$DATA_DIR/glance/images}
Dean Troyerbc071bc2012-10-01 14:06:44 -050033GLANCE_AUTH_CACHE_DIR=${GLANCE_AUTH_CACHE_DIR:-/var/cache/glance}
Dean Troyer73f6f252012-09-17 11:22:21 -050034
35GLANCE_CONF_DIR=${GLANCE_CONF_DIR:-/etc/glance}
36GLANCE_REGISTRY_CONF=$GLANCE_CONF_DIR/glance-registry.conf
37GLANCE_API_CONF=$GLANCE_CONF_DIR/glance-api.conf
38GLANCE_REGISTRY_PASTE_INI=$GLANCE_CONF_DIR/glance-registry-paste.ini
39GLANCE_API_PASTE_INI=$GLANCE_CONF_DIR/glance-api-paste.ini
40GLANCE_CACHE_CONF=$GLANCE_CONF_DIR/glance-cache.conf
41GLANCE_POLICY_JSON=$GLANCE_CONF_DIR/policy.json
Dirk Mueller46d1ba62013-09-09 14:31:37 +020042GLANCE_SCHEMA_JSON=$GLANCE_CONF_DIR/schema-image.json
Dean Troyer73f6f252012-09-17 11:22:21 -050043
44# Support entry points installation of console scripts
45if [[ -d $GLANCE_DIR/bin ]]; then
46 GLANCE_BIN_DIR=$GLANCE_DIR/bin
47else
Jakub Ruzicka4196d552013-01-30 15:35:54 +010048 GLANCE_BIN_DIR=$(get_python_exec_prefix)
Dean Troyer73f6f252012-09-17 11:22:21 -050049fi
50
51# Glance connection info. Note the port must be specified.
52GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$SERVICE_HOST:9292}
53
54
Dean Troyercc6b4432013-04-08 15:38:03 -050055# Functions
56# ---------
Dean Troyer73f6f252012-09-17 11:22:21 -050057
58# cleanup_glance() - Remove residual data files, anything left over from previous
59# runs that a clean run would need to clean up
60function cleanup_glance() {
61 # kill instances (nova)
62 # delete image files (glance)
Dean Troyer995eb922013-03-07 16:11:40 -060063 sudo rm -rf $GLANCE_CACHE_DIR $GLANCE_IMAGE_DIR $GLANCE_AUTH_CACHE_DIR
Dean Troyer73f6f252012-09-17 11:22:21 -050064}
65
Dean Troyer73f6f252012-09-17 11:22:21 -050066# configure_glance() - Set config files, create data dirs, etc
67function configure_glance() {
Dean Troyer73f6f252012-09-17 11:22:21 -050068 if [[ ! -d $GLANCE_CONF_DIR ]]; then
69 sudo mkdir -p $GLANCE_CONF_DIR
70 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +010071 sudo chown $STACK_USER $GLANCE_CONF_DIR
Dean Troyer73f6f252012-09-17 11:22:21 -050072
73 # Copy over our glance configurations and update them
74 cp $GLANCE_DIR/etc/glance-registry.conf $GLANCE_REGISTRY_CONF
Ben Nemec03997942013-08-10 09:56:16 -050075 iniset $GLANCE_REGISTRY_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Dean Troyer73f6f252012-09-17 11:22:21 -050076 inicomment $GLANCE_REGISTRY_CONF DEFAULT log_file
Attila Fazekas7e79d912013-03-03 12:23:04 +010077 local dburl=`database_connection_url glance`
Terry Wilson428af5a2012-11-01 16:12:39 -040078 iniset $GLANCE_REGISTRY_CONF DEFAULT sql_connection $dburl
Dean Troyer73f6f252012-09-17 11:22:21 -050079 iniset $GLANCE_REGISTRY_CONF DEFAULT use_syslog $SYSLOG
80 iniset $GLANCE_REGISTRY_CONF paste_deploy flavor keystone
81 iniset $GLANCE_REGISTRY_CONF keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
82 iniset $GLANCE_REGISTRY_CONF keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
83 iniset $GLANCE_REGISTRY_CONF keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
84 iniset $GLANCE_REGISTRY_CONF keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
85 iniset $GLANCE_REGISTRY_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
86 iniset $GLANCE_REGISTRY_CONF keystone_authtoken admin_user glance
87 iniset $GLANCE_REGISTRY_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +090088 iniset $GLANCE_REGISTRY_CONF keystone_authtoken signing_dir $GLANCE_AUTH_CACHE_DIR/registry
Dean Troyer73f6f252012-09-17 11:22:21 -050089
90 cp $GLANCE_DIR/etc/glance-api.conf $GLANCE_API_CONF
Ben Nemec03997942013-08-10 09:56:16 -050091 iniset $GLANCE_API_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Dean Troyer73f6f252012-09-17 11:22:21 -050092 inicomment $GLANCE_API_CONF DEFAULT log_file
Terry Wilson428af5a2012-11-01 16:12:39 -040093 iniset $GLANCE_API_CONF DEFAULT sql_connection $dburl
Dean Troyer73f6f252012-09-17 11:22:21 -050094 iniset $GLANCE_API_CONF DEFAULT use_syslog $SYSLOG
95 iniset $GLANCE_API_CONF DEFAULT filesystem_store_datadir $GLANCE_IMAGE_DIR/
96 iniset $GLANCE_API_CONF DEFAULT image_cache_dir $GLANCE_CACHE_DIR/
97 iniset $GLANCE_API_CONF paste_deploy flavor keystone+cachemanagement
98 iniset $GLANCE_API_CONF keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
99 iniset $GLANCE_API_CONF keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
100 iniset $GLANCE_API_CONF keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
101 iniset $GLANCE_API_CONF keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
102 iniset $GLANCE_API_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
103 iniset $GLANCE_API_CONF keystone_authtoken admin_user glance
104 iniset $GLANCE_API_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
Eoghan Glynnad80ead2012-09-27 09:36:33 +0100105 if is_service_enabled qpid; then
106 iniset $GLANCE_API_CONF DEFAULT notifier_strategy qpid
107 elif [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then
108 iniset $GLANCE_API_CONF DEFAULT notifier_strategy rabbit
Eoghan Glynnad80ead2012-09-27 09:36:33 +0100109 fi
Eoghan Glynn8c11f562013-03-01 12:09:01 +0000110 iniset_rpc_backend glance $GLANCE_API_CONF DEFAULT
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900111 iniset $GLANCE_API_CONF keystone_authtoken signing_dir $GLANCE_AUTH_CACHE_DIR/api
Mate Lakatbc2ef922013-08-15 18:06:59 +0100112 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
113 iniset $GLANCE_API_CONF DEFAULT container_formats "ami,ari,aki,bare,ovf,tgz"
114 iniset $GLANCE_API_CONF DEFAULT disk_formats "ami,ari,aki,vhd,raw,iso"
115 fi
Dean Troyer73f6f252012-09-17 11:22:21 -0500116
Dean Troyerc77b9322013-03-29 10:51:01 -0500117 # Store the images in swift if enabled.
118 if is_service_enabled s-proxy; then
119 iniset $GLANCE_API_CONF DEFAULT default_store swift
120 iniset $GLANCE_API_CONF DEFAULT swift_store_auth_address $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0/
121 iniset $GLANCE_API_CONF DEFAULT swift_store_user $SERVICE_TENANT_NAME:glance
122 iniset $GLANCE_API_CONF DEFAULT swift_store_key $SERVICE_PASSWORD
123 iniset $GLANCE_API_CONF DEFAULT swift_store_create_container_on_put True
124 fi
125
Dean Troyer73f6f252012-09-17 11:22:21 -0500126 cp -p $GLANCE_DIR/etc/glance-registry-paste.ini $GLANCE_REGISTRY_PASTE_INI
127
128 cp -p $GLANCE_DIR/etc/glance-api-paste.ini $GLANCE_API_PASTE_INI
129
130 cp $GLANCE_DIR/etc/glance-cache.conf $GLANCE_CACHE_CONF
Ben Nemec03997942013-08-10 09:56:16 -0500131 iniset $GLANCE_CACHE_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Dean Troyer73f6f252012-09-17 11:22:21 -0500132 inicomment $GLANCE_CACHE_CONF DEFAULT log_file
133 iniset $GLANCE_CACHE_CONF DEFAULT use_syslog $SYSLOG
134 iniset $GLANCE_CACHE_CONF DEFAULT filesystem_store_datadir $GLANCE_IMAGE_DIR/
135 iniset $GLANCE_CACHE_CONF DEFAULT image_cache_dir $GLANCE_CACHE_DIR/
136 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_url
137 iniset $GLANCE_CACHE_CONF DEFAULT auth_url $KEYSTONE_AUTH_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0
138 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_tenant_name
139 iniset $GLANCE_CACHE_CONF DEFAULT admin_tenant_name $SERVICE_TENANT_NAME
140 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_user
141 iniset $GLANCE_CACHE_CONF DEFAULT admin_user glance
142 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_password
143 iniset $GLANCE_CACHE_CONF DEFAULT admin_password $SERVICE_PASSWORD
144
145 cp -p $GLANCE_DIR/etc/policy.json $GLANCE_POLICY_JSON
Dirk Mueller46d1ba62013-09-09 14:31:37 +0200146 cp -p $GLANCE_DIR/etc/schema-image.json $GLANCE_SCHEMA_JSON
Dean Troyer73f6f252012-09-17 11:22:21 -0500147}
148
Dean Troyerf03bafe2013-02-12 10:58:28 -0600149# create_glance_cache_dir() - Part of the init_glance() process
150function create_glance_cache_dir() {
151 # Create cache dir
152 sudo mkdir -p $GLANCE_AUTH_CACHE_DIR/api
153 sudo chown $STACK_USER $GLANCE_AUTH_CACHE_DIR/api
154 rm -f $GLANCE_AUTH_CACHE_DIR/api/*
155 sudo mkdir -p $GLANCE_AUTH_CACHE_DIR/registry
156 sudo chown $STACK_USER $GLANCE_AUTH_CACHE_DIR/registry
157 rm -f $GLANCE_AUTH_CACHE_DIR/registry/*
158}
159
Dean Troyer73f6f252012-09-17 11:22:21 -0500160# init_glance() - Initialize databases, etc.
161function init_glance() {
162 # Delete existing images
163 rm -rf $GLANCE_IMAGE_DIR
164 mkdir -p $GLANCE_IMAGE_DIR
165
166 # Delete existing cache
167 rm -rf $GLANCE_CACHE_DIR
168 mkdir -p $GLANCE_CACHE_DIR
169
Dean Troyerf03bafe2013-02-12 10:58:28 -0600170 # (Re)create glance database
Terry Wilson428af5a2012-11-01 16:12:39 -0400171 recreate_database glance utf8
Dean Troyer73f6f252012-09-17 11:22:21 -0500172
Dean Troyerf03bafe2013-02-12 10:58:28 -0600173 # Migrate glance database
Dean Troyer73f6f252012-09-17 11:22:21 -0500174 $GLANCE_BIN_DIR/glance-manage db_sync
Dean Troyerbc071bc2012-10-01 14:06:44 -0500175
Dean Troyerf03bafe2013-02-12 10:58:28 -0600176 create_glance_cache_dir
Dean Troyer73f6f252012-09-17 11:22:21 -0500177}
178
179# install_glanceclient() - Collect source and prepare
180function install_glanceclient() {
181 git_clone $GLANCECLIENT_REPO $GLANCECLIENT_DIR $GLANCECLIENT_BRANCH
Sean Daguee4f0cd72013-04-01 15:56:07 -0400182 setup_develop $GLANCECLIENT_DIR
Dean Troyer73f6f252012-09-17 11:22:21 -0500183}
184
185# install_glance() - Collect source and prepare
186function install_glance() {
187 git_clone $GLANCE_REPO $GLANCE_DIR $GLANCE_BRANCH
Sean Daguee4f0cd72013-04-01 15:56:07 -0400188 setup_develop $GLANCE_DIR
Dean Troyer73f6f252012-09-17 11:22:21 -0500189}
190
191# start_glance() - Start running processes, including screen
192function start_glance() {
193 screen_it g-reg "cd $GLANCE_DIR; $GLANCE_BIN_DIR/glance-registry --config-file=$GLANCE_CONF_DIR/glance-registry.conf"
194 screen_it g-api "cd $GLANCE_DIR; $GLANCE_BIN_DIR/glance-api --config-file=$GLANCE_CONF_DIR/glance-api.conf"
195 echo "Waiting for g-api ($GLANCE_HOSTPORT) to start..."
JUN JIE NAN0aa85342013-09-13 15:47:09 +0800196 if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q -O- http://$GLANCE_HOSTPORT; do sleep 1; done"; then
Sean Dague101b4242013-10-22 08:47:11 -0400197 die $LINENO "g-api did not start"
Dean Troyer73f6f252012-09-17 11:22:21 -0500198 fi
199}
200
Dean Troyer699a29f2012-09-10 14:10:27 -0500201# stop_glance() - Stop running processes
Dean Troyer73f6f252012-09-17 11:22:21 -0500202function stop_glance() {
203 # Kill the Glance screen windows
204 screen -S $SCREEN_NAME -p g-api -X kill
205 screen -S $SCREEN_NAME -p g-reg -X kill
206}
207
Dean Troyercc6b4432013-04-08 15:38:03 -0500208
Dean Troyer73f6f252012-09-17 11:22:21 -0500209# Restore xtrace
210$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400211
212# Local variables:
213# mode: shell-script
214# End: