blob: b8838f59fbd616f8ecc85a253c8a9c81db2faae7 [file] [log] [blame]
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +03001# lib/ironic
2# Functions to control the configuration and operation of the **Ironic** service
3
4# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01005#
6# - ``functions`` file
7# - ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined
8# - ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined
9# - ``SERVICE_HOST``
10# - ``KEYSTONE_TOKEN_FORMAT`` must be defined
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030011
12# ``stack.sh`` calls the entry points in this order:
13#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010014# - install_ironic
15# - install_ironicclient
16# - init_ironic
17# - start_ironic
18# - stop_ironic
19# - cleanup_ironic
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030020
21# Save trace setting
22XTRACE=$(set +o | grep xtrace)
23set +o xtrace
24
25
26# Defaults
27# --------
28
29# Set up default directories
30IRONIC_DIR=$DEST/ironic
Roman Prykhodchenko43e00662013-10-15 17:03:15 +030031IRONICCLIENT_DIR=$DEST/python-ironicclient
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030032IRONIC_AUTH_CACHE_DIR=${IRONIC_AUTH_CACHE_DIR:-/var/cache/ironic}
33IRONIC_CONF_DIR=${IRONIC_CONF_DIR:-/etc/ironic}
34IRONIC_CONF_FILE=$IRONIC_CONF_DIR/ironic.conf
35IRONIC_ROOTWRAP_CONF=$IRONIC_CONF_DIR/rootwrap.conf
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030036IRONIC_POLICY_JSON=$IRONIC_CONF_DIR/policy.json
37
38# Support entry points installation of console scripts
39IRONIC_BIN_DIR=$(get_python_exec_prefix)
40
41# Ironic connection info. Note the port must be specified.
42IRONIC_SERVICE_PROTOCOL=http
43IRONIC_HOSTPORT=${IRONIC_HOSTPORT:-$SERVICE_HOST:6385}
44
Dean Troyer4237f592014-01-29 16:22:11 -060045# Tell Tempest this project is present
46TEMPEST_SERVICES+=,ironic
47
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030048
49# Functions
50# ---------
51
Roman Prykhodchenko43e00662013-10-15 17:03:15 +030052# install_ironic() - Collect source and prepare
53function install_ironic() {
54 git_clone $IRONIC_REPO $IRONIC_DIR $IRONIC_BRANCH
55 setup_develop $IRONIC_DIR
56}
57
58# install_ironicclient() - Collect sources and prepare
59function install_ironicclient() {
60 git_clone $IRONICCLIENT_REPO $IRONICCLIENT_DIR $IRONICCLIENT_BRANCH
61 setup_develop $IRONICCLIENT_DIR
62}
63
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030064# cleanup_ironic() - Remove residual data files, anything left over from previous
65# runs that would need to clean up.
66function cleanup_ironic() {
67 sudo rm -rf $IRONIC_AUTH_CACHE_DIR
68}
69
70# configure_ironic() - Set config files, create data dirs, etc
71function configure_ironic() {
72 if [[ ! -d $IRONIC_CONF_DIR ]]; then
73 sudo mkdir -p $IRONIC_CONF_DIR
74 fi
75 sudo chown $STACK_USER $IRONIC_CONF_DIR
76
77 # Copy over ironic configuration file and configure common parameters.
78 cp $IRONIC_DIR/etc/ironic/ironic.conf.sample $IRONIC_CONF_FILE
79 iniset $IRONIC_CONF_FILE DEFAULT debug True
80 inicomment $IRONIC_CONF_FILE DEFAULT log_file
81 iniset $IRONIC_CONF_FILE DEFAULT sql_connection `database_connection_url ironic`
82 iniset $IRONIC_CONF_FILE DEFAULT use_syslog $SYSLOG
83
84 # Configure Ironic conductor, if it was enabled.
85 if is_service_enabled ir-cond; then
86 configure_ironic_conductor
87 fi
88
89 # Configure Ironic API, if it was enabled.
90 if is_service_enabled ir-api; then
91 configure_ironic_api
92 fi
93}
94
95# configure_ironic_api() - Is used by configure_ironic(). Performs
96# API specific configuration.
97function configure_ironic_api() {
Roman Prykhodchenkoc48c3122013-10-01 17:19:05 +030098 iniset $IRONIC_CONF_FILE DEFAULT auth_strategy keystone
99 iniset $IRONIC_CONF_FILE DEFAULT policy_file $IRONIC_POLICY_JSON
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300100 iniset $IRONIC_CONF_FILE keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
101 iniset $IRONIC_CONF_FILE keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
102 iniset $IRONIC_CONF_FILE keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000103 iniset $IRONIC_CONF_FILE keystone_authtoken cafile $KEYSTONE_SSL_CA
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300104 iniset $IRONIC_CONF_FILE keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
105 iniset $IRONIC_CONF_FILE keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
106 iniset $IRONIC_CONF_FILE keystone_authtoken admin_user ironic
107 iniset $IRONIC_CONF_FILE keystone_authtoken admin_password $SERVICE_PASSWORD
108 if is_service_enabled qpid; then
109 iniset $IRONIC_CONF_FILE DEFAULT notifier_strategy qpid
110 elif [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then
111 iniset $IRONIC_CONF_FILE DEFAULT notifier_strategy rabbit
112 fi
113 iniset_rpc_backend ironic $IRONIC_CONF_FILE DEFAULT
114 iniset $IRONIC_CONF_FILE keystone_authtoken signing_dir $IRONIC_AUTH_CACHE_DIR/api
115
116 cp -p $IRONIC_DIR/etc/ironic/policy.json $IRONIC_POLICY_JSON
117}
118
119# configure_ironic_conductor() - Is used by configure_ironic().
120# Sets conductor specific settings.
121function configure_ironic_conductor() {
122 cp $IRONIC_DIR/etc/ironic/rootwrap.conf $IRONIC_ROOTWRAP_CONF
Lucas Alvares Gomes279295c2014-01-14 11:37:51 +0000123 cp -r $IRONIC_DIR/etc/ironic/rootwrap.d $IRONIC_CONF_DIR
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300124
125 iniset $IRONIC_CONF DEFAULT rootwrap_config $IRONIC_ROOTWRAP_CONF
126}
127
128# create_ironic_cache_dir() - Part of the init_ironic() process
129function create_ironic_cache_dir() {
130 # Create cache dir
131 sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/api
132 sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/api
133 rm -f $IRONIC_AUTH_CACHE_DIR/api/*
134 sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/registry
135 sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/registry
136 rm -f $IRONIC_AUTH_CACHE_DIR/registry/*
137}
138
139# create_ironic_accounts() - Set up common required ironic accounts
140
141# Tenant User Roles
142# ------------------------------------------------------------------
143# service ironic admin # if enabled
144create_ironic_accounts() {
145
146 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
147 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
148
149 # Ironic
150 if [[ "$ENABLED_SERVICES" =~ "ir-api" ]]; then
151 IRONIC_USER=$(keystone user-create \
152 --name=ironic \
153 --pass="$SERVICE_PASSWORD" \
Dirk Mueller25049cd2014-01-09 13:53:52 +0100154 --tenant-id $SERVICE_TENANT \
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300155 --email=ironic@example.com \
156 | grep " id " | get_field 2)
157 keystone user-role-add \
Dirk Mueller25049cd2014-01-09 13:53:52 +0100158 --tenant-id $SERVICE_TENANT \
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300159 --user_id $IRONIC_USER \
160 --role_id $ADMIN_ROLE
161 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
162 IRONIC_SERVICE=$(keystone service-create \
163 --name=ironic \
164 --type=baremetal \
165 --description="Ironic baremetal provisioning service" \
166 | grep " id " | get_field 2)
167 keystone endpoint-create \
168 --region RegionOne \
169 --service_id $IRONIC_SERVICE \
Roman Prykhodchenkof5002ef2013-09-24 19:09:26 +0300170 --publicurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
171 --adminurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
172 --internalurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT"
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300173 fi
174 fi
175}
176
177
178# init_ironic() - Initialize databases, etc.
179function init_ironic() {
180 # (Re)create ironic database
181 recreate_database ironic utf8
182
183 # Migrate ironic database
184 $IRONIC_BIN_DIR/ironic-dbsync
185
186 create_ironic_cache_dir
187
188 # Create keystone artifacts for Ironic.
189 create_ironic_accounts
190}
191
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300192# start_ironic() - Start running processes, including screen
193function start_ironic() {
194 # Start Ironic API server, if enabled.
195 if is_service_enabled ir-api; then
196 start_ironic_api
197 fi
198
199 # Start Ironic conductor, if enabled.
200 if is_service_enabled ir-cond; then
201 start_ironic_conductor
202 fi
203}
204
205# start_ironic_api() - Used by start_ironic().
206# Starts Ironic API server.
207function start_ironic_api() {
208 screen_it ir-api "cd $IRONIC_DIR; $IRONIC_BIN_DIR/ironic-api --config-file=$IRONIC_CONF_FILE"
209 echo "Waiting for ir-api ($IRONIC_HOSTPORT) to start..."
JUN JIE NAN0aa85342013-09-13 15:47:09 +0800210 if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q -O- http://$IRONIC_HOSTPORT; do sleep 1; done"; then
Sean Dague101b4242013-10-22 08:47:11 -0400211 die $LINENO "ir-api did not start"
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300212 fi
213}
214
215# start_ironic_conductor() - Used by start_ironic().
216# Starts Ironic conductor.
217function start_ironic_conductor() {
218 screen_it ir-cond "cd $IRONIC_DIR; $IRONIC_BIN_DIR/ironic-conductor --config-file=$IRONIC_CONF_FILE"
219 # TODO(romcheg): Find a way to check whether the conductor has started.
220}
221
222# stop_ironic() - Stop running processes
223function stop_ironic() {
224 # Kill the Ironic screen windows
225 screen -S $SCREEN_NAME -p ir-api -X kill
226 screen -S $SCREEN_NAME -p ir-cond -X kill
227}
228
229
230# Restore xtrace
231$XTRACE
232
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100233# Tell emacs to use shell-script-mode
234## Local variables:
235## mode: shell-script
236## End: