blob: dd4f8bf65f6b6e20400fde0bccf99cde67ee4e0b [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +03003# lib/ironic
4# Functions to control the configuration and operation of the **Ironic** service
5
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
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030013
14# ``stack.sh`` calls the entry points in this order:
15#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010016# - install_ironic
17# - install_ironicclient
18# - init_ironic
19# - start_ironic
20# - stop_ironic
21# - cleanup_ironic
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030022
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040023# Save trace and pipefail settings
Ian Wienand523f4882015-10-13 11:03:03 +110024_XTRACE_IRONIC=$(set +o | grep xtrace)
25_PIPEFAIL_IRONIC=$(set +o | grep pipefail)
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030026set +o xtrace
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040027set +o pipefail
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030028
Jim Rollenhagen9fc3ba42015-12-10 13:33:28 +000029# NOTE(jroll) this is used for the transition to a devstack plugin in
30# the ironic tree.
31IRONIC_USING_PLUGIN=$(trueorfalse False IRONIC_USING_PLUGIN)
32if [[ "$IRONIC_USING_PLUGIN" == "True" ]] ; then
33 return 0
34fi
35
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030036# Defaults
37# --------
38
39# Set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050040GITDIR["python-ironicclient"]=$DEST/python-ironicclient
Dmitry Tantsur869b72b2015-08-13 13:36:23 +020041GITDIR["ironic-lib"]=$DEST/ironic-lib
Sean Dague5cb19062014-11-01 01:37:45 +010042
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030043IRONIC_DIR=$DEST/ironic
Jim Rollenhagenf00766b2014-08-15 01:08:11 +000044IRONIC_PYTHON_AGENT_DIR=$DEST/ironic-python-agent
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040045IRONIC_DATA_DIR=$DATA_DIR/ironic
46IRONIC_STATE_PATH=/var/lib/ironic
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030047IRONIC_AUTH_CACHE_DIR=${IRONIC_AUTH_CACHE_DIR:-/var/cache/ironic}
48IRONIC_CONF_DIR=${IRONIC_CONF_DIR:-/etc/ironic}
49IRONIC_CONF_FILE=$IRONIC_CONF_DIR/ironic.conf
50IRONIC_ROOTWRAP_CONF=$IRONIC_CONF_DIR/rootwrap.conf
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030051IRONIC_POLICY_JSON=$IRONIC_CONF_DIR/policy.json
52
Adam Gandelmanf303d7e2015-01-06 12:18:03 -080053# Deploy callback timeout can be changed from its default (1800), if required.
54IRONIC_CALLBACK_TIMEOUT=${IRONIC_CALLBACK_TIMEOUT:-}
55
yunhong jiangae9ee6b2014-10-08 07:01:02 -070056# Deploy to hardware platform
57IRONIC_HW_NODE_CPU=${IRONIC_HW_NODE_CPU:-1}
58IRONIC_HW_NODE_RAM=${IRONIC_HW_NODE_RAM:-512}
59IRONIC_HW_NODE_DISK=${IRONIC_HW_NODE_DISK:-10}
60IRONIC_HW_EPHEMERAL_DISK=${IRONIC_HW_EPHEMERAL_DISK:-0}
61# The file is composed of multiple lines, each line includes four field
62# separated by white space: IPMI address, MAC address, IPMI username
63# and IPMI password.
Dean Troyerdc97cb72015-03-28 08:20:50 -050064#
yunhong jiangae9ee6b2014-10-08 07:01:02 -070065# 192.168.110.107 00:1e:67:57:50:4c root otc123
66IRONIC_IPMIINFO_FILE=${IRONIC_IPMIINFO_FILE:-$IRONIC_DATA_DIR/hardware_info}
67
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040068# Set up defaults for functional / integration testing
Vladyslav Drok41309002015-04-29 13:36:52 +030069IRONIC_NODE_UUID=${IRONIC_NODE_UUID:-`uuidgen`}
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040070IRONIC_SCRIPTS_DIR=${IRONIC_SCRIPTS_DIR:-$TOP_DIR/tools/ironic/scripts}
71IRONIC_TEMPLATES_DIR=${IRONIC_TEMPLATES_DIR:-$TOP_DIR/tools/ironic/templates}
Sean Dague53753292014-12-04 19:38:15 -050072IRONIC_BAREMETAL_BASIC_OPS=$(trueorfalse False IRONIC_BAREMETAL_BASIC_OPS)
Devananda van der Veen83eeed02014-04-11 10:08:41 -070073IRONIC_ENABLED_DRIVERS=${IRONIC_ENABLED_DRIVERS:-fake,pxe_ssh,pxe_ipmitool}
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040074IRONIC_SSH_USERNAME=${IRONIC_SSH_USERNAME:-`whoami`}
Zhenzan Zhou80cdbc42015-03-16 12:30:44 +080075IRONIC_SSH_TIMEOUT=${IRONIC_SSH_TIMEOUT:-15}
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040076IRONIC_SSH_KEY_DIR=${IRONIC_SSH_KEY_DIR:-$IRONIC_DATA_DIR/ssh_keys}
77IRONIC_SSH_KEY_FILENAME=${IRONIC_SSH_KEY_FILENAME:-ironic_key}
Adam Gandelman6c749322014-12-02 16:20:50 -080078IRONIC_KEY_FILE=${IRONIC_KEY_FILE:-$IRONIC_SSH_KEY_DIR/$IRONIC_SSH_KEY_FILENAME}
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040079IRONIC_SSH_VIRT_TYPE=${IRONIC_SSH_VIRT_TYPE:-virsh}
80IRONIC_TFTPBOOT_DIR=${IRONIC_TFTPBOOT_DIR:-$IRONIC_DATA_DIR/tftpboot}
yunhong jiangae9ee6b2014-10-08 07:01:02 -070081IRONIC_TFTPSERVER_IP=${IRONIC_TFTPSERVER_IP:-$HOST_IP}
Adam Gandelman86765102014-04-14 11:57:13 -070082IRONIC_VM_SSH_PORT=${IRONIC_VM_SSH_PORT:-22}
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040083IRONIC_VM_SSH_ADDRESS=${IRONIC_VM_SSH_ADDRESS:-$HOST_IP}
84IRONIC_VM_COUNT=${IRONIC_VM_COUNT:-1}
85IRONIC_VM_SPECS_CPU=${IRONIC_VM_SPECS_CPU:-1}
Adam Gandelmanea335f42014-07-03 17:57:49 -070086IRONIC_VM_SPECS_RAM=${IRONIC_VM_SPECS_RAM:-512}
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040087IRONIC_VM_SPECS_DISK=${IRONIC_VM_SPECS_DISK:-10}
David Shrewsbury3e4612b2014-05-01 11:38:21 -040088IRONIC_VM_EPHEMERAL_DISK=${IRONIC_VM_EPHEMERAL_DISK:-0}
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040089IRONIC_VM_EMULATOR=${IRONIC_VM_EMULATOR:-/usr/bin/qemu-system-x86_64}
90IRONIC_VM_NETWORK_BRIDGE=${IRONIC_VM_NETWORK_BRIDGE:-brbm}
91IRONIC_VM_NETWORK_RANGE=${IRONIC_VM_NETWORK_RANGE:-192.0.2.0/24}
92IRONIC_VM_MACS_CSV_FILE=${IRONIC_VM_MACS_CSV_FILE:-$IRONIC_DATA_DIR/ironic_macs.csv}
93IRONIC_AUTHORIZED_KEYS_FILE=${IRONIC_AUTHORIZED_KEYS_FILE:-$HOME/.ssh/authorized_keys}
94
Adam Gandelman8af6fae2014-04-11 17:06:14 -070095# By default, baremetal VMs will console output to file.
96IRONIC_VM_LOG_CONSOLE=${IRONIC_VM_LOG_CONSOLE:-True}
97IRONIC_VM_LOG_DIR=${IRONIC_VM_LOG_DIR:-$IRONIC_DATA_DIR/logs/}
98
Alexander Gordeevf177f722014-03-14 18:44:48 +040099# Use DIB to create deploy ramdisk and kernel.
Sean Dague53753292014-12-04 19:38:15 -0500100IRONIC_BUILD_DEPLOY_RAMDISK=$(trueorfalse True IRONIC_BUILD_DEPLOY_RAMDISK)
Alexander Gordeevf177f722014-03-14 18:44:48 +0400101# If not use DIB, these files are used as deploy ramdisk/kernel.
Swapnil Kulkarni (coolsvap)7f0be4f2015-11-20 10:52:59 +0530102# (The value must be an absolute path)
Alexander Gordeevf177f722014-03-14 18:44:48 +0400103IRONIC_DEPLOY_RAMDISK=${IRONIC_DEPLOY_RAMDISK:-}
104IRONIC_DEPLOY_KERNEL=${IRONIC_DEPLOY_KERNEL:-}
105IRONIC_DEPLOY_ELEMENT=${IRONIC_DEPLOY_ELEMENT:-deploy-ironic}
106
Jim Rollenhagen792dc5f2014-08-27 17:03:00 -0700107IRONIC_AGENT_KERNEL_URL=${IRONIC_AGENT_KERNEL_URL:-http://tarballs.openstack.org/ironic-python-agent/coreos/files/coreos_production_pxe.vmlinuz}
Jim Rollenhagen4cb0d8c2014-09-11 16:45:58 -0700108IRONIC_AGENT_RAMDISK_URL=${IRONIC_AGENT_RAMDISK_URL:-http://tarballs.openstack.org/ironic-python-agent/coreos/files/coreos_production_pxe_image-oem.cpio.gz}
Jim Rollenhagena6a45462014-08-05 18:08:29 +0000109
110# Which deploy driver to use - valid choices right now
Dean Troyerdc97cb72015-03-28 08:20:50 -0500111# are ``pxe_ssh``, ``pxe_ipmitool``, ``agent_ssh`` and ``agent_ipmitool``.
Jim Rollenhagena6a45462014-08-05 18:08:29 +0000112IRONIC_DEPLOY_DRIVER=${IRONIC_DEPLOY_DRIVER:-pxe_ssh}
113
Dean Troyerdc97cb72015-03-28 08:20:50 -0500114# TODO(agordeev): replace 'ubuntu' with host distro name getting
Alexander Gordeevf177f722014-03-14 18:44:48 +0400115IRONIC_DEPLOY_FLAVOR=${IRONIC_DEPLOY_FLAVOR:-ubuntu $IRONIC_DEPLOY_ELEMENT}
116
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300117# Support entry points installation of console scripts
118IRONIC_BIN_DIR=$(get_python_exec_prefix)
119
120# Ironic connection info. Note the port must be specified.
121IRONIC_SERVICE_PROTOCOL=http
Adam Gandelman4b45fca2014-11-17 09:59:23 -0800122IRONIC_SERVICE_PORT=${IRONIC_SERVICE_PORT:-6385}
123IRONIC_HOSTPORT=${IRONIC_HOSTPORT:-$SERVICE_HOST:$IRONIC_SERVICE_PORT}
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300124
Lucas Alvares Gomes5851e5f2014-08-19 10:01:45 +0100125# Enable iPXE
Sean Dague53753292014-12-04 19:38:15 -0500126IRONIC_IPXE_ENABLED=$(trueorfalse False IRONIC_IPXE_ENABLED)
Lucas Alvares Gomes5851e5f2014-08-19 10:01:45 +0100127IRONIC_HTTP_DIR=${IRONIC_HTTP_DIR:-$IRONIC_DATA_DIR/httpboot}
128IRONIC_HTTP_SERVER=${IRONIC_HTTP_SERVER:-$HOST_IP}
129IRONIC_HTTP_PORT=${IRONIC_HTTP_PORT:-8088}
130
Lucas Alvares Gomes1d3a6ec2015-02-25 12:38:47 +0000131# NOTE(lucasagomes): This flag is used to differentiate the nodes that
132# uses IPA as their deploy ramdisk from nodes that uses the agent_* drivers
133# (which also uses IPA but depends on Swift Temp URLs to work). At present,
134# all drivers that uses the iSCSI approach for their deployment supports
135# using both, IPA or bash ramdisks for the deployment. In the future we
136# want to remove the support for the bash ramdisk in favor of IPA, once
137# we get there this flag can be removed, and all conditionals that uses
138# it should just run by default.
139IRONIC_DEPLOY_DRIVER_ISCSI_WITH_IPA=$(trueorfalse False IRONIC_DEPLOY_DRIVER_ISCSI_WITH_IPA)
140
Lucas Alvares Gomes5851e5f2014-08-19 10:01:45 +0100141# get_pxe_boot_file() - Get the PXE/iPXE boot file path
142function get_pxe_boot_file {
143 local relpath=syslinux/pxelinux.0
144 if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
145 relpath=ipxe/undionly.kpxe
146 fi
147
148 local pxe_boot_file
149 if is_ubuntu; then
150 pxe_boot_file=/usr/lib/$relpath
151 elif is_fedora || is_suse; then
152 pxe_boot_file=/usr/share/$relpath
153 fi
154
155 echo $pxe_boot_file
156}
157
158# PXE boot image
159IRONIC_PXE_BOOT_IMAGE=${IRONIC_PXE_BOOT_IMAGE:-$(get_pxe_boot_file)}
160
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300161
162# Functions
163# ---------
164
Dean Troyer1023ff72014-01-27 14:56:44 -0600165# Test if any Ironic services are enabled
166# is_ironic_enabled
167function is_ironic_enabled {
168 [[ ,${ENABLED_SERVICES} =~ ,"ir-" ]] && return 0
169 return 1
170}
171
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700172function is_ironic_hardware {
173 is_ironic_enabled && [[ -n "${IRONIC_DEPLOY_DRIVER##*_ssh}" ]] && return 0
174 return 1
175}
176
yunhong jiangfe96ed62014-11-05 03:30:25 -0700177function is_deployed_by_agent {
178 [[ -z "${IRONIC_DEPLOY_DRIVER%%agent*}" ]] && return 0
179 return 1
180}
181
Lucas Alvares Gomes1d3a6ec2015-02-25 12:38:47 +0000182function is_deployed_with_ipa_ramdisk {
183 is_deployed_by_agent || [[ "$IRONIC_DEPLOY_DRIVER_ISCSI_WITH_IPA" == "True" ]] && return 0
184 return 1
185}
186
Roman Prykhodchenko43e00662013-10-15 17:03:15 +0300187# install_ironic() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100188function install_ironic {
Adam Gandelman6d271482014-08-05 18:12:29 -0700189 # make sure all needed service were enabled
Adam Gandelmanfab78802015-03-26 13:03:49 -0700190 local req_services="key"
Adam Gandelmande77c472015-03-11 17:15:42 -0700191 if [[ "$VIRT_DRIVER" == "ironic" ]]; then
192 req_services+=" nova glance neutron"
193 fi
194 for srv in $req_services; do
Adam Gandelman6d271482014-08-05 18:12:29 -0700195 if ! is_service_enabled "$srv"; then
196 die $LINENO "$srv should be enabled for Ironic."
197 fi
198 done
Dmitry Tantsur869b72b2015-08-13 13:36:23 +0200199
200 if use_library_from_git "ironic-lib"; then
201 git_clone_by_name "ironic-lib"
202 setup_dev_lib "ironic-lib"
203 fi
204
Roman Prykhodchenko43e00662013-10-15 17:03:15 +0300205 git_clone $IRONIC_REPO $IRONIC_DIR $IRONIC_BRANCH
206 setup_develop $IRONIC_DIR
Lucas Alvares Gomes5851e5f2014-08-19 10:01:45 +0100207
208 if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
209 install_apache_wsgi
210 fi
Roman Prykhodchenko43e00662013-10-15 17:03:15 +0300211}
212
213# install_ironicclient() - Collect sources and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100214function install_ironicclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500215 if use_library_from_git "python-ironicclient"; then
216 git_clone_by_name "python-ironicclient"
217 setup_dev_lib "python-ironicclient"
218 sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-ironicclient"]}/tools/,/etc/bash_completion.d/}ironic.bash_completion
Sean Dague5cb19062014-11-01 01:37:45 +0100219 else
220 # nothing actually "requires" ironicclient, so force instally from pypi
Sean Dague60996b12015-04-08 09:06:49 -0400221 pip_install_gr python-ironicclient
Sean Dague5cb19062014-11-01 01:37:45 +0100222 fi
Roman Prykhodchenko43e00662013-10-15 17:03:15 +0300223}
224
Lucas Alvares Gomes5851e5f2014-08-19 10:01:45 +0100225# _cleanup_ironic_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
226function _cleanup_ironic_apache_wsgi {
227 sudo rm -rf $IRONIC_HTTP_DIR
228 disable_apache_site ironic
229 sudo rm -f $(apache_site_config_for ironic)
230 restart_apache_server
231}
232
233# _config_ironic_apache_wsgi() - Set WSGI config files of Ironic
234function _config_ironic_apache_wsgi {
Ian Wienandada886d2015-10-07 14:06:26 +1100235 local ironic_apache_conf
236 ironic_apache_conf=$(apache_site_config_for ironic)
Lucas Alvares Gomes5851e5f2014-08-19 10:01:45 +0100237 sudo cp $FILES/apache-ironic.template $ironic_apache_conf
238 sudo sed -e "
239 s|%PUBLICPORT%|$IRONIC_HTTP_PORT|g;
240 s|%HTTPROOT%|$IRONIC_HTTP_DIR|g;
241 " -i $ironic_apache_conf
242 enable_apache_site ironic
243}
244
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300245# cleanup_ironic() - Remove residual data files, anything left over from previous
246# runs that would need to clean up.
Ian Wienandaee18c72014-02-21 15:35:08 +1100247function cleanup_ironic {
lokesh683ed9e2014-11-10 15:07:59 +0530248 sudo rm -rf $IRONIC_AUTH_CACHE_DIR $IRONIC_CONF_DIR
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300249}
250
Adam Gandelman6d271482014-08-05 18:12:29 -0700251# configure_ironic_dirs() - Create all directories required by Ironic and
252# associated services.
253function configure_ironic_dirs {
Dean Troyer8421c2b2015-03-16 13:52:19 -0500254 sudo install -d -o $STACK_USER $IRONIC_CONF_DIR $STACK_USER $IRONIC_DATA_DIR \
255 $IRONIC_STATE_PATH $IRONIC_TFTPBOOT_DIR $IRONIC_TFTPBOOT_DIR/pxelinux.cfg
256 sudo chown -R $STACK_USER:$LIBVIRT_GROUP $IRONIC_TFTPBOOT_DIR
Lucas Alvares Gomes5851e5f2014-08-19 10:01:45 +0100257
258 if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
Dean Troyer8421c2b2015-03-16 13:52:19 -0500259 sudo install -d -o $STACK_USER -g $LIBVIRT_GROUP $IRONIC_HTTP_DIR
Lucas Alvares Gomes5851e5f2014-08-19 10:01:45 +0100260 fi
261
Lucas Alvares Gomes5851e5f2014-08-19 10:01:45 +0100262 if [ ! -f $IRONIC_PXE_BOOT_IMAGE ]; then
263 die $LINENO "PXE boot file $IRONIC_PXE_BOOT_IMAGE not found."
Adam Gandelman6d271482014-08-05 18:12:29 -0700264 fi
265
Lucas Alvares Gomesc08d5472015-02-23 15:39:22 +0000266 # Copy PXE binary
267 if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
268 cp $IRONIC_PXE_BOOT_IMAGE $IRONIC_TFTPBOOT_DIR
269 else
270 # Syslinux >= 5.00 pxelinux.0 binary is not "stand-alone" anymore,
271 # it depends on some c32 modules to work correctly.
272 # More info: http://www.syslinux.org/wiki/index.php/Library_modules
273 cp -aR $(dirname $IRONIC_PXE_BOOT_IMAGE)/*.{c32,0} $IRONIC_TFTPBOOT_DIR
274 fi
Adam Gandelman6d271482014-08-05 18:12:29 -0700275}
276
277# configure_ironic() - Set config files, create data dirs, etc
278function configure_ironic {
279 configure_ironic_dirs
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300280
281 # Copy over ironic configuration file and configure common parameters.
282 cp $IRONIC_DIR/etc/ironic/ironic.conf.sample $IRONIC_CONF_FILE
283 iniset $IRONIC_CONF_FILE DEFAULT debug True
284 inicomment $IRONIC_CONF_FILE DEFAULT log_file
Joe Gordon23d6d502015-03-06 15:24:22 -0800285 iniset $IRONIC_CONF_FILE database connection `database_connection_url ironic`
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400286 iniset $IRONIC_CONF_FILE DEFAULT state_path $IRONIC_STATE_PATH
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300287 iniset $IRONIC_CONF_FILE DEFAULT use_syslog $SYSLOG
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300288 # Configure Ironic conductor, if it was enabled.
289 if is_service_enabled ir-cond; then
290 configure_ironic_conductor
291 fi
292
293 # Configure Ironic API, if it was enabled.
294 if is_service_enabled ir-api; then
295 configure_ironic_api
296 fi
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400297
Adam Gandelmanab592932014-06-06 15:12:32 -0700298 # Format logging
299 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Lucas Alvares Gomes010963c2015-06-23 14:16:39 +0100300 setup_colorized_logging $IRONIC_CONF_FILE DEFAULT tenant user
Adam Gandelmanab592932014-06-06 15:12:32 -0700301 fi
Lucas Alvares Gomes5851e5f2014-08-19 10:01:45 +0100302
303 if [[ "$IRONIC_IPXE_ENABLED" == "True" ]]; then
304 _config_ironic_apache_wsgi
305 fi
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300306}
307
308# configure_ironic_api() - Is used by configure_ironic(). Performs
309# API specific configuration.
Ian Wienandaee18c72014-02-21 15:35:08 +1100310function configure_ironic_api {
Roman Prykhodchenkoc48c3122013-10-01 17:19:05 +0300311 iniset $IRONIC_CONF_FILE DEFAULT auth_strategy keystone
Chris Dent74a85b02015-04-22 18:02:39 +0000312 iniset $IRONIC_CONF_FILE oslo_policy policy_file $IRONIC_POLICY_JSON
Yuki Nishiwakid5323972015-02-17 19:00:23 +0900313
314 # TODO(Yuki Nishiwaki): This is a temporary work-around until Ironic is fixed(bug#1422632).
315 # These codes need to be changed to use the function of configure_auth_token_middleware
316 # after Ironic conforms to the new auth plugin.
317 iniset $IRONIC_CONF_FILE keystone_authtoken identity_uri $KEYSTONE_AUTH_URI
318 iniset $IRONIC_CONF_FILE keystone_authtoken auth_uri $KEYSTONE_SERVICE_URI/v2.0
319 iniset $IRONIC_CONF_FILE keystone_authtoken admin_user ironic
320 iniset $IRONIC_CONF_FILE keystone_authtoken admin_password $SERVICE_PASSWORD
321 iniset $IRONIC_CONF_FILE keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
322 iniset $IRONIC_CONF_FILE keystone_authtoken cafile $SSL_BUNDLE_FILE
323 iniset $IRONIC_CONF_FILE keystone_authtoken signing_dir $IRONIC_AUTH_CACHE_DIR/api
324
Brant Knudson2dd110c2015-03-14 12:39:14 -0500325 iniset_rpc_backend ironic $IRONIC_CONF_FILE
Adam Gandelman4b45fca2014-11-17 09:59:23 -0800326 iniset $IRONIC_CONF_FILE api port $IRONIC_SERVICE_PORT
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300327
328 cp -p $IRONIC_DIR/etc/ironic/policy.json $IRONIC_POLICY_JSON
329}
330
331# configure_ironic_conductor() - Is used by configure_ironic().
332# Sets conductor specific settings.
Ian Wienandaee18c72014-02-21 15:35:08 +1100333function configure_ironic_conductor {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300334 cp $IRONIC_DIR/etc/ironic/rootwrap.conf $IRONIC_ROOTWRAP_CONF
Lucas Alvares Gomes279295c2014-01-14 11:37:51 +0000335 cp -r $IRONIC_DIR/etc/ironic/rootwrap.d $IRONIC_CONF_DIR
Ian Wienandada886d2015-10-07 14:06:26 +1100336 local ironic_rootwrap
337 ironic_rootwrap=$(get_rootwrap_location ironic)
Dean Troyerb52caa32014-07-25 13:04:13 -0500338 local rootwrap_isudoer_cmd="$ironic_rootwrap $IRONIC_CONF_DIR/rootwrap.conf *"
Adam Gandelman3f2a7b72014-04-14 16:14:33 -0700339
340 # Set up the rootwrap sudoers for ironic
Ian Wienandada886d2015-10-07 14:06:26 +1100341 local tempfile
342 tempfile=`mktemp`
Dean Troyerb52caa32014-07-25 13:04:13 -0500343 echo "$STACK_USER ALL=(root) NOPASSWD: $rootwrap_isudoer_cmd" >$tempfile
344 chmod 0440 $tempfile
345 sudo chown root:root $tempfile
346 sudo mv $tempfile /etc/sudoers.d/ironic-rootwrap
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300347
Alexander Gordeeva67cb1a2014-03-04 18:38:33 +0400348 iniset $IRONIC_CONF_FILE DEFAULT rootwrap_config $IRONIC_ROOTWRAP_CONF
Devananda van der Veen83eeed02014-04-11 10:08:41 -0700349 iniset $IRONIC_CONF_FILE DEFAULT enabled_drivers $IRONIC_ENABLED_DRIVERS
Adam Gandelman4b45fca2014-11-17 09:59:23 -0800350 iniset $IRONIC_CONF_FILE conductor api_url $IRONIC_SERVICE_PROTOCOL://$HOST_IP:$IRONIC_SERVICE_PORT
Adam Gandelmanf303d7e2015-01-06 12:18:03 -0800351 if [[ -n "$IRONIC_CALLBACK_TIMEOUT" ]]; then
352 iniset $IRONIC_CONF_FILE conductor deploy_callback_timeout $IRONIC_CALLBACK_TIMEOUT
353 fi
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700354 iniset $IRONIC_CONF_FILE pxe tftp_server $IRONIC_TFTPSERVER_IP
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400355 iniset $IRONIC_CONF_FILE pxe tftp_root $IRONIC_TFTPBOOT_DIR
356 iniset $IRONIC_CONF_FILE pxe tftp_master_path $IRONIC_TFTPBOOT_DIR/master_images
Adam Gandelman8c32e0d2015-03-04 14:53:05 -0800357
358 local pxe_params=""
Adam Gandelman8af6fae2014-04-11 17:06:14 -0700359 if [[ "$IRONIC_VM_LOG_CONSOLE" == "True" ]] ; then
Adam Gandelman8c32e0d2015-03-04 14:53:05 -0800360 pxe_params+="nofb nomodeset vga=normal console=ttyS0"
Lucas Alvares Gomes1d3a6ec2015-02-25 12:38:47 +0000361 if is_deployed_with_ipa_ramdisk; then
362 pxe_params+=" systemd.journald.forward_to_console=yes"
363 fi
Adam Gandelman8c32e0d2015-03-04 14:53:05 -0800364 fi
365 # When booting with less than 1GB, we need to switch from default tmpfs
366 # to ramfs for ramdisks to decompress successfully.
367 if (is_ironic_hardware && [[ "$IRONIC_HW_NODE_RAM" -lt 1024 ]]) ||
368 (! is_ironic_hardware && [[ "$IRONIC_VM_SPECS_RAM" -lt 1024 ]]); then
369 pxe_params+=" rootfstype=ramfs"
370 fi
371 if [[ -n "$pxe_params" ]]; then
Lucas Alvares Gomes1d3a6ec2015-02-25 12:38:47 +0000372 iniset $IRONIC_CONF_FILE pxe pxe_append_params "$pxe_params"
Adam Gandelman8af6fae2014-04-11 17:06:14 -0700373 fi
Adam Gandelman8c32e0d2015-03-04 14:53:05 -0800374
Devananda van der Veen2391d432015-12-03 09:16:18 -0800375 # Set these options for scenarios in which the agent fetches the image
376 # directly from glance, and don't set them where the image is pushed
377 # over iSCSI.
yunhong jiangfe96ed62014-11-05 03:30:25 -0700378 if is_deployed_by_agent; then
Jim Rollenhagena6a45462014-08-05 18:08:29 +0000379 if [[ "$SWIFT_ENABLE_TEMPURLS" == "True" ]] ; then
380 iniset $IRONIC_CONF_FILE glance swift_temp_url_key $SWIFT_TEMPURL_KEY
381 else
382 die $LINENO "SWIFT_ENABLE_TEMPURLS must be True to use agent_ssh driver in Ironic."
383 fi
Jim Rollenhagen74b28bc2014-10-29 14:15:22 -0700384 iniset $IRONIC_CONF_FILE glance swift_endpoint_url http://${HOST_IP}:${SWIFT_DEFAULT_BIND_PORT:-8080}
Jim Rollenhagena6a45462014-08-05 18:08:29 +0000385 iniset $IRONIC_CONF_FILE glance swift_api_version v1
Ian Wienandada886d2015-10-07 14:06:26 +1100386 local tenant_id
387 tenant_id=$(get_or_create_project $SERVICE_TENANT_NAME default)
Adam Gandelmanab50c702014-10-22 13:21:22 -0700388 iniset $IRONIC_CONF_FILE glance swift_account AUTH_${tenant_id}
Jim Rollenhagena6a45462014-08-05 18:08:29 +0000389 iniset $IRONIC_CONF_FILE glance swift_container glance
390 iniset $IRONIC_CONF_FILE glance swift_temp_url_duration 3600
391 iniset $IRONIC_CONF_FILE agent heartbeat_timeout 30
Jim Rollenhagena6a45462014-08-05 18:08:29 +0000392 fi
Lucas Alvares Gomes5851e5f2014-08-19 10:01:45 +0100393
Devananda van der Veen2391d432015-12-03 09:16:18 -0800394 # FIXME: this really needs to be tested in the gate.
395 # For now, any test using the agent ramdisk should skip cleaning
396 # because it is too slow to run in the gate.
397 iniset $IRONIC_CONF_FILE agent agent_erase_devices_priority 0
398
Lucas Alvares Gomes5851e5f2014-08-19 10:01:45 +0100399 if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
Ian Wienandada886d2015-10-07 14:06:26 +1100400 local pxebin
401 pxebin=`basename $IRONIC_PXE_BOOT_IMAGE`
Lucas Alvares Gomes5851e5f2014-08-19 10:01:45 +0100402 iniset $IRONIC_CONF_FILE pxe ipxe_enabled True
403 iniset $IRONIC_CONF_FILE pxe pxe_config_template '\$pybasedir/drivers/modules/ipxe_config.template'
404 iniset $IRONIC_CONF_FILE pxe pxe_bootfile_name $pxebin
405 iniset $IRONIC_CONF_FILE pxe http_root $IRONIC_HTTP_DIR
406 iniset $IRONIC_CONF_FILE pxe http_url "http://$IRONIC_HTTP_SERVER:$IRONIC_HTTP_PORT"
407 fi
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300408}
409
410# create_ironic_cache_dir() - Part of the init_ironic() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100411function create_ironic_cache_dir {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300412 # Create cache dir
413 sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/api
414 sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/api
415 rm -f $IRONIC_AUTH_CACHE_DIR/api/*
416 sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/registry
417 sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/registry
418 rm -f $IRONIC_AUTH_CACHE_DIR/registry/*
419}
420
421# create_ironic_accounts() - Set up common required ironic accounts
422
423# Tenant User Roles
424# ------------------------------------------------------------------
425# service ironic admin # if enabled
Ian Wienandaee18c72014-02-21 15:35:08 +1100426function create_ironic_accounts {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300427
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300428 # Ironic
429 if [[ "$ENABLED_SERVICES" =~ "ir-api" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100430 # Get ironic user if exists
431
David Shrewsburycdfcd4b2015-02-11 16:07:40 -0800432 # NOTE(Shrews): This user MUST have admin level privileges!
433 create_service_user "ironic" "admin"
Bartosz Górski0abde392014-02-28 14:15:19 +0100434
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300435 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100436
Jamie Lennoxb17ad752015-05-29 06:04:47 +0000437 get_or_create_service "ironic" "baremetal" "Ironic baremetal provisioning service"
438 get_or_create_endpoint "baremetal" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100439 "$REGION_NAME" \
440 "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
441 "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
442 "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT"
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300443 fi
444 fi
445}
446
447
448# init_ironic() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100449function init_ironic {
Josh Gachnangee78c9e2015-03-16 23:24:52 -0700450 # Save private network as cleaning network
451 local cleaning_network_uuid
452 cleaning_network_uuid=$(neutron net-list | grep private | get_field 1)
453 iniset $IRONIC_CONF_FILE neutron cleaning_network_uuid ${cleaning_network_uuid}
454
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300455 # (Re)create ironic database
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200456 recreate_database ironic
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300457
458 # Migrate ironic database
Dmitry Tantsur0c6a6542014-06-02 20:19:33 +0200459 $IRONIC_BIN_DIR/ironic-dbsync --config-file=$IRONIC_CONF_FILE
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300460
461 create_ironic_cache_dir
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300462}
463
Adam Gandelman22ec45e2014-10-16 17:41:22 -0700464# _ironic_bm_vm_names() - Generates list of names for baremetal VMs.
465function _ironic_bm_vm_names {
466 local idx
Ian Wienandada886d2015-10-07 14:06:26 +1100467 local num_vms
468 num_vms=$(($IRONIC_VM_COUNT - 1))
Adam Gandelman22ec45e2014-10-16 17:41:22 -0700469 for idx in $(seq 0 $num_vms); do
470 echo "baremetal${IRONIC_VM_NETWORK_BRIDGE}_${idx}"
471 done
472}
473
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300474# start_ironic() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100475function start_ironic {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300476 # Start Ironic API server, if enabled.
477 if is_service_enabled ir-api; then
478 start_ironic_api
479 fi
480
481 # Start Ironic conductor, if enabled.
482 if is_service_enabled ir-cond; then
483 start_ironic_conductor
484 fi
Lucas Alvares Gomes5851e5f2014-08-19 10:01:45 +0100485
486 # Start Apache if iPXE is enabled
487 if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
488 restart_apache_server
489 fi
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300490}
491
492# start_ironic_api() - Used by start_ironic().
493# Starts Ironic API server.
Ian Wienandaee18c72014-02-21 15:35:08 +1100494function start_ironic_api {
Chris Dent2f27a0e2014-09-09 13:46:02 +0100495 run_process ir-api "$IRONIC_BIN_DIR/ironic-api --config-file=$IRONIC_CONF_FILE"
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300496 echo "Waiting for ir-api ($IRONIC_HOSTPORT) to start..."
Adam Gandelman4b45fca2014-11-17 09:59:23 -0800497 if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q -O- $IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT; do sleep 1; done"; then
Sean Dague101b4242013-10-22 08:47:11 -0400498 die $LINENO "ir-api did not start"
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300499 fi
500}
501
502# start_ironic_conductor() - Used by start_ironic().
503# Starts Ironic conductor.
Ian Wienandaee18c72014-02-21 15:35:08 +1100504function start_ironic_conductor {
Chris Dent2f27a0e2014-09-09 13:46:02 +0100505 run_process ir-cond "$IRONIC_BIN_DIR/ironic-conductor --config-file=$IRONIC_CONF_FILE"
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300506 # TODO(romcheg): Find a way to check whether the conductor has started.
507}
508
509# stop_ironic() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100510function stop_ironic {
Chris Dentcf3b41f2015-03-12 13:33:12 +0000511 stop_process ir-api
512 stop_process ir-cond
Lucas Alvares Gomes5851e5f2014-08-19 10:01:45 +0100513
514 # Cleanup the WSGI files
515 if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
516 _cleanup_ironic_apache_wsgi
517 fi
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300518}
519
Adam Gandelman6d271482014-08-05 18:12:29 -0700520function create_ovs_taps {
Ian Wienandada886d2015-10-07 14:06:26 +1100521 local ironic_net_id
522 ironic_net_id=$(neutron net-list | grep private | get_field 1)
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400523
Adam Gandelman6d271482014-08-05 18:12:29 -0700524 # Work around: No netns exists on host until a Neutron port is created. We
525 # need to create one in Neutron to know what netns to tap into prior to the
526 # first node booting.
Ian Wienandada886d2015-10-07 14:06:26 +1100527 local port_id
528 port_id=$(neutron port-create private | grep " id " | get_field 2)
Adam Gandelman6d271482014-08-05 18:12:29 -0700529
530 # intentional sleep to make sure the tag has been set to port
531 sleep 10
532
Cedric Brandilyb814b532015-10-22 22:25:45 +0200533 local tapdev
534 tapdev=$(sudo ip netns exec qdhcp-${ironic_net_id} ip link list | grep " tap" | cut -d':' -f2 | cut -d'@' -f1 | cut -b2-)
Ian Wienandada886d2015-10-07 14:06:26 +1100535 local tag_id
536 tag_id=$(sudo ovs-vsctl show |grep ${tapdev} -A1 -m1 | grep tag | cut -d':' -f2 | cut -b2-)
Adam Gandelman6d271482014-08-05 18:12:29 -0700537
538 # make sure veth pair is not existing, otherwise delete its links
539 sudo ip link show ovs-tap1 && sudo ip link delete ovs-tap1
540 sudo ip link show brbm-tap1 && sudo ip link delete brbm-tap1
541 # create veth pair for future interconnection between br-int and brbm
542 sudo ip link add brbm-tap1 type veth peer name ovs-tap1
543 sudo ip link set dev brbm-tap1 up
544 sudo ip link set dev ovs-tap1 up
545
546 sudo ovs-vsctl -- --if-exists del-port ovs-tap1 -- add-port br-int ovs-tap1 tag=$tag_id
547 sudo ovs-vsctl -- --if-exists del-port brbm-tap1 -- add-port $IRONIC_VM_NETWORK_BRIDGE brbm-tap1
548
549 # Remove the port needed only for workaround.
550 neutron port-delete $port_id
Adam Gandelmancec97922014-07-29 18:43:18 -0700551
552 # Finally, share the fixed tenant network across all tenants. This allows the host
553 # to serve TFTP to a single network namespace via the tap device created above.
554 neutron net-update $ironic_net_id --shared true
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400555}
556
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400557function create_bridge_and_vms {
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400558 # Call libvirt setup scripts in a new shell to ensure any new group membership
559 sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/setup-network"
Adam Gandelman8af6fae2014-04-11 17:06:14 -0700560 if [[ "$IRONIC_VM_LOG_CONSOLE" == "True" ]] ; then
Dean Troyerb52caa32014-07-25 13:04:13 -0500561 local log_arg="$IRONIC_VM_LOG_DIR"
Adam Gandelman8af6fae2014-04-11 17:06:14 -0700562 else
Dean Troyerb52caa32014-07-25 13:04:13 -0500563 local log_arg=""
Adam Gandelman8af6fae2014-04-11 17:06:14 -0700564 fi
Adam Gandelman22ec45e2014-10-16 17:41:22 -0700565 local vm_name
566 for vm_name in $(_ironic_bm_vm_names); do
567 sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/create-node $vm_name \
568 $IRONIC_VM_SPECS_CPU $IRONIC_VM_SPECS_RAM $IRONIC_VM_SPECS_DISK \
569 amd64 $IRONIC_VM_NETWORK_BRIDGE $IRONIC_VM_EMULATOR \
570 $log_arg" >> $IRONIC_VM_MACS_CSV_FILE
571 done
Adam Gandelman6d271482014-08-05 18:12:29 -0700572 create_ovs_taps
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400573}
574
Adam Gandelmanc78e4672014-12-01 11:24:37 -0800575function wait_for_nova_resources {
Adam Gandelman0c99e2f2014-12-09 14:44:24 -0800576 # After nodes have been enrolled, we need to wait for both ironic and
577 # nova's periodic tasks to populate the resource tracker with available
578 # nodes and resources. Wait up to 2 minutes for a given resource before
579 # timing out.
580 local resource=$1
581 local expected_count=$2
Sean Dague95d42262015-10-12 07:34:41 -0400582 local i
Adam Gandelman0c99e2f2014-12-09 14:44:24 -0800583 echo_summary "Waiting 2 minutes for Nova resource tracker to pick up $resource >= $expected_count"
Adam Gandelmanc78e4672014-12-01 11:24:37 -0800584 for i in $(seq 1 120); do
Adam Gandelman0c99e2f2014-12-09 14:44:24 -0800585 if [ $(nova hypervisor-stats | grep " $resource " | get_field 2) -ge $expected_count ]; then
Adam Gandelmanc78e4672014-12-01 11:24:37 -0800586 return 0
587 fi
588 sleep 1
589 done
Adam Gandelman0c99e2f2014-12-09 14:44:24 -0800590 die $LINENO "Timed out waiting for Nova hypervisor-stats $resource >= $expected_count"
Adam Gandelmanc78e4672014-12-01 11:24:37 -0800591}
592
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700593function enroll_nodes {
Ian Wienandada886d2015-10-07 14:06:26 +1100594 local chassis_id
595 chassis_id=$(ironic chassis-create -d "ironic test chassis" | grep " uuid " | get_field 2)
Jim Rollenhagena6a45462014-08-05 18:08:29 +0000596
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700597 if ! is_ironic_hardware; then
598 local ironic_node_cpu=$IRONIC_VM_SPECS_CPU
599 local ironic_node_ram=$IRONIC_VM_SPECS_RAM
600 local ironic_node_disk=$IRONIC_VM_SPECS_DISK
601 local ironic_ephemeral_disk=$IRONIC_VM_EPHEMERAL_DISK
602 local ironic_hwinfo_file=$IRONIC_VM_MACS_CSV_FILE
603 local node_options="\
Lucas Alvares Gomes73d24b22015-05-27 11:41:33 +0100604 -i deploy_kernel=$IRONIC_DEPLOY_KERNEL_ID \
605 -i deploy_ramdisk=$IRONIC_DEPLOY_RAMDISK_ID \
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400606 -i ssh_virt_type=$IRONIC_SSH_VIRT_TYPE \
607 -i ssh_address=$IRONIC_VM_SSH_ADDRESS \
608 -i ssh_port=$IRONIC_VM_SSH_PORT \
609 -i ssh_username=$IRONIC_SSH_USERNAME \
Adam Gandelmand4a6e352014-12-11 14:53:17 -0800610 -i ssh_key_filename=$IRONIC_KEY_FILE"
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700611 else
612 local ironic_node_cpu=$IRONIC_HW_NODE_CPU
613 local ironic_node_ram=$IRONIC_HW_NODE_RAM
614 local ironic_node_disk=$IRONIC_HW_NODE_DISK
615 local ironic_ephemeral_disk=$IRONIC_HW_EPHEMERAL_DISK
616 if [[ -z "${IRONIC_DEPLOY_DRIVER##*_ipmitool}" ]]; then
617 local ironic_hwinfo_file=$IRONIC_IPMIINFO_FILE
618 fi
619 fi
620
Adam Gandelmanc78e4672014-12-01 11:24:37 -0800621 local total_nodes=0
Adam Gandelman0c99e2f2014-12-09 14:44:24 -0800622 local total_cpus=0
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700623 while read hardware_info; do
624 if ! is_ironic_hardware; then
625 local mac_address=$hardware_info
626 elif [[ -z "${IRONIC_DEPLOY_DRIVER##*_ipmitool}" ]]; then
Ian Wienandada886d2015-10-07 14:06:26 +1100627 local ipmi_address
628 ipmi_address=$(echo $hardware_info |awk '{print $1}')
629 local mac_address
630 mac_address=$(echo $hardware_info |awk '{print $2}')
631 local ironic_ipmi_username
632 ironic_ipmi_username=$(echo $hardware_info |awk '{print $3}')
633 local ironic_ipmi_passwd
634 ironic_ipmi_passwd=$(echo $hardware_info |awk '{print $4}')
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700635 # Currently we require all hardware platform have same CPU/RAM/DISK info
636 # in future, this can be enhanced to support different type, and then
637 # we create the bare metal flavor with minimum value
638 local node_options="-i ipmi_address=$ipmi_address -i ipmi_password=$ironic_ipmi_passwd\
639 -i ipmi_username=$ironic_ipmi_username"
Lucas Alvares Gomes73d24b22015-05-27 11:41:33 +0100640 node_options+=" -i deploy_kernel=$IRONIC_DEPLOY_KERNEL_ID"
641 node_options+=" -i deploy_ramdisk=$IRONIC_DEPLOY_RAMDISK_ID"
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700642 fi
643
Vladyslav Drok41309002015-04-29 13:36:52 +0300644 # First node created will be used for testing in ironic w/o glance
645 # scenario, so we need to know its UUID.
Dmitry Tantsur5ed8af62015-10-15 14:30:50 +0200646 local standalone_node_uuid=""
647 if [ $total_nodes -eq 0 ]; then
648 standalone_node_uuid="--uuid $IRONIC_NODE_UUID"
649 fi
Vladyslav Drok41309002015-04-29 13:36:52 +0300650
Ian Wienandada886d2015-10-07 14:06:26 +1100651 local node_id
652 node_id=$(ironic node-create $standalone_node_uuid\
Vladyslav Drok41309002015-04-29 13:36:52 +0300653 --chassis_uuid $chassis_id \
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700654 --driver $IRONIC_DEPLOY_DRIVER \
Lucas Alvares Gomes51bddb82015-08-14 17:21:47 +0100655 --name node-$total_nodes \
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700656 -p cpus=$ironic_node_cpu\
657 -p memory_mb=$ironic_node_ram\
658 -p local_gb=$ironic_node_disk\
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400659 -p cpu_arch=x86_64 \
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700660 $node_options \
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400661 | grep " uuid " | get_field 2)
662
Zhenzan Zhoue2d2d652015-02-28 11:13:27 +0800663 ironic port-create --address $mac_address --node $node_id
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400664
Adam Gandelmanc78e4672014-12-01 11:24:37 -0800665 total_nodes=$((total_nodes+1))
Adam Gandelman0c99e2f2014-12-09 14:44:24 -0800666 total_cpus=$((total_cpus+$ironic_node_cpu))
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700667 done < $ironic_hwinfo_file
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400668
Ian Wienandada886d2015-10-07 14:06:26 +1100669 local adjusted_disk
670 adjusted_disk=$(($ironic_node_disk - $ironic_ephemeral_disk))
vsaienkof0dd6892015-11-18 10:12:34 +0200671 nova flavor-create --ephemeral $ironic_ephemeral_disk baremetal auto $ironic_node_ram $adjusted_disk $ironic_node_cpu
Adam Gandelman29c3d632014-07-17 12:53:21 -0700672
Yuiko Takadab7d5bf62014-11-20 18:23:06 +0900673 nova flavor-key baremetal set "cpu_arch"="x86_64"
Adam Gandelmanc78e4672014-12-01 11:24:37 -0800674
675 if [ "$VIRT_DRIVER" == "ironic" ]; then
Adam Gandelman0c99e2f2014-12-09 14:44:24 -0800676 wait_for_nova_resources "count" $total_nodes
677 wait_for_nova_resources "vcpus" $total_cpus
Adam Gandelmanc78e4672014-12-01 11:24:37 -0800678 fi
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400679}
680
Adam Gandelmanc1f0db22014-04-14 13:21:22 -0700681function configure_iptables {
682 # enable tftp natting for allowing connections to HOST_IP's tftp server
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400683 sudo modprobe nf_conntrack_tftp
684 sudo modprobe nf_nat_tftp
Swapnil Kulkarni (coolsvap)7f0be4f2015-11-20 10:52:59 +0530685 # explicitly allow DHCP - packets are occasionally being dropped here
Jim Rollenhagen63cac532015-11-06 12:37:32 -0800686 sudo iptables -I INPUT -p udp --dport 67:68 --sport 67:68 -j ACCEPT || true
Adam Gandelmanc1f0db22014-04-14 13:21:22 -0700687 # nodes boot from TFTP and callback to the API server listening on $HOST_IP
688 sudo iptables -I INPUT -d $HOST_IP -p udp --dport 69 -j ACCEPT || true
Adam Gandelman4b45fca2014-11-17 09:59:23 -0800689 sudo iptables -I INPUT -d $HOST_IP -p tcp --dport $IRONIC_SERVICE_PORT -j ACCEPT || true
yunhong jiangfe96ed62014-11-05 03:30:25 -0700690 if is_deployed_by_agent; then
Jim Rollenhagen74b28bc2014-10-29 14:15:22 -0700691 # agent ramdisk gets instance image from swift
692 sudo iptables -I INPUT -d $HOST_IP -p tcp --dport ${SWIFT_DEFAULT_BIND_PORT:-8080} -j ACCEPT || true
693 fi
Lucas Alvares Gomes365d11d2015-06-23 11:50:18 +0100694
695 if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
696 sudo iptables -I INPUT -d $HOST_IP -p tcp --dport $IRONIC_HTTP_PORT -j ACCEPT || true
697 fi
Adam Gandelmanc1f0db22014-04-14 13:21:22 -0700698}
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400699
Adam Gandelmanc1f0db22014-04-14 13:21:22 -0700700function configure_tftpd {
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400701 # stop tftpd and setup serving via xinetd
702 stop_service tftpd-hpa || true
703 [ -f /etc/init/tftpd-hpa.conf ] && echo "manual" | sudo tee /etc/init/tftpd-hpa.override
704 sudo cp $IRONIC_TEMPLATES_DIR/tftpd-xinetd.template /etc/xinetd.d/tftp
705 sudo sed -e "s|%TFTPBOOT_DIR%|$IRONIC_TFTPBOOT_DIR|g" -i /etc/xinetd.d/tftp
706
707 # setup tftp file mapping to satisfy requests at the root (booting) and
708 # /tftpboot/ sub-dir (as per deploy-ironic elements)
709 echo "r ^([^/]) $IRONIC_TFTPBOOT_DIR/\1" >$IRONIC_TFTPBOOT_DIR/map-file
710 echo "r ^(/tftpboot/) $IRONIC_TFTPBOOT_DIR/\2" >>$IRONIC_TFTPBOOT_DIR/map-file
711
712 chmod -R 0755 $IRONIC_TFTPBOOT_DIR
713 restart_service xinetd
714}
715
716function configure_ironic_ssh_keypair {
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400717 if [[ ! -d $HOME/.ssh ]]; then
718 mkdir -p $HOME/.ssh
719 chmod 700 $HOME/.ssh
720 fi
Adam Gandelman6c749322014-12-02 16:20:50 -0800721 if [[ ! -e $IRONIC_KEY_FILE ]]; then
722 if [[ ! -d $(dirname $IRONIC_KEY_FILE) ]]; then
723 mkdir -p $(dirname $IRONIC_KEY_FILE)
724 fi
725 echo -e 'n\n' | ssh-keygen -q -t rsa -P '' -f $IRONIC_KEY_FILE
726 fi
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400727 cat $IRONIC_KEY_FILE.pub | tee -a $IRONIC_AUTHORIZED_KEYS_FILE
728}
729
730function ironic_ssh_check {
Dean Troyerb52caa32014-07-25 13:04:13 -0500731 local key_file=$1
732 local floating_ip=$2
733 local port=$3
734 local default_instance_user=$4
735 local active_timeout=$5
736 if ! timeout $active_timeout sh -c "while ! ssh -p $port -o StrictHostKeyChecking=no -i $key_file ${default_instance_user}@$floating_ip echo success; do sleep 1; done"; then
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400737 die $LINENO "server didn't become ssh-able!"
738 fi
739}
740
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400741function configure_ironic_auxiliary {
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400742 configure_ironic_ssh_keypair
Zhenzan Zhou80cdbc42015-03-16 12:30:44 +0800743 ironic_ssh_check $IRONIC_KEY_FILE $IRONIC_VM_SSH_ADDRESS $IRONIC_VM_SSH_PORT $IRONIC_SSH_USERNAME $IRONIC_SSH_TIMEOUT
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400744}
745
Jim Rollenhagenf00766b2014-08-15 01:08:11 +0000746function build_ipa_coreos_ramdisk {
747 echo "Building ironic-python-agent deploy ramdisk"
748 local kernel_path=$1
749 local ramdisk_path=$2
750 git_clone $IRONIC_PYTHON_AGENT_REPO $IRONIC_PYTHON_AGENT_DIR $IRONIC_PYTHON_AGENT_BRANCH
751 cd $IRONIC_PYTHON_AGENT_DIR
752 imagebuild/coreos/build_coreos_image.sh
753 cp imagebuild/coreos/UPLOAD/coreos_production_pxe_image-oem.cpio.gz $ramdisk_path
754 cp imagebuild/coreos/UPLOAD/coreos_production_pxe.vmlinuz $kernel_path
755 sudo rm -rf UPLOAD
756 cd -
757}
758
Alexander Gordeevf177f722014-03-14 18:44:48 +0400759# build deploy kernel+ramdisk, then upload them to glance
Dean Troyerb52caa32014-07-25 13:04:13 -0500760# this function sets ``IRONIC_DEPLOY_KERNEL_ID``, ``IRONIC_DEPLOY_RAMDISK_ID``
Alexander Gordeevf177f722014-03-14 18:44:48 +0400761function upload_baremetal_ironic_deploy {
Dean Troyerb52caa32014-07-25 13:04:13 -0500762 declare -g IRONIC_DEPLOY_KERNEL_ID IRONIC_DEPLOY_RAMDISK_ID
Adam Gandelman6d271482014-08-05 18:12:29 -0700763 echo_summary "Creating and uploading baremetal images for ironic"
764
765 # install diskimage-builder
Steve Bakercbfb3ae2014-05-05 16:06:47 +1200766 if [[ $(type -P ramdisk-image-create) == "" ]]; then
Sean Dague60996b12015-04-08 09:06:49 -0400767 pip_install_gr "diskimage-builder"
Steve Bakercbfb3ae2014-05-05 16:06:47 +1200768 fi
Alexander Gordeevf177f722014-03-14 18:44:48 +0400769
770 if [ -z "$IRONIC_DEPLOY_KERNEL" -o -z "$IRONIC_DEPLOY_RAMDISK" ]; then
yunhong jiangfe96ed62014-11-05 03:30:25 -0700771 local IRONIC_DEPLOY_KERNEL_PATH=$TOP_DIR/files/ir-deploy-$IRONIC_DEPLOY_DRIVER.kernel
772 local IRONIC_DEPLOY_RAMDISK_PATH=$TOP_DIR/files/ir-deploy-$IRONIC_DEPLOY_DRIVER.initramfs
Alexander Gordeevf177f722014-03-14 18:44:48 +0400773 else
Dean Troyerb52caa32014-07-25 13:04:13 -0500774 local IRONIC_DEPLOY_KERNEL_PATH=$IRONIC_DEPLOY_KERNEL
775 local IRONIC_DEPLOY_RAMDISK_PATH=$IRONIC_DEPLOY_RAMDISK
Alexander Gordeevf177f722014-03-14 18:44:48 +0400776 fi
777
778 if [ ! -e "$IRONIC_DEPLOY_RAMDISK_PATH" -o ! -e "$IRONIC_DEPLOY_KERNEL_PATH" ]; then
779 # files don't exist, need to build them
780 if [ "$IRONIC_BUILD_DEPLOY_RAMDISK" = "True" ]; then
781 # we can build them only if we're not offline
782 if [ "$OFFLINE" != "True" ]; then
Lucas Alvares Gomes1d3a6ec2015-02-25 12:38:47 +0000783 if is_deployed_with_ipa_ramdisk; then
Jim Rollenhagenf00766b2014-08-15 01:08:11 +0000784 build_ipa_coreos_ramdisk $IRONIC_DEPLOY_KERNEL_PATH $IRONIC_DEPLOY_RAMDISK_PATH
Jim Rollenhagena6a45462014-08-05 18:08:29 +0000785 else
Steve Bakercbfb3ae2014-05-05 16:06:47 +1200786 ramdisk-image-create $IRONIC_DEPLOY_FLAVOR \
yunhong jiangfe96ed62014-11-05 03:30:25 -0700787 -o $TOP_DIR/files/ir-deploy-$IRONIC_DEPLOY_DRIVER
Jim Rollenhagena6a45462014-08-05 18:08:29 +0000788 fi
Alexander Gordeevf177f722014-03-14 18:44:48 +0400789 else
790 die $LINENO "Deploy kernel+ramdisk files don't exist and cannot be build in OFFLINE mode"
791 fi
792 else
Lucas Alvares Gomes1d3a6ec2015-02-25 12:38:47 +0000793 if is_deployed_with_ipa_ramdisk; then
Jim Rollenhagena6a45462014-08-05 18:08:29 +0000794 # download the agent image tarball
Jim Rollenhagen792dc5f2014-08-27 17:03:00 -0700795 wget "$IRONIC_AGENT_KERNEL_URL" -O $IRONIC_DEPLOY_KERNEL_PATH
796 wget "$IRONIC_AGENT_RAMDISK_URL" -O $IRONIC_DEPLOY_RAMDISK_PATH
Jim Rollenhagena6a45462014-08-05 18:08:29 +0000797 else
798 die $LINENO "Deploy kernel+ramdisk files don't exist and their building was disabled explicitly by IRONIC_BUILD_DEPLOY_RAMDISK"
799 fi
Alexander Gordeevf177f722014-03-14 18:44:48 +0400800 fi
801 fi
802
Ian Wienandada886d2015-10-07 14:06:26 +1100803 local token
804 token=$(openstack token issue -c id -f value)
Adam Gandelman6d271482014-08-05 18:12:29 -0700805 die_if_not_set $LINENO token "Keystone fail to get token"
806
Alexander Gordeevf177f722014-03-14 18:44:48 +0400807 # load them into glance
Steve Martinelli8d3ac2d2014-08-02 23:47:15 -0400808 IRONIC_DEPLOY_KERNEL_ID=$(openstack \
809 --os-token $token \
Thiago Paivaabb40f62015-10-29 11:38:24 -0300810 --os-url $GLANCE_SERVICE_PROTOCOL://$GLANCE_HOSTPORT \
Steve Martinelli8d3ac2d2014-08-02 23:47:15 -0400811 image create \
812 $(basename $IRONIC_DEPLOY_KERNEL_PATH) \
813 --public --disk-format=aki \
Jim Rollenhagen722284f2014-08-15 18:04:02 +0000814 --container-format=aki \
Alexander Gordeevf177f722014-03-14 18:44:48 +0400815 < $IRONIC_DEPLOY_KERNEL_PATH | grep ' id ' | get_field 2)
Steve Martinelli8d3ac2d2014-08-02 23:47:15 -0400816 IRONIC_DEPLOY_RAMDISK_ID=$(openstack \
817 --os-token $token \
Thiago Paivaabb40f62015-10-29 11:38:24 -0300818 --os-url $GLANCE_SERVICE_PROTOCOL://$GLANCE_HOSTPORT \
Steve Martinelli8d3ac2d2014-08-02 23:47:15 -0400819 image create \
820 $(basename $IRONIC_DEPLOY_RAMDISK_PATH) \
821 --public --disk-format=ari \
Jim Rollenhagen722284f2014-08-15 18:04:02 +0000822 --container-format=ari \
Alexander Gordeevf177f722014-03-14 18:44:48 +0400823 < $IRONIC_DEPLOY_RAMDISK_PATH | grep ' id ' | get_field 2)
824}
825
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400826function prepare_baremetal_basic_ops {
Adam Gandelman03546402014-12-05 16:49:12 -0800827 if ! is_ironic_hardware; then
828 configure_ironic_auxiliary
829 fi
Adam Gandelman6d271482014-08-05 18:12:29 -0700830 upload_baremetal_ironic_deploy
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700831 if ! is_ironic_hardware; then
832 create_bridge_and_vms
833 fi
834 enroll_nodes
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400835 configure_tftpd
Adam Gandelmanc1f0db22014-04-14 13:21:22 -0700836 configure_iptables
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400837}
838
839function cleanup_baremetal_basic_ops {
840 rm -f $IRONIC_VM_MACS_CSV_FILE
841 if [ -f $IRONIC_KEY_FILE ]; then
Ian Wienandada886d2015-10-07 14:06:26 +1100842 local key
843 key=$(cat $IRONIC_KEY_FILE.pub)
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400844 # remove public key from authorized_keys
Dean Troyerb52caa32014-07-25 13:04:13 -0500845 grep -v "$key" $IRONIC_AUTHORIZED_KEYS_FILE > temp && mv temp $IRONIC_AUTHORIZED_KEYS_FILE
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400846 chmod 0600 $IRONIC_AUTHORIZED_KEYS_FILE
847 fi
848 sudo rm -rf $IRONIC_DATA_DIR $IRONIC_STATE_PATH
Adam Gandelman22ec45e2014-10-16 17:41:22 -0700849
850 local vm_name
851 for vm_name in $(_ironic_bm_vm_names); do
852 sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/cleanup-node $vm_name $IRONIC_VM_NETWORK_BRIDGE"
853 done
854
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400855 sudo rm -rf /etc/xinetd.d/tftp /etc/init/tftpd-hpa.override
856 restart_service xinetd
Adam Gandelmanc1f0db22014-04-14 13:21:22 -0700857 sudo iptables -D INPUT -d $HOST_IP -p udp --dport 69 -j ACCEPT || true
Adam Gandelman4b45fca2014-11-17 09:59:23 -0800858 sudo iptables -D INPUT -d $HOST_IP -p tcp --dport $IRONIC_SERVICE_PORT -j ACCEPT || true
yunhong jiangfe96ed62014-11-05 03:30:25 -0700859 if is_deployed_by_agent; then
Jim Rollenhagen74b28bc2014-10-29 14:15:22 -0700860 # agent ramdisk gets instance image from swift
861 sudo iptables -D INPUT -d $HOST_IP -p tcp --dport ${SWIFT_DEFAULT_BIND_PORT:-8080} -j ACCEPT || true
862 fi
Adam Gandelmanc1f0db22014-04-14 13:21:22 -0700863 sudo rmmod nf_conntrack_tftp || true
864 sudo rmmod nf_nat_tftp || true
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400865}
866
867# Restore xtrace + pipefail
Ian Wienand523f4882015-10-13 11:03:03 +1100868$_XTRACE_IRONIC
869$_PIPEFAIL_IRONIC
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300870
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100871# Tell emacs to use shell-script-mode
872## Local variables:
873## mode: shell-script
874## End: