blob: 8ba04b3a856e7fec0fa2a8053836865c67e1152b [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
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +090098 iniset $GLANCE_REGISTRY_CONF keystone_authtoken signing_dir $GLANCE_AUTH_CACHE_DIR/registry
Dean Troyer73f6f252012-09-17 11:22:21 -050099
100 cp $GLANCE_DIR/etc/glance-api.conf $GLANCE_API_CONF
101 iniset $GLANCE_API_CONF DEFAULT debug True
102 inicomment $GLANCE_API_CONF DEFAULT log_file
Terry Wilson428af5a2012-11-01 16:12:39 -0400103 iniset $GLANCE_API_CONF DEFAULT sql_connection $dburl
Dean Troyer73f6f252012-09-17 11:22:21 -0500104 iniset $GLANCE_API_CONF DEFAULT use_syslog $SYSLOG
105 iniset $GLANCE_API_CONF DEFAULT filesystem_store_datadir $GLANCE_IMAGE_DIR/
106 iniset $GLANCE_API_CONF DEFAULT image_cache_dir $GLANCE_CACHE_DIR/
107 iniset $GLANCE_API_CONF paste_deploy flavor keystone+cachemanagement
108 iniset $GLANCE_API_CONF keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
109 iniset $GLANCE_API_CONF keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
110 iniset $GLANCE_API_CONF keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
111 iniset $GLANCE_API_CONF keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
112 iniset $GLANCE_API_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
113 iniset $GLANCE_API_CONF keystone_authtoken admin_user glance
114 iniset $GLANCE_API_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
Eoghan Glynnad80ead2012-09-27 09:36:33 +0100115 if is_service_enabled qpid; then
116 iniset $GLANCE_API_CONF DEFAULT notifier_strategy qpid
117 elif [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then
118 iniset $GLANCE_API_CONF DEFAULT notifier_strategy rabbit
119 iniset $GLANCE_API_CONF DEFAULT rabbit_host $RABBIT_HOST
120 iniset $GLANCE_API_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
121 fi
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900122 iniset $GLANCE_API_CONF keystone_authtoken signing_dir $GLANCE_AUTH_CACHE_DIR/api
Dean Troyer73f6f252012-09-17 11:22:21 -0500123
124 cp -p $GLANCE_DIR/etc/glance-registry-paste.ini $GLANCE_REGISTRY_PASTE_INI
125
126 cp -p $GLANCE_DIR/etc/glance-api-paste.ini $GLANCE_API_PASTE_INI
127
128 cp $GLANCE_DIR/etc/glance-cache.conf $GLANCE_CACHE_CONF
129 iniset $GLANCE_CACHE_CONF DEFAULT debug True
130 inicomment $GLANCE_CACHE_CONF DEFAULT log_file
131 iniset $GLANCE_CACHE_CONF DEFAULT use_syslog $SYSLOG
132 iniset $GLANCE_CACHE_CONF DEFAULT filesystem_store_datadir $GLANCE_IMAGE_DIR/
133 iniset $GLANCE_CACHE_CONF DEFAULT image_cache_dir $GLANCE_CACHE_DIR/
134 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_url
135 iniset $GLANCE_CACHE_CONF DEFAULT auth_url $KEYSTONE_AUTH_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0
136 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_tenant_name
137 iniset $GLANCE_CACHE_CONF DEFAULT admin_tenant_name $SERVICE_TENANT_NAME
138 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_user
139 iniset $GLANCE_CACHE_CONF DEFAULT admin_user glance
140 iniuncomment $GLANCE_CACHE_CONF DEFAULT auth_password
141 iniset $GLANCE_CACHE_CONF DEFAULT admin_password $SERVICE_PASSWORD
142
143 cp -p $GLANCE_DIR/etc/policy.json $GLANCE_POLICY_JSON
144
145}
146
147# init_glance() - Initialize databases, etc.
148function init_glance() {
149 # Delete existing images
150 rm -rf $GLANCE_IMAGE_DIR
151 mkdir -p $GLANCE_IMAGE_DIR
152
153 # Delete existing cache
154 rm -rf $GLANCE_CACHE_DIR
155 mkdir -p $GLANCE_CACHE_DIR
156
157 # (re)create glance database
Terry Wilson428af5a2012-11-01 16:12:39 -0400158 recreate_database glance utf8
Dean Troyer73f6f252012-09-17 11:22:21 -0500159
160 $GLANCE_BIN_DIR/glance-manage db_sync
Dean Troyerbc071bc2012-10-01 14:06:44 -0500161
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900162 # Create cache dir
163 sudo mkdir -p $GLANCE_AUTH_CACHE_DIR/api
164 sudo chown `whoami` $GLANCE_AUTH_CACHE_DIR/api
Vishvananda Ishaya23431f32012-12-12 15:57:33 -0800165 rm -f $GLANCE_AUTH_CACHE_DIR/api/*
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900166 sudo mkdir -p $GLANCE_AUTH_CACHE_DIR/registry
167 sudo chown `whoami` $GLANCE_AUTH_CACHE_DIR/registry
Vishvananda Ishaya23431f32012-12-12 15:57:33 -0800168 rm -f $GLANCE_AUTH_CACHE_DIR/registry/*
Dean Troyer73f6f252012-09-17 11:22:21 -0500169}
170
171# install_glanceclient() - Collect source and prepare
172function install_glanceclient() {
173 git_clone $GLANCECLIENT_REPO $GLANCECLIENT_DIR $GLANCECLIENT_BRANCH
174}
175
176# install_glance() - Collect source and prepare
177function install_glance() {
178 git_clone $GLANCE_REPO $GLANCE_DIR $GLANCE_BRANCH
179}
180
181# start_glance() - Start running processes, including screen
182function start_glance() {
183 screen_it g-reg "cd $GLANCE_DIR; $GLANCE_BIN_DIR/glance-registry --config-file=$GLANCE_CONF_DIR/glance-registry.conf"
184 screen_it g-api "cd $GLANCE_DIR; $GLANCE_BIN_DIR/glance-api --config-file=$GLANCE_CONF_DIR/glance-api.conf"
185 echo "Waiting for g-api ($GLANCE_HOSTPORT) to start..."
186 if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://$GLANCE_HOSTPORT; do sleep 1; done"; then
187 echo "g-api did not start"
188 exit 1
189 fi
190}
191
Dean Troyer699a29f2012-09-10 14:10:27 -0500192# stop_glance() - Stop running processes
Dean Troyer73f6f252012-09-17 11:22:21 -0500193function stop_glance() {
194 # Kill the Glance screen windows
195 screen -S $SCREEN_NAME -p g-api -X kill
196 screen -S $SCREEN_NAME -p g-reg -X kill
197}
198
199# Restore xtrace
200$XTRACE