blob: 607b13125a78e9a2b78bb80d6f41b77be36f9a75 [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
Dean Troyer1023ff72014-01-27 14:56:44 -060052# Test if any Ironic services are enabled
53# is_ironic_enabled
54function is_ironic_enabled {
55 [[ ,${ENABLED_SERVICES} =~ ,"ir-" ]] && return 0
56 return 1
57}
58
Roman Prykhodchenko43e00662013-10-15 17:03:15 +030059# install_ironic() - Collect source and prepare
60function install_ironic() {
61 git_clone $IRONIC_REPO $IRONIC_DIR $IRONIC_BRANCH
62 setup_develop $IRONIC_DIR
63}
64
65# install_ironicclient() - Collect sources and prepare
66function install_ironicclient() {
67 git_clone $IRONICCLIENT_REPO $IRONICCLIENT_DIR $IRONICCLIENT_BRANCH
68 setup_develop $IRONICCLIENT_DIR
69}
70
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030071# cleanup_ironic() - Remove residual data files, anything left over from previous
72# runs that would need to clean up.
73function cleanup_ironic() {
74 sudo rm -rf $IRONIC_AUTH_CACHE_DIR
75}
76
77# configure_ironic() - Set config files, create data dirs, etc
78function configure_ironic() {
79 if [[ ! -d $IRONIC_CONF_DIR ]]; then
80 sudo mkdir -p $IRONIC_CONF_DIR
81 fi
82 sudo chown $STACK_USER $IRONIC_CONF_DIR
83
84 # Copy over ironic configuration file and configure common parameters.
85 cp $IRONIC_DIR/etc/ironic/ironic.conf.sample $IRONIC_CONF_FILE
86 iniset $IRONIC_CONF_FILE DEFAULT debug True
87 inicomment $IRONIC_CONF_FILE DEFAULT log_file
88 iniset $IRONIC_CONF_FILE DEFAULT sql_connection `database_connection_url ironic`
89 iniset $IRONIC_CONF_FILE DEFAULT use_syslog $SYSLOG
90
91 # Configure Ironic conductor, if it was enabled.
92 if is_service_enabled ir-cond; then
93 configure_ironic_conductor
94 fi
95
96 # Configure Ironic API, if it was enabled.
97 if is_service_enabled ir-api; then
98 configure_ironic_api
99 fi
100}
101
102# configure_ironic_api() - Is used by configure_ironic(). Performs
103# API specific configuration.
104function configure_ironic_api() {
Roman Prykhodchenkoc48c3122013-10-01 17:19:05 +0300105 iniset $IRONIC_CONF_FILE DEFAULT auth_strategy keystone
106 iniset $IRONIC_CONF_FILE DEFAULT policy_file $IRONIC_POLICY_JSON
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300107 iniset $IRONIC_CONF_FILE keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
108 iniset $IRONIC_CONF_FILE keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
109 iniset $IRONIC_CONF_FILE keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000110 iniset $IRONIC_CONF_FILE keystone_authtoken cafile $KEYSTONE_SSL_CA
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300111 iniset $IRONIC_CONF_FILE keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
112 iniset $IRONIC_CONF_FILE keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
113 iniset $IRONIC_CONF_FILE keystone_authtoken admin_user ironic
114 iniset $IRONIC_CONF_FILE keystone_authtoken admin_password $SERVICE_PASSWORD
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300115 iniset_rpc_backend ironic $IRONIC_CONF_FILE DEFAULT
116 iniset $IRONIC_CONF_FILE keystone_authtoken signing_dir $IRONIC_AUTH_CACHE_DIR/api
117
118 cp -p $IRONIC_DIR/etc/ironic/policy.json $IRONIC_POLICY_JSON
119}
120
121# configure_ironic_conductor() - Is used by configure_ironic().
122# Sets conductor specific settings.
123function configure_ironic_conductor() {
124 cp $IRONIC_DIR/etc/ironic/rootwrap.conf $IRONIC_ROOTWRAP_CONF
Lucas Alvares Gomes279295c2014-01-14 11:37:51 +0000125 cp -r $IRONIC_DIR/etc/ironic/rootwrap.d $IRONIC_CONF_DIR
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300126
127 iniset $IRONIC_CONF DEFAULT rootwrap_config $IRONIC_ROOTWRAP_CONF
128}
129
130# create_ironic_cache_dir() - Part of the init_ironic() process
131function create_ironic_cache_dir() {
132 # Create cache dir
133 sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/api
134 sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/api
135 rm -f $IRONIC_AUTH_CACHE_DIR/api/*
136 sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/registry
137 sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/registry
138 rm -f $IRONIC_AUTH_CACHE_DIR/registry/*
139}
140
141# create_ironic_accounts() - Set up common required ironic accounts
142
143# Tenant User Roles
144# ------------------------------------------------------------------
145# service ironic admin # if enabled
146create_ironic_accounts() {
147
Steve Martinelli19685422014-01-24 13:02:26 -0600148 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
149 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300150
151 # Ironic
152 if [[ "$ENABLED_SERVICES" =~ "ir-api" ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -0600153 IRONIC_USER=$(openstack user create \
154 ironic \
155 --password "$SERVICE_PASSWORD" \
156 --project $SERVICE_TENANT \
157 --email ironic@example.com \
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300158 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -0600159 openstack role add \
160 $ADMIN_ROLE \
161 --project $SERVICE_TENANT \
162 --user $IRONIC_USER
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300163 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -0600164 IRONIC_SERVICE=$(openstack service create \
165 ironic \
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300166 --type=baremetal \
167 --description="Ironic baremetal provisioning service" \
168 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -0600169 openstack endpoint create \
170 $IRONIC_SERVICE \
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300171 --region RegionOne \
Roman Prykhodchenkof5002ef2013-09-24 19:09:26 +0300172 --publicurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
173 --adminurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
174 --internalurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT"
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300175 fi
176 fi
177}
178
179
180# init_ironic() - Initialize databases, etc.
181function init_ironic() {
182 # (Re)create ironic database
183 recreate_database ironic utf8
184
185 # Migrate ironic database
186 $IRONIC_BIN_DIR/ironic-dbsync
187
188 create_ironic_cache_dir
189
190 # Create keystone artifacts for Ironic.
191 create_ironic_accounts
192}
193
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300194# start_ironic() - Start running processes, including screen
195function start_ironic() {
196 # Start Ironic API server, if enabled.
197 if is_service_enabled ir-api; then
198 start_ironic_api
199 fi
200
201 # Start Ironic conductor, if enabled.
202 if is_service_enabled ir-cond; then
203 start_ironic_conductor
204 fi
205}
206
207# start_ironic_api() - Used by start_ironic().
208# Starts Ironic API server.
209function start_ironic_api() {
210 screen_it ir-api "cd $IRONIC_DIR; $IRONIC_BIN_DIR/ironic-api --config-file=$IRONIC_CONF_FILE"
211 echo "Waiting for ir-api ($IRONIC_HOSTPORT) to start..."
JUN JIE NAN0aa85342013-09-13 15:47:09 +0800212 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 -0400213 die $LINENO "ir-api did not start"
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300214 fi
215}
216
217# start_ironic_conductor() - Used by start_ironic().
218# Starts Ironic conductor.
219function start_ironic_conductor() {
220 screen_it ir-cond "cd $IRONIC_DIR; $IRONIC_BIN_DIR/ironic-conductor --config-file=$IRONIC_CONF_FILE"
221 # TODO(romcheg): Find a way to check whether the conductor has started.
222}
223
224# stop_ironic() - Stop running processes
225function stop_ironic() {
226 # Kill the Ironic screen windows
227 screen -S $SCREEN_NAME -p ir-api -X kill
228 screen -S $SCREEN_NAME -p ir-cond -X kill
229}
230
231
232# Restore xtrace
233$XTRACE
234
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100235# Tell emacs to use shell-script-mode
236## Local variables:
237## mode: shell-script
238## End: