blob: 19564183cd181da12de625450abcb0acc283ad21 [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 Troyerbc071bc2012-10-01 14:06:44 -050047GLANCE_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
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}
Brian Haley180f5eb2015-06-16 13:14:31 -040067GLANCE_SERVICE_LISTEN_ADDRESS=${GLANCE_SERVICE_LISTEN_ADDRESS:-$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 Treinishe6217a92017-04-24 16:49:04 -040074GLANCE_UWSGI=$GLANCE_BIN_DIR/glance-wsgi-api
75GLANCE_UWSGI_CONF=$GLANCE_CONF_DIR/glance-uswgi.ini
76# 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 {
91 [[ ,${ENABLED_SERVICES} =~ ,"g-" ]] && return 0
92 return 1
93}
94
Dean Troyer73f6f252012-09-17 11:22:21 -050095# cleanup_glance() - Remove residual data files, anything left over from previous
96# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +110097function cleanup_glance {
Dean Troyer73f6f252012-09-17 11:22:21 -050098 # kill instances (nova)
99 # delete image files (glance)
Dean Troyer995eb922013-03-07 16:11:40 -0600100 sudo rm -rf $GLANCE_CACHE_DIR $GLANCE_IMAGE_DIR $GLANCE_AUTH_CACHE_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
Dean Troyer73f6f252012-09-17 11:22:21 -0500107 # Copy over our glance configurations and update them
108 cp $GLANCE_DIR/etc/glance-registry.conf $GLANCE_REGISTRY_CONF
Ben Nemec03997942013-08-10 09:56:16 -0500109 iniset $GLANCE_REGISTRY_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Brian Haley180f5eb2015-06-16 13:14:31 -0400110 iniset $GLANCE_REGISTRY_CONF DEFAULT bind_host $GLANCE_SERVICE_LISTEN_ADDRESS
Dean Troyer73f6f252012-09-17 11:22:21 -0500111 inicomment $GLANCE_REGISTRY_CONF DEFAULT log_file
Ian Wienandada886d2015-10-07 14:06:26 +1100112 local dburl
113 dburl=`database_connection_url glance`
Jordan Pittierceca15d2015-06-19 11:46:36 +0200114 iniset $GLANCE_REGISTRY_CONF database connection $dburl
Dean Troyer73f6f252012-09-17 11:22:21 -0500115 iniset $GLANCE_REGISTRY_CONF DEFAULT use_syslog $SYSLOG
116 iniset $GLANCE_REGISTRY_CONF paste_deploy flavor keystone
Brant Knudson05952372014-09-19 17:22:22 -0500117 configure_auth_token_middleware $GLANCE_REGISTRY_CONF glance $GLANCE_AUTH_CACHE_DIR/registry
Matt Riedemann45da7772017-03-05 13:07:39 -0500118 iniset $GLANCE_REGISTRY_CONF oslo_messaging_notifications driver messagingv2
Brant Knudson2dd110c2015-03-14 12:39:14 -0500119 iniset_rpc_backend glance $GLANCE_REGISTRY_CONF
Marian Horban7159b4b2015-10-22 15:47:49 -0400120 iniset $GLANCE_REGISTRY_CONF DEFAULT graceful_shutdown_timeout "$SERVICE_GRACEFUL_SHUTDOWN_TIMEOUT"
Dean Troyer73f6f252012-09-17 11:22:21 -0500121
Ben Nemec03997942013-08-10 09:56:16 -0500122 iniset $GLANCE_API_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Dean Troyer73f6f252012-09-17 11:22:21 -0500123 inicomment $GLANCE_API_CONF DEFAULT log_file
Jordan Pittierceca15d2015-06-19 11:46:36 +0200124 iniset $GLANCE_API_CONF database connection $dburl
Dean Troyer73f6f252012-09-17 11:22:21 -0500125 iniset $GLANCE_API_CONF DEFAULT use_syslog $SYSLOG
Dean Troyer73f6f252012-09-17 11:22:21 -0500126 iniset $GLANCE_API_CONF DEFAULT image_cache_dir $GLANCE_CACHE_DIR/
Matthew Treinishfa898f52017-04-25 01:30:10 -0400127 iniset $GLANCE_API_CONF DEFAULT lock_path $GLANCE_LOCK_DIR
Dean Troyer73f6f252012-09-17 11:22:21 -0500128 iniset $GLANCE_API_CONF paste_deploy flavor keystone+cachemanagement
Brant Knudson05952372014-09-19 17:22:22 -0500129 configure_auth_token_middleware $GLANCE_API_CONF glance $GLANCE_AUTH_CACHE_DIR/api
Matt Riedemann45da7772017-03-05 13:07:39 -0500130 iniset $GLANCE_API_CONF oslo_messaging_notifications driver messagingv2
Brant Knudson2dd110c2015-03-14 12:39:14 -0500131 iniset_rpc_backend glance $GLANCE_API_CONF
Mate Lakatbc2ef922013-08-15 18:06:59 +0100132 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
133 iniset $GLANCE_API_CONF DEFAULT container_formats "ami,ari,aki,bare,ovf,tgz"
134 iniset $GLANCE_API_CONF DEFAULT disk_formats "ami,ari,aki,vhd,raw,iso"
135 fi
Evgeny Antyshev19354582014-11-24 14:20:35 +0400136 if [ "$VIRT_DRIVER" = 'libvirt' ] && [ "$LIBVIRT_TYPE" = 'parallels' ]; then
137 iniset $GLANCE_API_CONF DEFAULT disk_formats "ami,ari,aki,vhd,vmdk,raw,qcow2,vdi,iso,ploop"
138 fi
Dean Troyer73f6f252012-09-17 11:22:21 -0500139
Flavio Percoco22c695f2016-05-11 12:49:07 -0500140 # NOTE(flaper87): To uncomment as soon as all services consuming Glance are
141 # able to consume V2 entirely.
142 if [ "$GLANCE_V1_ENABLED" != "True" ]; then
143 iniset $GLANCE_API_CONF DEFAULT enable_v1_api False
144 fi
145
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200146 # Store specific configs
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200147 iniset $GLANCE_API_CONF glance_store filesystem_store_datadir $GLANCE_IMAGE_DIR/
Brian Haley180f5eb2015-06-16 13:14:31 -0400148 iniset $GLANCE_API_CONF DEFAULT registry_host $GLANCE_SERVICE_HOST
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200149
Timur Sufieva44dd9a2016-04-29 14:08:51 +0300150 # CORS feature support - to allow calls from Horizon by default
151 if [ -n "$GLANCE_CORS_ALLOWED_ORIGIN" ]; then
152 iniset $GLANCE_API_CONF cors allowed_origin "$GLANCE_CORS_ALLOWED_ORIGIN"
153 else
154 iniset $GLANCE_API_CONF cors allowed_origin "http://$SERVICE_HOST"
155 fi
156
Dean Troyerc77b9322013-03-29 10:51:01 -0500157 # Store the images in swift if enabled.
158 if is_service_enabled s-proxy; then
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200159 iniset $GLANCE_API_CONF glance_store default_store swift
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200160 iniset $GLANCE_API_CONF glance_store swift_store_create_container_on_put True
Davanum Srinivas80f36352017-01-02 09:30:16 -0500161 if python3_enabled; then
162 iniset $GLANCE_API_CONF glance_store swift_store_auth_insecure True
163 fi
Jamie Lennoxf4f01c62015-06-19 02:52:41 +0000164
165 iniset $GLANCE_API_CONF glance_store swift_store_config_file $GLANCE_SWIFT_STORE_CONF
166 iniset $GLANCE_API_CONF glance_store default_swift_reference ref1
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200167 iniset $GLANCE_API_CONF glance_store stores "file, http, swift"
Marian Horban7159b4b2015-10-22 15:47:49 -0400168 iniset $GLANCE_API_CONF DEFAULT graceful_shutdown_timeout "$SERVICE_GRACEFUL_SHUTDOWN_TIMEOUT"
Jamie Lennoxf4f01c62015-06-19 02:52:41 +0000169
Sean Dague7580a0c2016-02-17 06:23:36 -0500170 iniset $GLANCE_SWIFT_STORE_CONF ref1 user $SERVICE_PROJECT_NAME:glance-swift
Alexey Galkinb65cf0a2015-12-15 16:14:26 +0300171
Jamie Lennoxf4f01c62015-06-19 02:52:41 +0000172 iniset $GLANCE_SWIFT_STORE_CONF ref1 key $SERVICE_PASSWORD
Davanum Srinivas80f36352017-01-02 09:30:16 -0500173 if python3_enabled; then
174 # NOTE(dims): Currently the glance_store+swift does not support either an insecure flag
175 # or ability to specify the CACERT. So fallback to http:// url
176 iniset $GLANCE_SWIFT_STORE_CONF ref1 auth_address ${KEYSTONE_SERVICE_URI/https/http}/v3
177 else
178 iniset $GLANCE_SWIFT_STORE_CONF ref1 auth_address $KEYSTONE_SERVICE_URI/v3
179 fi
Jamie Lennox19c5e622015-08-05 15:53:21 +1000180 iniset $GLANCE_SWIFT_STORE_CONF ref1 auth_version 3
Jamie Lennoxf4f01c62015-06-19 02:52:41 +0000181
182 # commenting is not strictly necessary but it's confusing to have bad values in conf
183 inicomment $GLANCE_API_CONF glance_store swift_store_user
184 inicomment $GLANCE_API_CONF glance_store swift_store_key
185 inicomment $GLANCE_API_CONF glance_store swift_store_auth_address
Dean Troyerc77b9322013-03-29 10:51:01 -0500186 fi
187
Rob Crittenden18d47782014-03-19 17:47:42 -0400188 if is_service_enabled tls-proxy; then
189 iniset $GLANCE_API_CONF DEFAULT bind_port $GLANCE_SERVICE_PORT_INT
Rob Crittenden6254d5f2015-06-05 11:58:15 -0400190 iniset $GLANCE_API_CONF DEFAULT public_endpoint $GLANCE_SERVICE_PROTOCOL://$GLANCE_HOSTPORT
Rob Crittenden18d47782014-03-19 17:47:42 -0400191 iniset $GLANCE_REGISTRY_CONF DEFAULT bind_port $GLANCE_REGISTRY_PORT_INT
Rob Crittendencdba7b02015-05-26 15:33:45 -0400192
193 iniset $GLANCE_API_CONF keystone_authtoken identity_uri $KEYSTONE_AUTH_URI
194 iniset $GLANCE_REGISTRY_CONF keystone_authtoken identity_uri $KEYSTONE_AUTH_URI
Rob Crittenden18d47782014-03-19 17:47:42 -0400195 fi
196
Sean Daguef3b2f4c2017-04-13 10:11:48 -0400197 if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -0400198 iniset $GLANCE_API_CONF DEFAULT registry_client_protocol https
199 fi
200
Louis Taylor701276a2015-02-11 19:34:09 +0000201 # Format logging
Sean Dague9751be62016-04-05 12:08:57 -0400202 setup_logging $GLANCE_API_CONF
203 setup_logging $GLANCE_REGISTRY_CONF
Louis Taylor701276a2015-02-11 19:34:09 +0000204
Dean Troyer73f6f252012-09-17 11:22:21 -0500205 cp -p $GLANCE_DIR/etc/glance-registry-paste.ini $GLANCE_REGISTRY_PASTE_INI
Dean Troyer73f6f252012-09-17 11:22:21 -0500206 cp -p $GLANCE_DIR/etc/glance-api-paste.ini $GLANCE_API_PASTE_INI
207
208 cp $GLANCE_DIR/etc/glance-cache.conf $GLANCE_CACHE_CONF
Ben Nemec03997942013-08-10 09:56:16 -0500209 iniset $GLANCE_CACHE_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Dean Troyer73f6f252012-09-17 11:22:21 -0500210 inicomment $GLANCE_CACHE_CONF DEFAULT log_file
211 iniset $GLANCE_CACHE_CONF DEFAULT use_syslog $SYSLOG
Dean Troyer73f6f252012-09-17 11:22:21 -0500212 iniset $GLANCE_CACHE_CONF DEFAULT image_cache_dir $GLANCE_CACHE_DIR/
213 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_url
Sean Daguec13b8a12017-04-20 06:54:51 -0400214 iniset $GLANCE_CACHE_CONF DEFAULT auth_url $KEYSTONE_AUTH_URI
Dean Troyer73f6f252012-09-17 11:22:21 -0500215 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_tenant_name
Sean Dague7580a0c2016-02-17 06:23:36 -0500216 iniset $GLANCE_CACHE_CONF DEFAULT admin_tenant_name $SERVICE_PROJECT_NAME
Dean Troyer73f6f252012-09-17 11:22:21 -0500217 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_user
218 iniset $GLANCE_CACHE_CONF DEFAULT admin_user glance
219 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_password
220 iniset $GLANCE_CACHE_CONF DEFAULT admin_password $SERVICE_PASSWORD
Brian Haley180f5eb2015-06-16 13:14:31 -0400221 iniset $GLANCE_CACHE_CONF DEFAULT registry_host $GLANCE_SERVICE_HOST
Dean Troyer73f6f252012-09-17 11:22:21 -0500222
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200223 # Store specific confs
Flavio Percocofe65e2d2014-09-03 11:51:00 +0200224 iniset $GLANCE_CACHE_CONF glance_store filesystem_store_datadir $GLANCE_IMAGE_DIR/
225
Dean Troyer73f6f252012-09-17 11:22:21 -0500226 cp -p $GLANCE_DIR/etc/policy.json $GLANCE_POLICY_JSON
Dirk Mueller46d1ba62013-09-09 14:31:37 +0200227 cp -p $GLANCE_DIR/etc/schema-image.json $GLANCE_SCHEMA_JSON
Pawel Koniszewski76e39252014-09-06 07:06:46 -0400228
229 cp -p $GLANCE_DIR/etc/metadefs/*.json $GLANCE_METADEF_DIR
Rob Crittenden18d47782014-03-19 17:47:42 -0400230
Sean Daguef3b2f4c2017-04-13 10:11:48 -0400231 if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -0400232 CINDER_SERVICE_HOST=${CINDER_SERVICE_HOST:-$SERVICE_HOST}
233 CINDER_SERVICE_PORT=${CINDER_SERVICE_PORT:-8776}
234
235 iniset $GLANCE_API_CONF DEFAULT cinder_endpoint_template "https://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/%(project_id)s"
236 iniset $GLANCE_CACHE_CONF DEFAULT cinder_endpoint_template "https://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/%(project_id)s"
237 fi
Matthew Treinishe6217a92017-04-24 16:49:04 -0400238
239 if [[ "$WSGI_MODE" == "uwsgi" ]]; then
240 write_local_uwsgi_http_config "$GLANCE_UWSGI_CONF" "$GLANCE_UWSGI" "/image"
241 else
242 iniset $GLANCE_API_CONF DEFAULT bind_host $GLANCE_SERVICE_LISTEN_ADDRESS
243 iniset $GLANCE_API_CONF DEFAULT workers "$API_WORKERS"
244 fi
Dean Troyer73f6f252012-09-17 11:22:21 -0500245}
246
Dean Troyer42a59c22014-03-03 14:31:29 -0600247# create_glance_accounts() - Set up common required glance accounts
248
Wayne Okumadd622932015-03-31 00:28:39 -0700249# Project User Roles
250# ---------------------------------------------------------------------
Sean Dague7580a0c2016-02-17 06:23:36 -0500251# SERVICE_PROJECT_NAME glance service
252# SERVICE_PROJECT_NAME glance-swift ResellerAdmin (if Swift is enabled)
253# SERVICE_PROJECT_NAME glance-search search (if Search is enabled)
Dean Troyer42a59c22014-03-03 14:31:29 -0600254
255function create_glance_accounts {
256 if is_service_enabled g-api; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100257
Jamie Lennox85ff5322015-01-28 14:28:01 +1000258 create_service_user "glance"
Bartosz Górski0abde392014-02-28 14:15:19 +0100259
Dean Troyer42a59c22014-03-03 14:31:29 -0600260 # required for swift access
261 if is_service_enabled s-proxy; then
Jamie Lennoxcbcbd8f2016-01-21 16:08:14 -0600262 create_service_user "glance-swift" "ResellerAdmin"
Dean Troyer42a59c22014-03-03 14:31:29 -0600263 fi
Bartosz Górski0abde392014-02-28 14:15:19 +0100264
Sean Dague985e9582016-02-10 07:25:24 -0500265 get_or_create_service "glance" "image" "Glance Image Service"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000266 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500267 "image" \
268 "$REGION_NAME" \
Matthew Treinishe6217a92017-04-24 16:49:04 -0400269 "$GLANCE_URL"
Jens Rosenboom890342e2016-09-13 22:41:41 +0200270
271 # Note(frickler): Crude workaround for https://bugs.launchpad.net/glance-store/+bug/1620999
272 service_domain_id=$(get_or_create_domain $SERVICE_DOMAIN_NAME)
273 iniset $GLANCE_SWIFT_STORE_CONF ref1 project_domain_id $service_domain_id
274 iniset $GLANCE_SWIFT_STORE_CONF ref1 user_domain_id $service_domain_id
Dean Troyer42a59c22014-03-03 14:31:29 -0600275 fi
276}
277
Dean Troyerf03bafe2013-02-12 10:58:28 -0600278# create_glance_cache_dir() - Part of the init_glance() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100279function create_glance_cache_dir {
Dean Troyerf03bafe2013-02-12 10:58:28 -0600280 # Create cache dir
Alexey Galkinb65cf0a2015-12-15 16:14:26 +0300281 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
282 rm -f $GLANCE_AUTH_CACHE_DIR/api/* $GLANCE_AUTH_CACHE_DIR/registry/* $GLANCE_AUTH_CACHE_DIR/search/* $GLANCE_AUTH_CACHE_DIR/artifact/*
Dean Troyerf03bafe2013-02-12 10:58:28 -0600283}
284
Dean Troyer73f6f252012-09-17 11:22:21 -0500285# init_glance() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100286function init_glance {
Dean Troyer73f6f252012-09-17 11:22:21 -0500287 # Delete existing images
288 rm -rf $GLANCE_IMAGE_DIR
289 mkdir -p $GLANCE_IMAGE_DIR
290
291 # Delete existing cache
292 rm -rf $GLANCE_CACHE_DIR
293 mkdir -p $GLANCE_CACHE_DIR
294
Dean Troyerf03bafe2013-02-12 10:58:28 -0600295 # (Re)create glance database
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200296 recreate_database glance
Dean Troyer73f6f252012-09-17 11:22:21 -0500297
Dean Troyerf03bafe2013-02-12 10:58:28 -0600298 # Migrate glance database
Einst Crazy4f55c2d2016-05-04 08:14:01 +0000299 $GLANCE_BIN_DIR/glance-manage --config-file $GLANCE_CONF_DIR/glance-api.conf db_sync
Dean Troyerbc071bc2012-10-01 14:06:44 -0500300
Pawel Koniszewski76e39252014-09-06 07:06:46 -0400301 # Load metadata definitions
Einst Crazy4f55c2d2016-05-04 08:14:01 +0000302 $GLANCE_BIN_DIR/glance-manage --config-file $GLANCE_CONF_DIR/glance-api.conf db_load_metadefs
Pawel Koniszewski76e39252014-09-06 07:06:46 -0400303
Dean Troyerf03bafe2013-02-12 10:58:28 -0600304 create_glance_cache_dir
Dean Troyer73f6f252012-09-17 11:22:21 -0500305}
306
307# install_glanceclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100308function install_glanceclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500309 if use_library_from_git "python-glanceclient"; then
310 git_clone_by_name "python-glanceclient"
311 setup_dev_lib "python-glanceclient"
Louis Taylor8df690c2014-11-20 13:09:03 +0000312 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 +0100313 fi
Dean Troyer73f6f252012-09-17 11:22:21 -0500314}
315
316# install_glance() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100317function install_glance {
Flavio Percoco4f78f8f2014-09-09 09:37:42 +0200318 # Install glance_store from git so we make sure we're testing
319 # the latest code.
Sean Dagueee5ae7b2014-11-13 13:23:27 -0500320 if use_library_from_git "glance_store"; then
321 git_clone_by_name "glance_store"
322 setup_dev_lib "glance_store"
323 fi
Flavio Percoco4f78f8f2014-09-09 09:37:42 +0200324
Dean Troyer73f6f252012-09-17 11:22:21 -0500325 git_clone $GLANCE_REPO $GLANCE_DIR $GLANCE_BRANCH
Wayne Okumadd622932015-03-31 00:28:39 -0700326
Wayne Okumadd622932015-03-31 00:28:39 -0700327 setup_develop $GLANCE_DIR
Dean Troyer73f6f252012-09-17 11:22:21 -0500328}
329
330# start_glance() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100331function start_glance {
Rob Crittenden18d47782014-03-19 17:47:42 -0400332 local service_protocol=$GLANCE_SERVICE_PROTOCOL
333 if is_service_enabled tls-proxy; then
Matthew Treinishe6217a92017-04-24 16:49:04 -0400334 if [[ "$WSGI_MODE" != "uwsgi" ]]; then
335 start_tls_proxy glance-service '*' $GLANCE_SERVICE_PORT $GLANCE_SERVICE_HOST $GLANCE_SERVICE_PORT_INT
336 fi
Gregory Haynes4b49e402016-08-31 18:19:51 -0700337 start_tls_proxy glance-registry '*' $GLANCE_REGISTRY_PORT $GLANCE_SERVICE_HOST $GLANCE_REGISTRY_PORT_INT
Rob Crittenden18d47782014-03-19 17:47:42 -0400338 fi
339
Chris Dent2f27a0e2014-09-09 13:46:02 +0100340 run_process g-reg "$GLANCE_BIN_DIR/glance-registry --config-file=$GLANCE_CONF_DIR/glance-registry.conf"
Matthew Treinishe6217a92017-04-24 16:49:04 -0400341 if [[ "$WSGI_MODE" == "uwsgi" ]]; then
342 run_process g-api "$GLANCE_BIN_DIR/uwsgi --ini $GLANCE_UWSGI_CONF"
343 else
344 run_process g-api "$GLANCE_BIN_DIR/glance-api --config-file=$GLANCE_CONF_DIR/glance-api.conf"
345 fi
Rob Crittenden18d47782014-03-19 17:47:42 -0400346
Matthew Treinishe6217a92017-04-24 16:49:04 -0400347 echo "Waiting for g-api ($GLANCE_SERVICE_HOST) to start..."
348 if ! wait_for_service $SERVICE_TIMEOUT $GLANCE_URL; then
Sean Dague101b4242013-10-22 08:47:11 -0400349 die $LINENO "g-api did not start"
Dean Troyer73f6f252012-09-17 11:22:21 -0500350 fi
351}
352
Dean Troyer699a29f2012-09-10 14:10:27 -0500353# stop_glance() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100354function stop_glance {
Dean Troyer73f6f252012-09-17 11:22:21 -0500355 # Kill the Glance screen windows
Chris Dent2f27a0e2014-09-09 13:46:02 +0100356 stop_process g-api
357 stop_process g-reg
Dean Troyer73f6f252012-09-17 11:22:21 -0500358}
359
360# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +1100361$_XTRACE_GLANCE
Sean Dague584d90e2013-03-29 14:34:53 -0400362
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100363# Tell emacs to use shell-script-mode
364## Local variables:
365## mode: shell-script
366## End: