blob: 54d327643372f5293eb3de416304dbe8429ffc0a [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}
Dean Troyer73f6f252012-09-17 11:22:21 -050047
48GLANCE_CONF_DIR=${GLANCE_CONF_DIR:-/etc/glance}
Pawel Koniszewski76e39252014-09-06 07:06:46 -040049GLANCE_METADEF_DIR=$GLANCE_CONF_DIR/metadefs
Dean Troyer73f6f252012-09-17 11:22:21 -050050GLANCE_REGISTRY_CONF=$GLANCE_CONF_DIR/glance-registry.conf
51GLANCE_API_CONF=$GLANCE_CONF_DIR/glance-api.conf
52GLANCE_REGISTRY_PASTE_INI=$GLANCE_CONF_DIR/glance-registry-paste.ini
53GLANCE_API_PASTE_INI=$GLANCE_CONF_DIR/glance-api-paste.ini
54GLANCE_CACHE_CONF=$GLANCE_CONF_DIR/glance-cache.conf
55GLANCE_POLICY_JSON=$GLANCE_CONF_DIR/policy.json
Dirk Mueller46d1ba62013-09-09 14:31:37 +020056GLANCE_SCHEMA_JSON=$GLANCE_CONF_DIR/schema-image.json
Jamie Lennoxf4f01c62015-06-19 02:52:41 +000057GLANCE_SWIFT_STORE_CONF=$GLANCE_CONF_DIR/glance-swift-store.conf
bhagyashris6a25fb92017-12-14 13:23:41 +053058GLANCE_IMAGE_IMPORT_CONF=$GLANCE_CONF_DIR/glance-image-import.conf
Matt Riedemann80e82ea2016-07-15 22:53:17 -040059GLANCE_V1_ENABLED=${GLANCE_V1_ENABLED:-False}
Dean Troyer73f6f252012-09-17 11:22:21 -050060
Sean Daguef3b2f4c2017-04-13 10:11:48 -040061if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -040062 GLANCE_SERVICE_PROTOCOL="https"
63fi
64
Dean Troyer73f6f252012-09-17 11:22:21 -050065# Glance connection info. Note the port must be specified.
Rob Crittenden18d47782014-03-19 17:47:42 -040066GLANCE_SERVICE_HOST=${GLANCE_SERVICE_HOST:-$SERVICE_HOST}
Jens Harbottdc7b4292017-09-19 10:52:32 +000067GLANCE_SERVICE_LISTEN_ADDRESS=${GLANCE_SERVICE_LISTEN_ADDRESS:-$(ipv6_unquote $SERVICE_LISTEN_ADDRESS)}
Rob Crittenden18d47782014-03-19 17:47:42 -040068GLANCE_SERVICE_PORT=${GLANCE_SERVICE_PORT:-9292}
69GLANCE_SERVICE_PORT_INT=${GLANCE_SERVICE_PORT_INT:-19292}
70GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$GLANCE_SERVICE_HOST:$GLANCE_SERVICE_PORT}
71GLANCE_SERVICE_PROTOCOL=${GLANCE_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
72GLANCE_REGISTRY_PORT=${GLANCE_REGISTRY_PORT:-9191}
73GLANCE_REGISTRY_PORT_INT=${GLANCE_REGISTRY_PORT_INT:-19191}
Matthew Treinish1fa65362017-06-23 22:32:37 +000074GLANCE_UWSGI=$GLANCE_BIN_DIR/glance-wsgi-api
Jeremy Liu2f7df512017-07-12 10:09:48 +080075GLANCE_UWSGI_CONF=$GLANCE_CONF_DIR/glance-uwsgi.ini
Matthew Treinish1fa65362017-06-23 22:32:37 +000076# If wsgi mode is uwsgi run glance under uwsgi, else default to eventlet
77# TODO(mtreinish): Remove the eventlet path here and in all the similar
78# conditionals below after the Pike release
79if [[ "$WSGI_MODE" == "uwsgi" ]]; then
80 GLANCE_URL="$GLANCE_SERVICE_PROTOCOL://$GLANCE_SERVICE_HOST/image"
81else
82 GLANCE_URL="$GLANCE_SERVICE_PROTOCOL://$GLANCE_HOSTPORT"
83fi
Dean Troyer73f6f252012-09-17 11:22:21 -050084
Dean Troyercc6b4432013-04-08 15:38:03 -050085# Functions
86# ---------
Dean Troyer73f6f252012-09-17 11:22:21 -050087
Dean Troyere4fa7212014-01-15 15:04:49 -060088# Test if any Glance services are enabled
89# is_glance_enabled
90function is_glance_enabled {
Clark Boylan902158b2017-05-30 14:11:09 -070091 [[ ,${DISABLED_SERVICES} =~ ,"glance" ]] && return 1
Dean Troyere4fa7212014-01-15 15:04:49 -060092 [[ ,${ENABLED_SERVICES} =~ ,"g-" ]] && return 0
93 return 1
94}
95
Dean Troyer73f6f252012-09-17 11:22:21 -050096# cleanup_glance() - Remove residual data files, anything left over from previous
97# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +110098function cleanup_glance {
Dean Troyer73f6f252012-09-17 11:22:21 -050099 # delete image files (glance)
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100100 sudo rm -rf $GLANCE_CACHE_DIR $GLANCE_IMAGE_DIR
Dean Troyer73f6f252012-09-17 11:22:21 -0500101}
102
Dean Troyer73f6f252012-09-17 11:22:21 -0500103# configure_glance() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100104function configure_glance {
Dean Troyer8421c2b2015-03-16 13:52:19 -0500105 sudo install -d -o $STACK_USER $GLANCE_CONF_DIR $GLANCE_METADEF_DIR
Pawel Koniszewski76e39252014-09-06 07:06:46 -0400106
Brian Rosmaita44a19b42017-12-11 18:07:50 -0500107 # Set non-default configuration options for registry
Ben Nemec03997942013-08-10 09:56:16 -0500108 iniset $GLANCE_REGISTRY_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Brian Haley180f5eb2015-06-16 13:14:31 -0400109 iniset $GLANCE_REGISTRY_CONF DEFAULT bind_host $GLANCE_SERVICE_LISTEN_ADDRESS
Matt Riedemann0f4af392018-06-02 09:34:20 -0400110 iniset $GLANCE_REGISTRY_CONF DEFAULT workers $API_WORKERS
Ian Wienandada886d2015-10-07 14:06:26 +1100111 local dburl
112 dburl=`database_connection_url glance`
Jordan Pittierceca15d2015-06-19 11:46:36 +0200113 iniset $GLANCE_REGISTRY_CONF database connection $dburl
Dean Troyer73f6f252012-09-17 11:22:21 -0500114 iniset $GLANCE_REGISTRY_CONF DEFAULT use_syslog $SYSLOG
115 iniset $GLANCE_REGISTRY_CONF paste_deploy flavor keystone
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100116 configure_keystone_authtoken_middleware $GLANCE_REGISTRY_CONF glance
Matt Riedemann45da7772017-03-05 13:07:39 -0500117 iniset $GLANCE_REGISTRY_CONF oslo_messaging_notifications driver messagingv2
Brant Knudson2dd110c2015-03-14 12:39:14 -0500118 iniset_rpc_backend glance $GLANCE_REGISTRY_CONF
Marian Horban7159b4b2015-10-22 15:47:49 -0400119 iniset $GLANCE_REGISTRY_CONF DEFAULT graceful_shutdown_timeout "$SERVICE_GRACEFUL_SHUTDOWN_TIMEOUT"
Dean Troyer73f6f252012-09-17 11:22:21 -0500120
Brian Rosmaita44a19b42017-12-11 18:07:50 -0500121 # Set non-default configuration options for the API server
Ben Nemec03997942013-08-10 09:56:16 -0500122 iniset $GLANCE_API_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Jordan Pittierceca15d2015-06-19 11:46:36 +0200123 iniset $GLANCE_API_CONF database connection $dburl
Dean Troyer73f6f252012-09-17 11:22:21 -0500124 iniset $GLANCE_API_CONF DEFAULT use_syslog $SYSLOG
Dean Troyer73f6f252012-09-17 11:22:21 -0500125 iniset $GLANCE_API_CONF DEFAULT image_cache_dir $GLANCE_CACHE_DIR/
ZhongShengping5fe60c12019-04-30 10:12:51 +0800126 iniset $GLANCE_API_CONF oslo_concurrency lock_path $GLANCE_LOCK_DIR
Dean Troyer73f6f252012-09-17 11:22:21 -0500127 iniset $GLANCE_API_CONF paste_deploy flavor keystone+cachemanagement
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100128 configure_keystone_authtoken_middleware $GLANCE_API_CONF glance
Matt Riedemann45da7772017-03-05 13:07:39 -0500129 iniset $GLANCE_API_CONF oslo_messaging_notifications driver messagingv2
Brant Knudson2dd110c2015-03-14 12:39:14 -0500130 iniset_rpc_backend glance $GLANCE_API_CONF
Mate Lakatbc2ef922013-08-15 18:06:59 +0100131 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
132 iniset $GLANCE_API_CONF DEFAULT container_formats "ami,ari,aki,bare,ovf,tgz"
133 iniset $GLANCE_API_CONF DEFAULT disk_formats "ami,ari,aki,vhd,raw,iso"
134 fi
Evgeny Antyshev19354582014-11-24 14:20:35 +0400135 if [ "$VIRT_DRIVER" = 'libvirt' ] && [ "$LIBVIRT_TYPE" = 'parallels' ]; then
136 iniset $GLANCE_API_CONF DEFAULT disk_formats "ami,ari,aki,vhd,vmdk,raw,qcow2,vdi,iso,ploop"
137 fi
Dean Troyer73f6f252012-09-17 11:22:21 -0500138
Flavio Percoco22c695f2016-05-11 12:49:07 -0500139 # NOTE(flaper87): To uncomment as soon as all services consuming Glance are
140 # able to consume V2 entirely.
141 if [ "$GLANCE_V1_ENABLED" != "True" ]; then
142 iniset $GLANCE_API_CONF DEFAULT enable_v1_api False
143 fi
144
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200145 # Store specific configs
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200146 iniset $GLANCE_API_CONF glance_store filesystem_store_datadir $GLANCE_IMAGE_DIR/
Jens Harbottdc7b4292017-09-19 10:52:32 +0000147 iniset $GLANCE_API_CONF DEFAULT registry_host $(ipv6_unquote $GLANCE_SERVICE_HOST)
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200148
Timur Sufieva44dd9a2016-04-29 14:08:51 +0300149 # CORS feature support - to allow calls from Horizon by default
150 if [ -n "$GLANCE_CORS_ALLOWED_ORIGIN" ]; then
151 iniset $GLANCE_API_CONF cors allowed_origin "$GLANCE_CORS_ALLOWED_ORIGIN"
152 else
153 iniset $GLANCE_API_CONF cors allowed_origin "http://$SERVICE_HOST"
154 fi
155
Dean Troyerc77b9322013-03-29 10:51:01 -0500156 # Store the images in swift if enabled.
157 if is_service_enabled s-proxy; then
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200158 iniset $GLANCE_API_CONF glance_store default_store swift
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200159 iniset $GLANCE_API_CONF glance_store swift_store_create_container_on_put True
Davanum Srinivas80f36352017-01-02 09:30:16 -0500160 if python3_enabled; then
161 iniset $GLANCE_API_CONF glance_store swift_store_auth_insecure True
162 fi
Jamie Lennoxf4f01c62015-06-19 02:52:41 +0000163
164 iniset $GLANCE_API_CONF glance_store swift_store_config_file $GLANCE_SWIFT_STORE_CONF
165 iniset $GLANCE_API_CONF glance_store default_swift_reference ref1
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200166 iniset $GLANCE_API_CONF glance_store stores "file, http, swift"
Marian Horban7159b4b2015-10-22 15:47:49 -0400167 iniset $GLANCE_API_CONF DEFAULT graceful_shutdown_timeout "$SERVICE_GRACEFUL_SHUTDOWN_TIMEOUT"
Jamie Lennoxf4f01c62015-06-19 02:52:41 +0000168
Sean Dague7580a0c2016-02-17 06:23:36 -0500169 iniset $GLANCE_SWIFT_STORE_CONF ref1 user $SERVICE_PROJECT_NAME:glance-swift
Alexey Galkinb65cf0a2015-12-15 16:14:26 +0300170
Jamie Lennoxf4f01c62015-06-19 02:52:41 +0000171 iniset $GLANCE_SWIFT_STORE_CONF ref1 key $SERVICE_PASSWORD
Davanum Srinivas80f36352017-01-02 09:30:16 -0500172 if python3_enabled; then
173 # NOTE(dims): Currently the glance_store+swift does not support either an insecure flag
174 # or ability to specify the CACERT. So fallback to http:// url
175 iniset $GLANCE_SWIFT_STORE_CONF ref1 auth_address ${KEYSTONE_SERVICE_URI/https/http}/v3
176 else
177 iniset $GLANCE_SWIFT_STORE_CONF ref1 auth_address $KEYSTONE_SERVICE_URI/v3
178 fi
Jamie Lennox19c5e622015-08-05 15:53:21 +1000179 iniset $GLANCE_SWIFT_STORE_CONF ref1 auth_version 3
Dean Troyerc77b9322013-03-29 10:51:01 -0500180 fi
181
Matthew Treinish1fa65362017-06-23 22:32:37 +0000182 # We need to tell glance what it's public endpoint is so that the version
183 # discovery document will be correct
184 iniset $GLANCE_API_CONF DEFAULT public_endpoint $GLANCE_URL
185
Rob Crittenden18d47782014-03-19 17:47:42 -0400186 if is_service_enabled tls-proxy; then
187 iniset $GLANCE_API_CONF DEFAULT bind_port $GLANCE_SERVICE_PORT_INT
188 iniset $GLANCE_REGISTRY_CONF DEFAULT bind_port $GLANCE_REGISTRY_PORT_INT
Rob Crittendencdba7b02015-05-26 15:33:45 -0400189
190 iniset $GLANCE_API_CONF keystone_authtoken identity_uri $KEYSTONE_AUTH_URI
191 iniset $GLANCE_REGISTRY_CONF keystone_authtoken identity_uri $KEYSTONE_AUTH_URI
Rob Crittenden18d47782014-03-19 17:47:42 -0400192 fi
193
Sean Daguef3b2f4c2017-04-13 10:11:48 -0400194 if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -0400195 iniset $GLANCE_API_CONF DEFAULT registry_client_protocol https
196 fi
197
Louis Taylor701276a2015-02-11 19:34:09 +0000198 # Format logging
Sean Dague9751be62016-04-05 12:08:57 -0400199 setup_logging $GLANCE_API_CONF
200 setup_logging $GLANCE_REGISTRY_CONF
Louis Taylor701276a2015-02-11 19:34:09 +0000201
Dean Troyer73f6f252012-09-17 11:22:21 -0500202 cp -p $GLANCE_DIR/etc/glance-registry-paste.ini $GLANCE_REGISTRY_PASTE_INI
Dean Troyer73f6f252012-09-17 11:22:21 -0500203 cp -p $GLANCE_DIR/etc/glance-api-paste.ini $GLANCE_API_PASTE_INI
204
Brian Rosmaita44a19b42017-12-11 18:07:50 -0500205 # Set non-default configuration options for the glance-cache
Ben Nemec03997942013-08-10 09:56:16 -0500206 iniset $GLANCE_CACHE_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Dean Troyer73f6f252012-09-17 11:22:21 -0500207 iniset $GLANCE_CACHE_CONF DEFAULT use_syslog $SYSLOG
Dean Troyer73f6f252012-09-17 11:22:21 -0500208 iniset $GLANCE_CACHE_CONF DEFAULT image_cache_dir $GLANCE_CACHE_DIR/
Sean Daguec13b8a12017-04-20 06:54:51 -0400209 iniset $GLANCE_CACHE_CONF DEFAULT auth_url $KEYSTONE_AUTH_URI
Sean Dague7580a0c2016-02-17 06:23:36 -0500210 iniset $GLANCE_CACHE_CONF DEFAULT admin_tenant_name $SERVICE_PROJECT_NAME
Dean Troyer73f6f252012-09-17 11:22:21 -0500211 iniset $GLANCE_CACHE_CONF DEFAULT admin_user glance
Dean Troyer73f6f252012-09-17 11:22:21 -0500212 iniset $GLANCE_CACHE_CONF DEFAULT admin_password $SERVICE_PASSWORD
Jens Harbottdc7b4292017-09-19 10:52:32 +0000213 iniset $GLANCE_CACHE_CONF DEFAULT registry_host $(ipv6_unquote $GLANCE_SERVICE_HOST)
Dean Troyer73f6f252012-09-17 11:22:21 -0500214
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200215 # Store specific confs
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200216 iniset $GLANCE_CACHE_CONF glance_store filesystem_store_datadir $GLANCE_IMAGE_DIR/
217
bhagyashris6a25fb92017-12-14 13:23:41 +0530218 # Set default configuration options for the glance-image-import
219 iniset $GLANCE_IMAGE_IMPORT_CONF image_import_opts image_import_plugins []
220 iniset $GLANCE_IMAGE_IMPORT_CONF inject_metadata_properties ignore_user_roles admin
221 iniset $GLANCE_IMAGE_IMPORT_CONF inject_metadata_properties inject
222
Dean Troyer73f6f252012-09-17 11:22:21 -0500223 cp -p $GLANCE_DIR/etc/policy.json $GLANCE_POLICY_JSON
Dirk Mueller46d1ba62013-09-09 14:31:37 +0200224 cp -p $GLANCE_DIR/etc/schema-image.json $GLANCE_SCHEMA_JSON
Pawel Koniszewski76e39252014-09-06 07:06:46 -0400225
226 cp -p $GLANCE_DIR/etc/metadefs/*.json $GLANCE_METADEF_DIR
Rob Crittenden18d47782014-03-19 17:47:42 -0400227
Sean Daguef3b2f4c2017-04-13 10:11:48 -0400228 if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -0400229 CINDER_SERVICE_HOST=${CINDER_SERVICE_HOST:-$SERVICE_HOST}
230 CINDER_SERVICE_PORT=${CINDER_SERVICE_PORT:-8776}
231
Brian Rosmaitab43810a2019-02-07 16:46:49 -0500232 iniset $GLANCE_API_CONF DEFAULT cinder_endpoint_template "https://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/%(project_id)s"
233 iniset $GLANCE_CACHE_CONF DEFAULT cinder_endpoint_template "https://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/%(project_id)s"
Rob Crittenden18d47782014-03-19 17:47:42 -0400234 fi
Matthew Treinish1fa65362017-06-23 22:32:37 +0000235
236 if [[ "$WSGI_MODE" == "uwsgi" ]]; then
237 write_local_uwsgi_http_config "$GLANCE_UWSGI_CONF" "$GLANCE_UWSGI" "/image"
238 else
239 iniset $GLANCE_API_CONF DEFAULT bind_host $GLANCE_SERVICE_LISTEN_ADDRESS
240 iniset $GLANCE_API_CONF DEFAULT workers "$API_WORKERS"
241 fi
Dean Troyer73f6f252012-09-17 11:22:21 -0500242}
243
Dean Troyer42a59c22014-03-03 14:31:29 -0600244# create_glance_accounts() - Set up common required glance accounts
245
Wayne Okumadd622932015-03-31 00:28:39 -0700246# Project User Roles
247# ---------------------------------------------------------------------
Sean Dague7580a0c2016-02-17 06:23:36 -0500248# SERVICE_PROJECT_NAME glance service
249# SERVICE_PROJECT_NAME glance-swift ResellerAdmin (if Swift is enabled)
250# SERVICE_PROJECT_NAME glance-search search (if Search is enabled)
Dean Troyer42a59c22014-03-03 14:31:29 -0600251
252function create_glance_accounts {
253 if is_service_enabled g-api; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100254
Jamie Lennox85ff5322015-01-28 14:28:01 +1000255 create_service_user "glance"
Bartosz Górski0abde392014-02-28 14:15:19 +0100256
Dean Troyer42a59c22014-03-03 14:31:29 -0600257 # required for swift access
258 if is_service_enabled s-proxy; then
Jamie Lennoxcbcbd8f2016-01-21 16:08:14 -0600259 create_service_user "glance-swift" "ResellerAdmin"
Dean Troyer42a59c22014-03-03 14:31:29 -0600260 fi
Bartosz Górski0abde392014-02-28 14:15:19 +0100261
Sean Dague985e9582016-02-10 07:25:24 -0500262 get_or_create_service "glance" "image" "Glance Image Service"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000263 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500264 "image" \
265 "$REGION_NAME" \
Matthew Treinish1fa65362017-06-23 22:32:37 +0000266 "$GLANCE_URL"
Jens Rosenboom890342e2016-09-13 22:41:41 +0200267
268 # Note(frickler): Crude workaround for https://bugs.launchpad.net/glance-store/+bug/1620999
269 service_domain_id=$(get_or_create_domain $SERVICE_DOMAIN_NAME)
270 iniset $GLANCE_SWIFT_STORE_CONF ref1 project_domain_id $service_domain_id
271 iniset $GLANCE_SWIFT_STORE_CONF ref1 user_domain_id $service_domain_id
Dean Troyer42a59c22014-03-03 14:31:29 -0600272 fi
273}
274
Dean Troyer73f6f252012-09-17 11:22:21 -0500275# init_glance() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100276function init_glance {
Dean Troyer73f6f252012-09-17 11:22:21 -0500277 # Delete existing images
278 rm -rf $GLANCE_IMAGE_DIR
279 mkdir -p $GLANCE_IMAGE_DIR
280
Dean Troyerf03bafe2013-02-12 10:58:28 -0600281 # (Re)create glance database
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200282 recreate_database glance
Dean Troyer73f6f252012-09-17 11:22:21 -0500283
Clark Boylan633dbc32017-06-14 12:09:21 -0700284 time_start "dbsync"
Dean Troyerf03bafe2013-02-12 10:58:28 -0600285 # Migrate glance database
Einst Crazy4f55c2d2016-05-04 08:14:01 +0000286 $GLANCE_BIN_DIR/glance-manage --config-file $GLANCE_CONF_DIR/glance-api.conf db_sync
Dean Troyerbc071bc2012-10-01 14:06:44 -0500287
Pawel Koniszewski76e39252014-09-06 07:06:46 -0400288 # Load metadata definitions
Einst Crazy4f55c2d2016-05-04 08:14:01 +0000289 $GLANCE_BIN_DIR/glance-manage --config-file $GLANCE_CONF_DIR/glance-api.conf db_load_metadefs
Clark Boylan633dbc32017-06-14 12:09:21 -0700290 time_stop "dbsync"
Dean Troyer73f6f252012-09-17 11:22:21 -0500291}
292
293# install_glanceclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100294function install_glanceclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500295 if use_library_from_git "python-glanceclient"; then
296 git_clone_by_name "python-glanceclient"
297 setup_dev_lib "python-glanceclient"
Louis Taylor8df690c2014-11-20 13:09:03 +0000298 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 +0100299 fi
Dean Troyer73f6f252012-09-17 11:22:21 -0500300}
301
302# install_glance() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100303function install_glance {
Flavio Percoco4f78f8f2014-09-09 09:37:42 +0200304 # Install glance_store from git so we make sure we're testing
305 # the latest code.
Sean Dagueee5ae7b2014-11-13 13:23:27 -0500306 if use_library_from_git "glance_store"; then
307 git_clone_by_name "glance_store"
308 setup_dev_lib "glance_store"
309 fi
Flavio Percoco4f78f8f2014-09-09 09:37:42 +0200310
Dean Troyer73f6f252012-09-17 11:22:21 -0500311 git_clone $GLANCE_REPO $GLANCE_DIR $GLANCE_BRANCH
Wayne Okumadd622932015-03-31 00:28:39 -0700312
Wayne Okumadd622932015-03-31 00:28:39 -0700313 setup_develop $GLANCE_DIR
Dean Troyer73f6f252012-09-17 11:22:21 -0500314}
315
Sean Dague0eebeb42017-08-30 14:16:58 -0400316# start_glance() - Start running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100317function start_glance {
Rob Crittenden18d47782014-03-19 17:47:42 -0400318 local service_protocol=$GLANCE_SERVICE_PROTOCOL
319 if is_service_enabled tls-proxy; then
Matthew Treinish1fa65362017-06-23 22:32:37 +0000320 if [[ "$WSGI_MODE" != "uwsgi" ]]; then
321 start_tls_proxy glance-service '*' $GLANCE_SERVICE_PORT $GLANCE_SERVICE_HOST $GLANCE_SERVICE_PORT_INT
322 fi
Gregory Haynes4b49e402016-08-31 18:19:51 -0700323 start_tls_proxy glance-registry '*' $GLANCE_REGISTRY_PORT $GLANCE_SERVICE_HOST $GLANCE_REGISTRY_PORT_INT
Rob Crittenden18d47782014-03-19 17:47:42 -0400324 fi
325
Chris Dent2f27a0e2014-09-09 13:46:02 +0100326 run_process g-reg "$GLANCE_BIN_DIR/glance-registry --config-file=$GLANCE_CONF_DIR/glance-registry.conf"
Matthew Treinish1fa65362017-06-23 22:32:37 +0000327 if [[ "$WSGI_MODE" == "uwsgi" ]]; then
Davanum Srinivasaceb27e2017-08-17 08:59:59 -0400328 run_process g-api "$GLANCE_BIN_DIR/uwsgi --procname-prefix glance-api --ini $GLANCE_UWSGI_CONF"
Matthew Treinish1fa65362017-06-23 22:32:37 +0000329 else
Brian Rosmaita96269d82018-12-17 10:38:42 -0500330 run_process g-api "$GLANCE_BIN_DIR/glance-api --config-dir=$GLANCE_CONF_DIR"
Matthew Treinish1fa65362017-06-23 22:32:37 +0000331 fi
Rob Crittenden18d47782014-03-19 17:47:42 -0400332
Matthew Treinish1fa65362017-06-23 22:32:37 +0000333 echo "Waiting for g-api ($GLANCE_SERVICE_HOST) to start..."
334 if ! wait_for_service $SERVICE_TIMEOUT $GLANCE_URL; then
Sean Dague101b4242013-10-22 08:47:11 -0400335 die $LINENO "g-api did not start"
Dean Troyer73f6f252012-09-17 11:22:21 -0500336 fi
337}
338
Dean Troyer699a29f2012-09-10 14:10:27 -0500339# stop_glance() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100340function stop_glance {
Chris Dent2f27a0e2014-09-09 13:46:02 +0100341 stop_process g-api
342 stop_process g-reg
Dean Troyer73f6f252012-09-17 11:22:21 -0500343}
344
345# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +1100346$_XTRACE_GLANCE
Sean Dague584d90e2013-03-29 14:34:53 -0400347
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100348# Tell emacs to use shell-script-mode
349## Local variables:
350## mode: shell-script
351## End: