73f6f25b |
# lib/glance |
6d04fd7b |
# Functions to control the configuration and operation of the **Glance** service |
73f6f25b |
# Dependencies: |
6a5aa7c6 |
#
# - ``functions`` file
# - ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined
# - ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined
# - ``SERVICE_HOST``
# - ``KEYSTONE_TOKEN_FORMAT`` must be defined |
73f6f25b |
# ``stack.sh`` calls the entry points in this order:
# |
6a5aa7c6 |
# - install_glance
# - configure_glance
# - init_glance
# - start_glance
# - stop_glance
# - cleanup_glance |
73f6f25b |
# Save trace setting
XTRACE=$(set +o | grep xtrace)
set +o xtrace
# Defaults
# --------
# Set up default directories
GLANCE_DIR=$DEST/glance
GLANCECLIENT_DIR=$DEST/python-glanceclient
GLANCE_CACHE_DIR=${GLANCE_CACHE_DIR:=$DATA_DIR/glance/cache}
GLANCE_IMAGE_DIR=${GLANCE_IMAGE_DIR:=$DATA_DIR/glance/images} |
bc071bce |
GLANCE_AUTH_CACHE_DIR=${GLANCE_AUTH_CACHE_DIR:-/var/cache/glance} |
73f6f25b |
GLANCE_CONF_DIR=${GLANCE_CONF_DIR:-/etc/glance}
GLANCE_REGISTRY_CONF=$GLANCE_CONF_DIR/glance-registry.conf
GLANCE_API_CONF=$GLANCE_CONF_DIR/glance-api.conf
GLANCE_REGISTRY_PASTE_INI=$GLANCE_CONF_DIR/glance-registry-paste.ini
GLANCE_API_PASTE_INI=$GLANCE_CONF_DIR/glance-api-paste.ini
GLANCE_CACHE_CONF=$GLANCE_CONF_DIR/glance-cache.conf
GLANCE_POLICY_JSON=$GLANCE_CONF_DIR/policy.json |
46d1ba6e |
GLANCE_SCHEMA_JSON=$GLANCE_CONF_DIR/schema-image.json |
73f6f25b |
# Support entry points installation of console scripts
if [[ -d $GLANCE_DIR/bin ]]; then
GLANCE_BIN_DIR=$GLANCE_DIR/bin
else |
4196d556 |
GLANCE_BIN_DIR=$(get_python_exec_prefix) |
73f6f25b |
fi
# Glance connection info. Note the port must be specified.
GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$SERVICE_HOST:9292}
|
4237f590 |
# Tell Tempest this project is present
TEMPEST_SERVICES+=,glance
|
73f6f25b |
|
cc6b4435 |
# Functions
# --------- |
73f6f25b |
|
e4fa7213 |
# Test if any Glance services are enabled
# is_glance_enabled
function is_glance_enabled {
[[ ,${ENABLED_SERVICES} =~ ,"g-" ]] && return 0
return 1
}
|
73f6f25b |
# cleanup_glance() - Remove residual data files, anything left over from previous
# runs that a clean run would need to clean up |
aee18c74 |
function cleanup_glance { |
73f6f25b |
# kill instances (nova)
# delete image files (glance) |
995eb927 |
sudo rm -rf $GLANCE_CACHE_DIR $GLANCE_IMAGE_DIR $GLANCE_AUTH_CACHE_DIR |
73f6f25b |
}
# configure_glance() - Set config files, create data dirs, etc |
aee18c74 |
function configure_glance { |
73f6f25b |
if [[ ! -d $GLANCE_CONF_DIR ]]; then
sudo mkdir -p $GLANCE_CONF_DIR
fi |
91b8d13e |
sudo chown $STACK_USER $GLANCE_CONF_DIR |
73f6f25b |
# Copy over our glance configurations and update them
cp $GLANCE_DIR/etc/glance-registry.conf $GLANCE_REGISTRY_CONF |
03997942 |
iniset $GLANCE_REGISTRY_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
73f6f25b |
inicomment $GLANCE_REGISTRY_CONF DEFAULT log_file |
7e79d913 |
local dburl=`database_connection_url glance` |
428af5a2 |
iniset $GLANCE_REGISTRY_CONF DEFAULT sql_connection $dburl |
73f6f25b |
iniset $GLANCE_REGISTRY_CONF DEFAULT use_syslog $SYSLOG
iniset $GLANCE_REGISTRY_CONF paste_deploy flavor keystone |
3561d7f9 |
iniset $GLANCE_REGISTRY_CONF keystone_authtoken identity_uri $KEYSTONE_AUTH_URI |
bd24a8d0 |
iniset $GLANCE_REGISTRY_CONF keystone_authtoken cafile $KEYSTONE_SSL_CA |
21fe4e76 |
configure_API_version $GLANCE_REGISTRY_CONF $IDENTITY_API_VERSION |
73f6f25b |
iniset $GLANCE_REGISTRY_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
iniset $GLANCE_REGISTRY_CONF keystone_authtoken admin_user glance
iniset $GLANCE_REGISTRY_CONF keystone_authtoken admin_password $SERVICE_PASSWORD |
5e3deb67 |
iniset $GLANCE_REGISTRY_CONF keystone_authtoken signing_dir $GLANCE_AUTH_CACHE_DIR/registry |
0d029246 |
if is_service_enabled qpid || [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then
iniset $GLANCE_REGISTRY_CONF DEFAULT notification_driver messaging
fi
iniset_rpc_backend glance $GLANCE_REGISTRY_CONF DEFAULT |
73f6f25b |
cp $GLANCE_DIR/etc/glance-api.conf $GLANCE_API_CONF |
03997942 |
iniset $GLANCE_API_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
73f6f25b |
inicomment $GLANCE_API_CONF DEFAULT log_file |
428af5a2 |
iniset $GLANCE_API_CONF DEFAULT sql_connection $dburl |
73f6f25b |
iniset $GLANCE_API_CONF DEFAULT use_syslog $SYSLOG
iniset $GLANCE_API_CONF DEFAULT image_cache_dir $GLANCE_CACHE_DIR/
iniset $GLANCE_API_CONF paste_deploy flavor keystone+cachemanagement |
3561d7f9 |
iniset $GLANCE_API_CONF keystone_authtoken identity_uri $KEYSTONE_AUTH_URI |
bd24a8d0 |
iniset $GLANCE_API_CONF keystone_authtoken cafile $KEYSTONE_SSL_CA |
21fe4e76 |
configure_API_version $GLANCE_API_CONF $IDENTITY_API_VERSION |
73f6f25b |
iniset $GLANCE_API_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
iniset $GLANCE_API_CONF keystone_authtoken admin_user glance
iniset $GLANCE_API_CONF keystone_authtoken admin_password $SERVICE_PASSWORD |
19a3814b |
if is_service_enabled qpid || [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then
iniset $GLANCE_API_CONF DEFAULT notification_driver messaging |
ad80eadb |
fi |
8c11f561 |
iniset_rpc_backend glance $GLANCE_API_CONF DEFAULT |
5e3deb67 |
iniset $GLANCE_API_CONF keystone_authtoken signing_dir $GLANCE_AUTH_CACHE_DIR/api |
bc2ef929 |
if [ "$VIRT_DRIVER" = 'xenserver' ]; then
iniset $GLANCE_API_CONF DEFAULT container_formats "ami,ari,aki,bare,ovf,tgz"
iniset $GLANCE_API_CONF DEFAULT disk_formats "ami,ari,aki,vhd,raw,iso"
fi |
73f6f25b |
|
fe65e2df |
# Store specific configs
iniset $GLANCE_API_CONF DEFAULT filesystem_store_datadir $GLANCE_IMAGE_DIR/
# NOTE(flaper87): Until Glance is fully migrated, set these configs in both
# sections.
iniset $GLANCE_API_CONF glance_store filesystem_store_datadir $GLANCE_IMAGE_DIR/
|
2f72050a |
if [ -n "$API_WORKERS" ]; then
iniset $GLANCE_API_CONF DEFAULT workers "$API_WORKERS"
fi
|
c77b932e |
# Store the images in swift if enabled.
if is_service_enabled s-proxy; then
iniset $GLANCE_API_CONF DEFAULT default_store swift |
3561d7f9 |
iniset $GLANCE_API_CONF DEFAULT swift_store_auth_address $KEYSTONE_SERVICE_URI/v2.0/ |
85a85f87 |
iniset $GLANCE_API_CONF DEFAULT swift_store_user $SERVICE_TENANT_NAME:glance-swift |
c77b932e |
iniset $GLANCE_API_CONF DEFAULT swift_store_key $SERVICE_PASSWORD
iniset $GLANCE_API_CONF DEFAULT swift_store_create_container_on_put True |
355fc866 |
|
c3e5b77b |
iniset $GLANCE_API_CONF DEFAULT known_stores "glance.store.filesystem.Store, glance.store.http.Store, glance.store.swift.Store" |
fe65e2df |
# NOTE(flaper87): Until Glance is fully migrated, set these configs in both
# sections.
iniset $GLANCE_API_CONF glance_store default_store swift
iniset $GLANCE_API_CONF glance_store swift_store_auth_address $KEYSTONE_SERVICE_URI/v2.0/
iniset $GLANCE_API_CONF glance_store swift_store_user $SERVICE_TENANT_NAME:glance-swift
iniset $GLANCE_API_CONF glance_store swift_store_key $SERVICE_PASSWORD
iniset $GLANCE_API_CONF glance_store swift_store_create_container_on_put True
iniset $GLANCE_API_CONF glance_store stores "file, http, swift" |
c77b932e |
fi
|
73f6f25b |
cp -p $GLANCE_DIR/etc/glance-registry-paste.ini $GLANCE_REGISTRY_PASTE_INI
cp -p $GLANCE_DIR/etc/glance-api-paste.ini $GLANCE_API_PASTE_INI
cp $GLANCE_DIR/etc/glance-cache.conf $GLANCE_CACHE_CONF |
03997942 |
iniset $GLANCE_CACHE_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
73f6f25b |
inicomment $GLANCE_CACHE_CONF DEFAULT log_file
iniset $GLANCE_CACHE_CONF DEFAULT use_syslog $SYSLOG
iniset $GLANCE_CACHE_CONF DEFAULT image_cache_dir $GLANCE_CACHE_DIR/
iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_url |
3561d7f9 |
iniset $GLANCE_CACHE_CONF DEFAULT auth_url $KEYSTONE_AUTH_URI/v2.0 |
73f6f25b |
iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_tenant_name
iniset $GLANCE_CACHE_CONF DEFAULT admin_tenant_name $SERVICE_TENANT_NAME
iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_user
iniset $GLANCE_CACHE_CONF DEFAULT admin_user glance
iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_password
iniset $GLANCE_CACHE_CONF DEFAULT admin_password $SERVICE_PASSWORD
|
fe65e2df |
# Store specific confs
# NOTE(flaper87): Until Glance is fully migrated, set these configs in both
# sections.
iniset $GLANCE_CACHE_CONF DEFAULT filesystem_store_datadir $GLANCE_IMAGE_DIR/
iniset $GLANCE_CACHE_CONF glance_store filesystem_store_datadir $GLANCE_IMAGE_DIR/
|
73f6f25b |
cp -p $GLANCE_DIR/etc/policy.json $GLANCE_POLICY_JSON |
46d1ba6e |
cp -p $GLANCE_DIR/etc/schema-image.json $GLANCE_SCHEMA_JSON |
73f6f25b |
}
|
42a59c2b |
# create_glance_accounts() - Set up common required glance accounts
# Project User Roles
# ------------------------------------------------------------------
# SERVICE_TENANT_NAME glance service
# SERVICE_TENANT_NAME glance-swift ResellerAdmin (if Swift is enabled)
function create_glance_accounts {
if is_service_enabled g-api; then |
0abde393 |
|
16ef9760 |
local glance_user=$(get_or_create_user "glance" \ |
6dd8a8be |
"$SERVICE_PASSWORD" $SERVICE_TENANT_NAME) |
16ef9760 |
get_or_add_user_role service $glance_user $SERVICE_TENANT_NAME |
0abde393 |
|
42a59c2b |
# required for swift access
if is_service_enabled s-proxy; then |
0abde393 |
|
16ef9760 |
local glance_swift_user=$(get_or_create_user "glance-swift" \ |
0abde393 |
"$SERVICE_PASSWORD" $SERVICE_TENANT_NAME "glance-swift@example.com") |
16ef9760 |
get_or_add_user_role "ResellerAdmin" $glance_swift_user $SERVICE_TENANT_NAME |
42a59c2b |
fi |
0abde393 |
|
42a59c2b |
if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
0abde393 |
|
16ef9760 |
local glance_service=$(get_or_create_service "glance" \ |
0abde393 |
"image" "Glance Image Service") |
16ef9760 |
get_or_create_endpoint $glance_service \ |
0abde393 |
"$REGION_NAME" \
"http://$GLANCE_HOSTPORT" \
"http://$GLANCE_HOSTPORT" \
"http://$GLANCE_HOSTPORT" |
42a59c2b |
fi
fi
}
|
f03bafeb |
# create_glance_cache_dir() - Part of the init_glance() process |
aee18c74 |
function create_glance_cache_dir { |
f03bafeb |
# Create cache dir
sudo mkdir -p $GLANCE_AUTH_CACHE_DIR/api
sudo chown $STACK_USER $GLANCE_AUTH_CACHE_DIR/api
rm -f $GLANCE_AUTH_CACHE_DIR/api/*
sudo mkdir -p $GLANCE_AUTH_CACHE_DIR/registry
sudo chown $STACK_USER $GLANCE_AUTH_CACHE_DIR/registry
rm -f $GLANCE_AUTH_CACHE_DIR/registry/*
}
|
73f6f25b |
# init_glance() - Initialize databases, etc. |
aee18c74 |
function init_glance { |
73f6f25b |
# Delete existing images
rm -rf $GLANCE_IMAGE_DIR
mkdir -p $GLANCE_IMAGE_DIR
# Delete existing cache
rm -rf $GLANCE_CACHE_DIR
mkdir -p $GLANCE_CACHE_DIR
|
f03bafeb |
# (Re)create glance database |
428af5a2 |
recreate_database glance utf8 |
73f6f25b |
|
f03bafeb |
# Migrate glance database |
16312738 |
$GLANCE_BIN_DIR/glance-manage db_sync |
bc071bce |
|
f03bafeb |
create_glance_cache_dir |
73f6f25b |
}
# install_glanceclient() - Collect source and prepare |
aee18c74 |
function install_glanceclient { |
73f6f25b |
git_clone $GLANCECLIENT_REPO $GLANCECLIENT_DIR $GLANCECLIENT_BRANCH |
e4f0cd7e |
setup_develop $GLANCECLIENT_DIR |
73f6f25b |
}
# install_glance() - Collect source and prepare |
aee18c74 |
function install_glance { |
73f6f25b |
git_clone $GLANCE_REPO $GLANCE_DIR $GLANCE_BRANCH |
e4f0cd7e |
setup_develop $GLANCE_DIR |
73f6f25b |
}
# start_glance() - Start running processes, including screen |
aee18c74 |
function start_glance { |
73f6f25b |
screen_it g-reg "cd $GLANCE_DIR; $GLANCE_BIN_DIR/glance-registry --config-file=$GLANCE_CONF_DIR/glance-registry.conf"
screen_it g-api "cd $GLANCE_DIR; $GLANCE_BIN_DIR/glance-api --config-file=$GLANCE_CONF_DIR/glance-api.conf"
echo "Waiting for g-api ($GLANCE_HOSTPORT) to start..." |
0aa8534a |
if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q -O- http://$GLANCE_HOSTPORT; do sleep 1; done"; then |
101b4248 |
die $LINENO "g-api did not start" |
73f6f25b |
fi
}
|
699a29f7 |
# stop_glance() - Stop running processes |
aee18c74 |
function stop_glance { |
73f6f25b |
# Kill the Glance screen windows |
9fc8792b |
screen_stop g-api
screen_stop g-reg |
73f6f25b |
}
|
cc6b4435 |
|
73f6f25b |
# Restore xtrace
$XTRACE |
584d90ec |
|
6a5aa7c6 |
# Tell emacs to use shell-script-mode
## Local variables:
## mode: shell-script
## End: |