blob: b02a4b63c807a0cfcc70f90d30311848e583dda1 [file] [log] [blame]
Dean Troyer73f6f252012-09-17 11:22:21 -05001# lib/glance
2# Functions to control the configuration and operation of the Glance service
3
4# Dependencies:
5# ``functions`` file
6# ``DEST``, ``DATA_DIR`` must be defined
7# ``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
28# <define global variables here that belong to this project>
29
30# Set up default directories
31GLANCE_DIR=$DEST/glance
32GLANCECLIENT_DIR=$DEST/python-glanceclient
33GLANCE_CACHE_DIR=${GLANCE_CACHE_DIR:=$DATA_DIR/glance/cache}
34GLANCE_IMAGE_DIR=${GLANCE_IMAGE_DIR:=$DATA_DIR/glance/images}
Dean Troyerbc071bc2012-10-01 14:06:44 -050035GLANCE_AUTH_CACHE_DIR=${GLANCE_AUTH_CACHE_DIR:-/var/cache/glance}
Dean Troyer73f6f252012-09-17 11:22:21 -050036
37GLANCE_CONF_DIR=${GLANCE_CONF_DIR:-/etc/glance}
38GLANCE_REGISTRY_CONF=$GLANCE_CONF_DIR/glance-registry.conf
39GLANCE_API_CONF=$GLANCE_CONF_DIR/glance-api.conf
40GLANCE_REGISTRY_PASTE_INI=$GLANCE_CONF_DIR/glance-registry-paste.ini
41GLANCE_API_PASTE_INI=$GLANCE_CONF_DIR/glance-api-paste.ini
42GLANCE_CACHE_CONF=$GLANCE_CONF_DIR/glance-cache.conf
43GLANCE_POLICY_JSON=$GLANCE_CONF_DIR/policy.json
44
45# Support entry points installation of console scripts
46if [[ -d $GLANCE_DIR/bin ]]; then
47 GLANCE_BIN_DIR=$GLANCE_DIR/bin
48else
49 GLANCE_BIN_DIR=/usr/local/bin
50fi
51
52# Glance connection info. Note the port must be specified.
53GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$SERVICE_HOST:9292}
54
55
56# Entry Points
57# ------------
58
59# cleanup_glance() - Remove residual data files, anything left over from previous
60# runs that a clean run would need to clean up
61function cleanup_glance() {
62 # kill instances (nova)
63 # delete image files (glance)
64 # This function intentionally left blank
65 :
66}
67
68# configure_glanceclient() - Set config files, create data dirs, etc
69function configure_glanceclient() {
70 setup_develop $GLANCECLIENT_DIR
71}
72
73# configure_glance() - Set config files, create data dirs, etc
74function configure_glance() {
75 setup_develop $GLANCE_DIR
76
77 if [[ ! -d $GLANCE_CONF_DIR ]]; then
78 sudo mkdir -p $GLANCE_CONF_DIR
79 fi
80 sudo chown `whoami` $GLANCE_CONF_DIR
81
82 # Copy over our glance configurations and update them
83 cp $GLANCE_DIR/etc/glance-registry.conf $GLANCE_REGISTRY_CONF
84 iniset $GLANCE_REGISTRY_CONF DEFAULT debug True
85 inicomment $GLANCE_REGISTRY_CONF DEFAULT log_file
Terry Wilson428af5a2012-11-01 16:12:39 -040086 local dburl
87 database_connection_url dburl glance
88 iniset $GLANCE_REGISTRY_CONF DEFAULT sql_connection $dburl
Dean Troyer73f6f252012-09-17 11:22:21 -050089 iniset $GLANCE_REGISTRY_CONF DEFAULT use_syslog $SYSLOG
90 iniset $GLANCE_REGISTRY_CONF paste_deploy flavor keystone
91 iniset $GLANCE_REGISTRY_CONF keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
92 iniset $GLANCE_REGISTRY_CONF keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
93 iniset $GLANCE_REGISTRY_CONF keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
94 iniset $GLANCE_REGISTRY_CONF keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
95 iniset $GLANCE_REGISTRY_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
96 iniset $GLANCE_REGISTRY_CONF keystone_authtoken admin_user glance
97 iniset $GLANCE_REGISTRY_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
Dean Troyerbc071bc2012-10-01 14:06:44 -050098 if [[ "$KEYSTONE_TOKEN_FORMAT" == "PKI" ]]; then
99 iniset $GLANCE_REGISTRY_CONF keystone_authtoken signing_dir $GLANCE_AUTH_CACHE_DIR/registry
100 fi
Dean Troyer73f6f252012-09-17 11:22:21 -0500101
102 cp $GLANCE_DIR/etc/glance-api.conf $GLANCE_API_CONF
103 iniset $GLANCE_API_CONF DEFAULT debug True
104 inicomment $GLANCE_API_CONF DEFAULT log_file
Terry Wilson428af5a2012-11-01 16:12:39 -0400105 iniset $GLANCE_API_CONF DEFAULT sql_connection $dburl
Dean Troyer73f6f252012-09-17 11:22:21 -0500106 iniset $GLANCE_API_CONF DEFAULT use_syslog $SYSLOG
107 iniset $GLANCE_API_CONF DEFAULT filesystem_store_datadir $GLANCE_IMAGE_DIR/
108 iniset $GLANCE_API_CONF DEFAULT image_cache_dir $GLANCE_CACHE_DIR/
109 iniset $GLANCE_API_CONF paste_deploy flavor keystone+cachemanagement
110 iniset $GLANCE_API_CONF keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
111 iniset $GLANCE_API_CONF keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
112 iniset $GLANCE_API_CONF keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
113 iniset $GLANCE_API_CONF keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
114 iniset $GLANCE_API_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
115 iniset $GLANCE_API_CONF keystone_authtoken admin_user glance
116 iniset $GLANCE_API_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
Eoghan Glynnad80ead2012-09-27 09:36:33 +0100117 if is_service_enabled qpid; then
118 iniset $GLANCE_API_CONF DEFAULT notifier_strategy qpid
119 elif [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then
120 iniset $GLANCE_API_CONF DEFAULT notifier_strategy rabbit
121 iniset $GLANCE_API_CONF DEFAULT rabbit_host $RABBIT_HOST
122 iniset $GLANCE_API_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
123 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500124 if [[ "$KEYSTONE_TOKEN_FORMAT" == "PKI" ]]; then
125 iniset $GLANCE_API_CONF keystone_authtoken signing_dir $GLANCE_AUTH_CACHE_DIR/api
126 fi
Dean Troyer73f6f252012-09-17 11:22:21 -0500127
128 cp -p $GLANCE_DIR/etc/glance-registry-paste.ini $GLANCE_REGISTRY_PASTE_INI
129
130 cp -p $GLANCE_DIR/etc/glance-api-paste.ini $GLANCE_API_PASTE_INI
131
132 cp $GLANCE_DIR/etc/glance-cache.conf $GLANCE_CACHE_CONF
133 iniset $GLANCE_CACHE_CONF DEFAULT debug True
134 inicomment $GLANCE_CACHE_CONF DEFAULT log_file
135 iniset $GLANCE_CACHE_CONF DEFAULT use_syslog $SYSLOG
136 iniset $GLANCE_CACHE_CONF DEFAULT filesystem_store_datadir $GLANCE_IMAGE_DIR/
137 iniset $GLANCE_CACHE_CONF DEFAULT image_cache_dir $GLANCE_CACHE_DIR/
138 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_url
139 iniset $GLANCE_CACHE_CONF DEFAULT auth_url $KEYSTONE_AUTH_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0
140 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_tenant_name
141 iniset $GLANCE_CACHE_CONF DEFAULT admin_tenant_name $SERVICE_TENANT_NAME
142 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_user
143 iniset $GLANCE_CACHE_CONF DEFAULT admin_user glance
144 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_password
145 iniset $GLANCE_CACHE_CONF DEFAULT admin_password $SERVICE_PASSWORD
146
147 cp -p $GLANCE_DIR/etc/policy.json $GLANCE_POLICY_JSON
148
149}
150
151# init_glance() - Initialize databases, etc.
152function init_glance() {
153 # Delete existing images
154 rm -rf $GLANCE_IMAGE_DIR
155 mkdir -p $GLANCE_IMAGE_DIR
156
157 # Delete existing cache
158 rm -rf $GLANCE_CACHE_DIR
159 mkdir -p $GLANCE_CACHE_DIR
160
161 # (re)create glance database
Terry Wilson428af5a2012-11-01 16:12:39 -0400162 recreate_database glance utf8
Dean Troyer73f6f252012-09-17 11:22:21 -0500163
164 $GLANCE_BIN_DIR/glance-manage db_sync
Dean Troyerbc071bc2012-10-01 14:06:44 -0500165
166 if [[ "$KEYSTONE_TOKEN_FORMAT" == "PKI" ]]; then
167 # Create cache dir
168 sudo mkdir -p $GLANCE_AUTH_CACHE_DIR/api
169 sudo chown `whoami` $GLANCE_AUTH_CACHE_DIR/api
170 sudo mkdir -p $GLANCE_AUTH_CACHE_DIR/registry
171 sudo chown `whoami` $GLANCE_AUTH_CACHE_DIR/registry
172 fi
Dean Troyer73f6f252012-09-17 11:22:21 -0500173}
174
175# install_glanceclient() - Collect source and prepare
176function install_glanceclient() {
177 git_clone $GLANCECLIENT_REPO $GLANCECLIENT_DIR $GLANCECLIENT_BRANCH
178}
179
180# install_glance() - Collect source and prepare
181function install_glance() {
182 git_clone $GLANCE_REPO $GLANCE_DIR $GLANCE_BRANCH
183}
184
185# start_glance() - Start running processes, including screen
186function start_glance() {
187 screen_it g-reg "cd $GLANCE_DIR; $GLANCE_BIN_DIR/glance-registry --config-file=$GLANCE_CONF_DIR/glance-registry.conf"
188 screen_it g-api "cd $GLANCE_DIR; $GLANCE_BIN_DIR/glance-api --config-file=$GLANCE_CONF_DIR/glance-api.conf"
189 echo "Waiting for g-api ($GLANCE_HOSTPORT) to start..."
190 if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://$GLANCE_HOSTPORT; do sleep 1; done"; then
191 echo "g-api did not start"
192 exit 1
193 fi
194}
195
Dean Troyer699a29f2012-09-10 14:10:27 -0500196# stop_glance() - Stop running processes
Dean Troyer73f6f252012-09-17 11:22:21 -0500197function stop_glance() {
198 # Kill the Glance screen windows
199 screen -S $SCREEN_NAME -p g-api -X kill
200 screen -S $SCREEN_NAME -p g-reg -X kill
201}
202
203# Restore xtrace
204$XTRACE