blob: 95d2450da778c31896300e115e92f808dddd7306 [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Dean Troyer73f6f252012-09-17 11:22:21 -05003# lib/glance
Dean Troyer6d04fd72012-12-21 11:03:37 -06004# Functions to control the configuration and operation of the **Glance** service
Dean Troyer73f6f252012-09-17 11:22:21 -05005
6# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01007#
8# - ``functions`` file
9# - ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined
10# - ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined
11# - ``SERVICE_HOST``
12# - ``KEYSTONE_TOKEN_FORMAT`` must be defined
Dean Troyer73f6f252012-09-17 11:22:21 -050013
14# ``stack.sh`` calls the entry points in this order:
15#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010016# - install_glance
17# - configure_glance
18# - init_glance
19# - start_glance
20# - stop_glance
21# - cleanup_glance
Dean Troyer73f6f252012-09-17 11:22:21 -050022
23# Save trace setting
Ian Wienand523f4882015-10-13 11:03:03 +110024_XTRACE_GLANCE=$(set +o | grep xtrace)
Dean Troyer73f6f252012-09-17 11:22:21 -050025set +o xtrace
26
27
28# Defaults
29# --------
30
Dean Troyer73f6f252012-09-17 11:22:21 -050031# Set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050032GITDIR["python-glanceclient"]=$DEST/python-glanceclient
Sean Dagueaecd1892014-11-19 15:19:51 -050033GITDIR["glance_store"]=$DEST/glance_store
Dean Troyer73f6f252012-09-17 11:22:21 -050034GLANCE_DIR=$DEST/glance
Dean Troyeraed60792015-02-17 15:38:16 -060035
36# Glance virtual environment
37if [[ ${USE_VENV} = True ]]; then
38 PROJECT_VENV["glance"]=${GLANCE_DIR}.venv
39 GLANCE_BIN_DIR=${PROJECT_VENV["glance"]}/bin
40else
41 GLANCE_BIN_DIR=$(get_python_exec_prefix)
42fi
43
Dean Troyer73f6f252012-09-17 11:22:21 -050044GLANCE_CACHE_DIR=${GLANCE_CACHE_DIR:=$DATA_DIR/glance/cache}
45GLANCE_IMAGE_DIR=${GLANCE_IMAGE_DIR:=$DATA_DIR/glance/images}
Matthew Treinishfa898f52017-04-25 01:30:10 -040046GLANCE_LOCK_DIR=${GLANCE_LOCK_DIR:=$DATA_DIR/glance/locks}
Ian Wienand1f82f432017-10-04 09:51:02 +110047GLANCE_AUTH_CACHE_DIR=${GLANCE_AUTH_CACHE_DIR:-/var/cache/glance}
Dean Troyer73f6f252012-09-17 11:22:21 -050048
49GLANCE_CONF_DIR=${GLANCE_CONF_DIR:-/etc/glance}
Pawel Koniszewski76e39252014-09-06 07:06:46 -040050GLANCE_METADEF_DIR=$GLANCE_CONF_DIR/metadefs
Dean Troyer73f6f252012-09-17 11:22:21 -050051GLANCE_REGISTRY_CONF=$GLANCE_CONF_DIR/glance-registry.conf
52GLANCE_API_CONF=$GLANCE_CONF_DIR/glance-api.conf
53GLANCE_REGISTRY_PASTE_INI=$GLANCE_CONF_DIR/glance-registry-paste.ini
54GLANCE_API_PASTE_INI=$GLANCE_CONF_DIR/glance-api-paste.ini
55GLANCE_CACHE_CONF=$GLANCE_CONF_DIR/glance-cache.conf
56GLANCE_POLICY_JSON=$GLANCE_CONF_DIR/policy.json
Dirk Mueller46d1ba62013-09-09 14:31:37 +020057GLANCE_SCHEMA_JSON=$GLANCE_CONF_DIR/schema-image.json
Jamie Lennoxf4f01c62015-06-19 02:52:41 +000058GLANCE_SWIFT_STORE_CONF=$GLANCE_CONF_DIR/glance-swift-store.conf
bhagyashris6a25fb92017-12-14 13:23:41 +053059GLANCE_IMAGE_IMPORT_CONF=$GLANCE_CONF_DIR/glance-image-import.conf
Matt Riedemann80e82ea2016-07-15 22:53:17 -040060GLANCE_V1_ENABLED=${GLANCE_V1_ENABLED:-False}
Dean Troyer73f6f252012-09-17 11:22:21 -050061
Sean Daguef3b2f4c2017-04-13 10:11:48 -040062if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -040063 GLANCE_SERVICE_PROTOCOL="https"
64fi
65
Dean Troyer73f6f252012-09-17 11:22:21 -050066# Glance connection info. Note the port must be specified.
Rob Crittenden18d47782014-03-19 17:47:42 -040067GLANCE_SERVICE_HOST=${GLANCE_SERVICE_HOST:-$SERVICE_HOST}
Brian Haley180f5eb2015-06-16 13:14:31 -040068GLANCE_SERVICE_LISTEN_ADDRESS=${GLANCE_SERVICE_LISTEN_ADDRESS:-$SERVICE_LISTEN_ADDRESS}
Rob Crittenden18d47782014-03-19 17:47:42 -040069GLANCE_SERVICE_PORT=${GLANCE_SERVICE_PORT:-9292}
70GLANCE_SERVICE_PORT_INT=${GLANCE_SERVICE_PORT_INT:-19292}
71GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$GLANCE_SERVICE_HOST:$GLANCE_SERVICE_PORT}
72GLANCE_SERVICE_PROTOCOL=${GLANCE_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
73GLANCE_REGISTRY_PORT=${GLANCE_REGISTRY_PORT:-9191}
74GLANCE_REGISTRY_PORT_INT=${GLANCE_REGISTRY_PORT_INT:-19191}
Matthew Treinish1fa65362017-06-23 22:32:37 +000075GLANCE_UWSGI=$GLANCE_BIN_DIR/glance-wsgi-api
Jeremy Liu2f7df512017-07-12 10:09:48 +080076GLANCE_UWSGI_CONF=$GLANCE_CONF_DIR/glance-uwsgi.ini
Matthew Treinish1fa65362017-06-23 22:32:37 +000077# If wsgi mode is uwsgi run glance under uwsgi, else default to eventlet
78# TODO(mtreinish): Remove the eventlet path here and in all the similar
79# conditionals below after the Pike release
80if [[ "$WSGI_MODE" == "uwsgi" ]]; then
81 GLANCE_URL="$GLANCE_SERVICE_PROTOCOL://$GLANCE_SERVICE_HOST/image"
82else
83 GLANCE_URL="$GLANCE_SERVICE_PROTOCOL://$GLANCE_HOSTPORT"
84fi
Dean Troyer73f6f252012-09-17 11:22:21 -050085
Dean Troyercc6b4432013-04-08 15:38:03 -050086# Functions
87# ---------
Dean Troyer73f6f252012-09-17 11:22:21 -050088
Dean Troyere4fa7212014-01-15 15:04:49 -060089# Test if any Glance services are enabled
90# is_glance_enabled
91function is_glance_enabled {
Clark Boylan902158b2017-05-30 14:11:09 -070092 [[ ,${DISABLED_SERVICES} =~ ,"glance" ]] && return 1
Dean Troyere4fa7212014-01-15 15:04:49 -060093 [[ ,${ENABLED_SERVICES} =~ ,"g-" ]] && return 0
94 return 1
95}
96
Dean Troyer73f6f252012-09-17 11:22:21 -050097# cleanup_glance() - Remove residual data files, anything left over from previous
98# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +110099function cleanup_glance {
Dean Troyer73f6f252012-09-17 11:22:21 -0500100 # kill instances (nova)
101 # delete image files (glance)
Ian Wienand1f82f432017-10-04 09:51:02 +1100102 sudo rm -rf $GLANCE_CACHE_DIR $GLANCE_IMAGE_DIR $GLANCE_AUTH_CACHE_DIR
Dean Troyer73f6f252012-09-17 11:22:21 -0500103}
104
Dean Troyer73f6f252012-09-17 11:22:21 -0500105# configure_glance() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100106function configure_glance {
Dean Troyer8421c2b2015-03-16 13:52:19 -0500107 sudo install -d -o $STACK_USER $GLANCE_CONF_DIR $GLANCE_METADEF_DIR
Pawel Koniszewski76e39252014-09-06 07:06:46 -0400108
Clark Boylan56131eb2017-09-30 09:55:38 -0700109 # We run this here as this configures cache dirs for the auth middleware
110 # which is used in the api server and not in the registry. The api
111 # Server is configured through this function and not init_glance.
112 create_glance_cache_dir
113
Dean Troyer73f6f252012-09-17 11:22:21 -0500114 # Copy over our glance configurations and update them
115 cp $GLANCE_DIR/etc/glance-registry.conf $GLANCE_REGISTRY_CONF
Ben Nemec03997942013-08-10 09:56:16 -0500116 iniset $GLANCE_REGISTRY_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Brian Haley180f5eb2015-06-16 13:14:31 -0400117 iniset $GLANCE_REGISTRY_CONF DEFAULT bind_host $GLANCE_SERVICE_LISTEN_ADDRESS
Dean Troyer73f6f252012-09-17 11:22:21 -0500118 inicomment $GLANCE_REGISTRY_CONF DEFAULT log_file
Ian Wienandada886d2015-10-07 14:06:26 +1100119 local dburl
120 dburl=`database_connection_url glance`
Jordan Pittierceca15d2015-06-19 11:46:36 +0200121 iniset $GLANCE_REGISTRY_CONF database connection $dburl
Dean Troyer73f6f252012-09-17 11:22:21 -0500122 iniset $GLANCE_REGISTRY_CONF DEFAULT use_syslog $SYSLOG
123 iniset $GLANCE_REGISTRY_CONF paste_deploy flavor keystone
Ian Wienand1f82f432017-10-04 09:51:02 +1100124 configure_auth_token_middleware $GLANCE_REGISTRY_CONF glance $GLANCE_AUTH_CACHE_DIR/registry
Matt Riedemann45da7772017-03-05 13:07:39 -0500125 iniset $GLANCE_REGISTRY_CONF oslo_messaging_notifications driver messagingv2
Brant Knudson2dd110c2015-03-14 12:39:14 -0500126 iniset_rpc_backend glance $GLANCE_REGISTRY_CONF
Marian Horban7159b4b2015-10-22 15:47:49 -0400127 iniset $GLANCE_REGISTRY_CONF DEFAULT graceful_shutdown_timeout "$SERVICE_GRACEFUL_SHUTDOWN_TIMEOUT"
Dean Troyer73f6f252012-09-17 11:22:21 -0500128
Ben Nemec03997942013-08-10 09:56:16 -0500129 iniset $GLANCE_API_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Dean Troyer73f6f252012-09-17 11:22:21 -0500130 inicomment $GLANCE_API_CONF DEFAULT log_file
Jordan Pittierceca15d2015-06-19 11:46:36 +0200131 iniset $GLANCE_API_CONF database connection $dburl
Dean Troyer73f6f252012-09-17 11:22:21 -0500132 iniset $GLANCE_API_CONF DEFAULT use_syslog $SYSLOG
Dean Troyer73f6f252012-09-17 11:22:21 -0500133 iniset $GLANCE_API_CONF DEFAULT image_cache_dir $GLANCE_CACHE_DIR/
Matthew Treinishfa898f52017-04-25 01:30:10 -0400134 iniset $GLANCE_API_CONF DEFAULT lock_path $GLANCE_LOCK_DIR
Dean Troyer73f6f252012-09-17 11:22:21 -0500135 iniset $GLANCE_API_CONF paste_deploy flavor keystone+cachemanagement
Ian Wienand1f82f432017-10-04 09:51:02 +1100136 configure_auth_token_middleware $GLANCE_API_CONF glance $GLANCE_AUTH_CACHE_DIR/api
Matt Riedemann45da7772017-03-05 13:07:39 -0500137 iniset $GLANCE_API_CONF oslo_messaging_notifications driver messagingv2
Brant Knudson2dd110c2015-03-14 12:39:14 -0500138 iniset_rpc_backend glance $GLANCE_API_CONF
Mate Lakatbc2ef922013-08-15 18:06:59 +0100139 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
140 iniset $GLANCE_API_CONF DEFAULT container_formats "ami,ari,aki,bare,ovf,tgz"
141 iniset $GLANCE_API_CONF DEFAULT disk_formats "ami,ari,aki,vhd,raw,iso"
142 fi
Evgeny Antyshev19354582014-11-24 14:20:35 +0400143 if [ "$VIRT_DRIVER" = 'libvirt' ] && [ "$LIBVIRT_TYPE" = 'parallels' ]; then
144 iniset $GLANCE_API_CONF DEFAULT disk_formats "ami,ari,aki,vhd,vmdk,raw,qcow2,vdi,iso,ploop"
145 fi
Dean Troyer73f6f252012-09-17 11:22:21 -0500146
Flavio Percoco22c695f2016-05-11 12:49:07 -0500147 # NOTE(flaper87): To uncomment as soon as all services consuming Glance are
148 # able to consume V2 entirely.
149 if [ "$GLANCE_V1_ENABLED" != "True" ]; then
150 iniset $GLANCE_API_CONF DEFAULT enable_v1_api False
151 fi
152
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200153 # Store specific configs
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200154 iniset $GLANCE_API_CONF glance_store filesystem_store_datadir $GLANCE_IMAGE_DIR/
Brian Haley180f5eb2015-06-16 13:14:31 -0400155 iniset $GLANCE_API_CONF DEFAULT registry_host $GLANCE_SERVICE_HOST
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200156
Timur Sufieva44dd9a2016-04-29 14:08:51 +0300157 # CORS feature support - to allow calls from Horizon by default
158 if [ -n "$GLANCE_CORS_ALLOWED_ORIGIN" ]; then
159 iniset $GLANCE_API_CONF cors allowed_origin "$GLANCE_CORS_ALLOWED_ORIGIN"
160 else
161 iniset $GLANCE_API_CONF cors allowed_origin "http://$SERVICE_HOST"
162 fi
163
Dean Troyerc77b9322013-03-29 10:51:01 -0500164 # Store the images in swift if enabled.
165 if is_service_enabled s-proxy; then
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200166 iniset $GLANCE_API_CONF glance_store default_store swift
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200167 iniset $GLANCE_API_CONF glance_store swift_store_create_container_on_put True
Davanum Srinivas80f36352017-01-02 09:30:16 -0500168 if python3_enabled; then
169 iniset $GLANCE_API_CONF glance_store swift_store_auth_insecure True
170 fi
Jamie Lennoxf4f01c62015-06-19 02:52:41 +0000171
172 iniset $GLANCE_API_CONF glance_store swift_store_config_file $GLANCE_SWIFT_STORE_CONF
173 iniset $GLANCE_API_CONF glance_store default_swift_reference ref1
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200174 iniset $GLANCE_API_CONF glance_store stores "file, http, swift"
Marian Horban7159b4b2015-10-22 15:47:49 -0400175 iniset $GLANCE_API_CONF DEFAULT graceful_shutdown_timeout "$SERVICE_GRACEFUL_SHUTDOWN_TIMEOUT"
Jamie Lennoxf4f01c62015-06-19 02:52:41 +0000176
Sean Dague7580a0c2016-02-17 06:23:36 -0500177 iniset $GLANCE_SWIFT_STORE_CONF ref1 user $SERVICE_PROJECT_NAME:glance-swift
Alexey Galkinb65cf0a2015-12-15 16:14:26 +0300178
Jamie Lennoxf4f01c62015-06-19 02:52:41 +0000179 iniset $GLANCE_SWIFT_STORE_CONF ref1 key $SERVICE_PASSWORD
Davanum Srinivas80f36352017-01-02 09:30:16 -0500180 if python3_enabled; then
181 # NOTE(dims): Currently the glance_store+swift does not support either an insecure flag
182 # or ability to specify the CACERT. So fallback to http:// url
183 iniset $GLANCE_SWIFT_STORE_CONF ref1 auth_address ${KEYSTONE_SERVICE_URI/https/http}/v3
184 else
185 iniset $GLANCE_SWIFT_STORE_CONF ref1 auth_address $KEYSTONE_SERVICE_URI/v3
186 fi
Jamie Lennox19c5e622015-08-05 15:53:21 +1000187 iniset $GLANCE_SWIFT_STORE_CONF ref1 auth_version 3
Jamie Lennoxf4f01c62015-06-19 02:52:41 +0000188
189 # commenting is not strictly necessary but it's confusing to have bad values in conf
190 inicomment $GLANCE_API_CONF glance_store swift_store_user
191 inicomment $GLANCE_API_CONF glance_store swift_store_key
192 inicomment $GLANCE_API_CONF glance_store swift_store_auth_address
Dean Troyerc77b9322013-03-29 10:51:01 -0500193 fi
194
Matthew Treinish1fa65362017-06-23 22:32:37 +0000195 # We need to tell glance what it's public endpoint is so that the version
196 # discovery document will be correct
197 iniset $GLANCE_API_CONF DEFAULT public_endpoint $GLANCE_URL
198
Rob Crittenden18d47782014-03-19 17:47:42 -0400199 if is_service_enabled tls-proxy; then
200 iniset $GLANCE_API_CONF DEFAULT bind_port $GLANCE_SERVICE_PORT_INT
201 iniset $GLANCE_REGISTRY_CONF DEFAULT bind_port $GLANCE_REGISTRY_PORT_INT
Rob Crittendencdba7b02015-05-26 15:33:45 -0400202
203 iniset $GLANCE_API_CONF keystone_authtoken identity_uri $KEYSTONE_AUTH_URI
204 iniset $GLANCE_REGISTRY_CONF keystone_authtoken identity_uri $KEYSTONE_AUTH_URI
Rob Crittenden18d47782014-03-19 17:47:42 -0400205 fi
206
Sean Daguef3b2f4c2017-04-13 10:11:48 -0400207 if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -0400208 iniset $GLANCE_API_CONF DEFAULT registry_client_protocol https
209 fi
210
Louis Taylor701276a2015-02-11 19:34:09 +0000211 # Format logging
Sean Dague9751be62016-04-05 12:08:57 -0400212 setup_logging $GLANCE_API_CONF
213 setup_logging $GLANCE_REGISTRY_CONF
Louis Taylor701276a2015-02-11 19:34:09 +0000214
Dean Troyer73f6f252012-09-17 11:22:21 -0500215 cp -p $GLANCE_DIR/etc/glance-registry-paste.ini $GLANCE_REGISTRY_PASTE_INI
Dean Troyer73f6f252012-09-17 11:22:21 -0500216 cp -p $GLANCE_DIR/etc/glance-api-paste.ini $GLANCE_API_PASTE_INI
217
218 cp $GLANCE_DIR/etc/glance-cache.conf $GLANCE_CACHE_CONF
Ben Nemec03997942013-08-10 09:56:16 -0500219 iniset $GLANCE_CACHE_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Dean Troyer73f6f252012-09-17 11:22:21 -0500220 inicomment $GLANCE_CACHE_CONF DEFAULT log_file
221 iniset $GLANCE_CACHE_CONF DEFAULT use_syslog $SYSLOG
Dean Troyer73f6f252012-09-17 11:22:21 -0500222 iniset $GLANCE_CACHE_CONF DEFAULT image_cache_dir $GLANCE_CACHE_DIR/
223 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_url
Sean Daguec13b8a12017-04-20 06:54:51 -0400224 iniset $GLANCE_CACHE_CONF DEFAULT auth_url $KEYSTONE_AUTH_URI
Dean Troyer73f6f252012-09-17 11:22:21 -0500225 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_tenant_name
Sean Dague7580a0c2016-02-17 06:23:36 -0500226 iniset $GLANCE_CACHE_CONF DEFAULT admin_tenant_name $SERVICE_PROJECT_NAME
Dean Troyer73f6f252012-09-17 11:22:21 -0500227 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_user
228 iniset $GLANCE_CACHE_CONF DEFAULT admin_user glance
229 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_password
230 iniset $GLANCE_CACHE_CONF DEFAULT admin_password $SERVICE_PASSWORD
Brian Haley180f5eb2015-06-16 13:14:31 -0400231 iniset $GLANCE_CACHE_CONF DEFAULT registry_host $GLANCE_SERVICE_HOST
Dean Troyer73f6f252012-09-17 11:22:21 -0500232
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200233 # Store specific confs
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200234 iniset $GLANCE_CACHE_CONF glance_store filesystem_store_datadir $GLANCE_IMAGE_DIR/
235
bhagyashris6a25fb92017-12-14 13:23:41 +0530236 # Set default configuration options for the glance-image-import
237 iniset $GLANCE_IMAGE_IMPORT_CONF image_import_opts image_import_plugins []
238 iniset $GLANCE_IMAGE_IMPORT_CONF inject_metadata_properties ignore_user_roles admin
239 iniset $GLANCE_IMAGE_IMPORT_CONF inject_metadata_properties inject
240
Dean Troyer73f6f252012-09-17 11:22:21 -0500241 cp -p $GLANCE_DIR/etc/policy.json $GLANCE_POLICY_JSON
Dirk Mueller46d1ba62013-09-09 14:31:37 +0200242 cp -p $GLANCE_DIR/etc/schema-image.json $GLANCE_SCHEMA_JSON
Pawel Koniszewski76e39252014-09-06 07:06:46 -0400243
244 cp -p $GLANCE_DIR/etc/metadefs/*.json $GLANCE_METADEF_DIR
Rob Crittenden18d47782014-03-19 17:47:42 -0400245
Sean Daguef3b2f4c2017-04-13 10:11:48 -0400246 if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -0400247 CINDER_SERVICE_HOST=${CINDER_SERVICE_HOST:-$SERVICE_HOST}
248 CINDER_SERVICE_PORT=${CINDER_SERVICE_PORT:-8776}
249
250 iniset $GLANCE_API_CONF DEFAULT cinder_endpoint_template "https://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/%(project_id)s"
251 iniset $GLANCE_CACHE_CONF DEFAULT cinder_endpoint_template "https://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/%(project_id)s"
252 fi
Matthew Treinish1fa65362017-06-23 22:32:37 +0000253
254 if [[ "$WSGI_MODE" == "uwsgi" ]]; then
255 write_local_uwsgi_http_config "$GLANCE_UWSGI_CONF" "$GLANCE_UWSGI" "/image"
256 else
257 iniset $GLANCE_API_CONF DEFAULT bind_host $GLANCE_SERVICE_LISTEN_ADDRESS
258 iniset $GLANCE_API_CONF DEFAULT workers "$API_WORKERS"
259 fi
Dean Troyer73f6f252012-09-17 11:22:21 -0500260}
261
Dean Troyer42a59c22014-03-03 14:31:29 -0600262# create_glance_accounts() - Set up common required glance accounts
263
Wayne Okumadd622932015-03-31 00:28:39 -0700264# Project User Roles
265# ---------------------------------------------------------------------
Sean Dague7580a0c2016-02-17 06:23:36 -0500266# SERVICE_PROJECT_NAME glance service
267# SERVICE_PROJECT_NAME glance-swift ResellerAdmin (if Swift is enabled)
268# SERVICE_PROJECT_NAME glance-search search (if Search is enabled)
Dean Troyer42a59c22014-03-03 14:31:29 -0600269
270function create_glance_accounts {
271 if is_service_enabled g-api; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100272
Jamie Lennox85ff5322015-01-28 14:28:01 +1000273 create_service_user "glance"
Bartosz Górski0abde392014-02-28 14:15:19 +0100274
Dean Troyer42a59c22014-03-03 14:31:29 -0600275 # required for swift access
276 if is_service_enabled s-proxy; then
Jamie Lennoxcbcbd8f2016-01-21 16:08:14 -0600277 create_service_user "glance-swift" "ResellerAdmin"
Dean Troyer42a59c22014-03-03 14:31:29 -0600278 fi
Bartosz Górski0abde392014-02-28 14:15:19 +0100279
Sean Dague985e9582016-02-10 07:25:24 -0500280 get_or_create_service "glance" "image" "Glance Image Service"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000281 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500282 "image" \
283 "$REGION_NAME" \
Matthew Treinish1fa65362017-06-23 22:32:37 +0000284 "$GLANCE_URL"
Jens Rosenboom890342e2016-09-13 22:41:41 +0200285
286 # Note(frickler): Crude workaround for https://bugs.launchpad.net/glance-store/+bug/1620999
287 service_domain_id=$(get_or_create_domain $SERVICE_DOMAIN_NAME)
288 iniset $GLANCE_SWIFT_STORE_CONF ref1 project_domain_id $service_domain_id
289 iniset $GLANCE_SWIFT_STORE_CONF ref1 user_domain_id $service_domain_id
Dean Troyer42a59c22014-03-03 14:31:29 -0600290 fi
291}
292
Clark Boylan56131eb2017-09-30 09:55:38 -0700293# create_glance_cache_dir() - Part of the configure_glance() process
Ian Wienand1f82f432017-10-04 09:51:02 +1100294function create_glance_cache_dir {
295 # Create cache dir
296 sudo install -d -o $STACK_USER $GLANCE_AUTH_CACHE_DIR/api $GLANCE_AUTH_CACHE_DIR/registry $GLANCE_AUTH_CACHE_DIR/search $GLANCE_AUTH_CACHE_DIR/artifact
297 rm -f $GLANCE_AUTH_CACHE_DIR/api/* $GLANCE_AUTH_CACHE_DIR/registry/* $GLANCE_AUTH_CACHE_DIR/search/* $GLANCE_AUTH_CACHE_DIR/artifact/*
298}
299
Dean Troyer73f6f252012-09-17 11:22:21 -0500300# init_glance() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100301function init_glance {
Dean Troyer73f6f252012-09-17 11:22:21 -0500302 # Delete existing images
303 rm -rf $GLANCE_IMAGE_DIR
304 mkdir -p $GLANCE_IMAGE_DIR
305
306 # Delete existing cache
307 rm -rf $GLANCE_CACHE_DIR
308 mkdir -p $GLANCE_CACHE_DIR
309
Dean Troyerf03bafe2013-02-12 10:58:28 -0600310 # (Re)create glance database
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200311 recreate_database glance
Dean Troyer73f6f252012-09-17 11:22:21 -0500312
Clark Boylan633dbc32017-06-14 12:09:21 -0700313 time_start "dbsync"
Dean Troyerf03bafe2013-02-12 10:58:28 -0600314 # Migrate glance database
Einst Crazy4f55c2d2016-05-04 08:14:01 +0000315 $GLANCE_BIN_DIR/glance-manage --config-file $GLANCE_CONF_DIR/glance-api.conf db_sync
Dean Troyerbc071bc2012-10-01 14:06:44 -0500316
Pawel Koniszewski76e39252014-09-06 07:06:46 -0400317 # Load metadata definitions
Einst Crazy4f55c2d2016-05-04 08:14:01 +0000318 $GLANCE_BIN_DIR/glance-manage --config-file $GLANCE_CONF_DIR/glance-api.conf db_load_metadefs
Clark Boylan633dbc32017-06-14 12:09:21 -0700319 time_stop "dbsync"
Dean Troyer73f6f252012-09-17 11:22:21 -0500320}
321
322# install_glanceclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100323function install_glanceclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500324 if use_library_from_git "python-glanceclient"; then
325 git_clone_by_name "python-glanceclient"
326 setup_dev_lib "python-glanceclient"
Louis Taylor8df690c2014-11-20 13:09:03 +0000327 sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-glanceclient"]}/tools/,/etc/bash_completion.d/}glance.bash_completion
Sean Dague5cb19062014-11-01 01:37:45 +0100328 fi
Dean Troyer73f6f252012-09-17 11:22:21 -0500329}
330
331# install_glance() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100332function install_glance {
Flavio Percoco4f78f8f2014-09-09 09:37:42 +0200333 # Install glance_store from git so we make sure we're testing
334 # the latest code.
Sean Dagueee5ae7b2014-11-13 13:23:27 -0500335 if use_library_from_git "glance_store"; then
336 git_clone_by_name "glance_store"
337 setup_dev_lib "glance_store"
338 fi
Flavio Percoco4f78f8f2014-09-09 09:37:42 +0200339
Dean Troyer73f6f252012-09-17 11:22:21 -0500340 git_clone $GLANCE_REPO $GLANCE_DIR $GLANCE_BRANCH
Wayne Okumadd622932015-03-31 00:28:39 -0700341
Wayne Okumadd622932015-03-31 00:28:39 -0700342 setup_develop $GLANCE_DIR
Dean Troyer73f6f252012-09-17 11:22:21 -0500343}
344
Sean Dague0eebeb42017-08-30 14:16:58 -0400345# start_glance() - Start running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100346function start_glance {
Rob Crittenden18d47782014-03-19 17:47:42 -0400347 local service_protocol=$GLANCE_SERVICE_PROTOCOL
348 if is_service_enabled tls-proxy; then
Matthew Treinish1fa65362017-06-23 22:32:37 +0000349 if [[ "$WSGI_MODE" != "uwsgi" ]]; then
350 start_tls_proxy glance-service '*' $GLANCE_SERVICE_PORT $GLANCE_SERVICE_HOST $GLANCE_SERVICE_PORT_INT
351 fi
Gregory Haynes4b49e402016-08-31 18:19:51 -0700352 start_tls_proxy glance-registry '*' $GLANCE_REGISTRY_PORT $GLANCE_SERVICE_HOST $GLANCE_REGISTRY_PORT_INT
Rob Crittenden18d47782014-03-19 17:47:42 -0400353 fi
354
Chris Dent2f27a0e2014-09-09 13:46:02 +0100355 run_process g-reg "$GLANCE_BIN_DIR/glance-registry --config-file=$GLANCE_CONF_DIR/glance-registry.conf"
Matthew Treinish1fa65362017-06-23 22:32:37 +0000356 if [[ "$WSGI_MODE" == "uwsgi" ]]; then
Davanum Srinivasaceb27e2017-08-17 08:59:59 -0400357 run_process g-api "$GLANCE_BIN_DIR/uwsgi --procname-prefix glance-api --ini $GLANCE_UWSGI_CONF"
Matthew Treinish1fa65362017-06-23 22:32:37 +0000358 else
359 run_process g-api "$GLANCE_BIN_DIR/glance-api --config-file=$GLANCE_CONF_DIR/glance-api.conf"
360 fi
Rob Crittenden18d47782014-03-19 17:47:42 -0400361
Matthew Treinish1fa65362017-06-23 22:32:37 +0000362 echo "Waiting for g-api ($GLANCE_SERVICE_HOST) to start..."
363 if ! wait_for_service $SERVICE_TIMEOUT $GLANCE_URL; then
Sean Dague101b4242013-10-22 08:47:11 -0400364 die $LINENO "g-api did not start"
Dean Troyer73f6f252012-09-17 11:22:21 -0500365 fi
366}
367
Dean Troyer699a29f2012-09-10 14:10:27 -0500368# stop_glance() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100369function stop_glance {
Chris Dent2f27a0e2014-09-09 13:46:02 +0100370 stop_process g-api
371 stop_process g-reg
Dean Troyer73f6f252012-09-17 11:22:21 -0500372}
373
374# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +1100375$_XTRACE_GLANCE
Sean Dague584d90e2013-03-29 14:34:53 -0400376
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100377# Tell emacs to use shell-script-mode
378## Local variables:
379## mode: shell-script
380## End: