~devstack-core/devstack/github

« back to all changes in this revision

Viewing changes to lib/ironic

  • Committer: Lucas Alvares Gomes
  • Date: 2014-08-20 16:32:32 UTC
  • mto: This revision was merged to the branch mainline in revision 2431.
  • Revision ID: git-v1:5851e5f6984afe1f3a71d3a0420b442c55770f3e
Ironic: Setup/Configure iPXE

Setup the enviroment and configure Ironic to use iPXE for deployments. If
IRONIC_IPXE_ENABLED enviroment variable is True, DevStack will now start
and configure an Apache HTTP server to serve the images, will copy the
undionly.kpxe boot file in place of the standard pxelinux.0 and will set
the right configuration to Ironic to deploy the images using iPXE+HTTP.

Implements: blueprint ipxe-boot
Change-Id: I0ea40cb8bbf9236c634f803c2bde1081634679ff

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
# Tell Tempest this project is present
96
96
TEMPEST_SERVICES+=,ironic
97
97
 
 
98
# Enable iPXE
 
99
IRONIC_IPXE_ENABLED=$(trueorfalse False $IRONIC_IPXE_ENABLED)
 
100
IRONIC_HTTP_DIR=${IRONIC_HTTP_DIR:-$IRONIC_DATA_DIR/httpboot}
 
101
IRONIC_HTTP_SERVER=${IRONIC_HTTP_SERVER:-$HOST_IP}
 
102
IRONIC_HTTP_PORT=${IRONIC_HTTP_PORT:-8088}
 
103
 
 
104
# get_pxe_boot_file() - Get the PXE/iPXE boot file path
 
105
function get_pxe_boot_file {
 
106
    local relpath=syslinux/pxelinux.0
 
107
    if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
 
108
        relpath=ipxe/undionly.kpxe
 
109
    fi
 
110
 
 
111
    local pxe_boot_file
 
112
    if is_ubuntu; then
 
113
        pxe_boot_file=/usr/lib/$relpath
 
114
    elif is_fedora || is_suse; then
 
115
        pxe_boot_file=/usr/share/$relpath
 
116
    fi
 
117
 
 
118
    echo $pxe_boot_file
 
119
}
 
120
 
 
121
# PXE boot image
 
122
IRONIC_PXE_BOOT_IMAGE=${IRONIC_PXE_BOOT_IMAGE:-$(get_pxe_boot_file)}
 
123
 
98
124
 
99
125
# Functions
100
126
# ---------
116
142
    done
117
143
    git_clone $IRONIC_REPO $IRONIC_DIR $IRONIC_BRANCH
118
144
    setup_develop $IRONIC_DIR
 
145
 
 
146
    if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
 
147
        install_apache_wsgi
 
148
    fi
119
149
}
120
150
 
121
151
# install_ironicclient() - Collect sources and prepare
125
155
    sudo install -D -m 0644 -o $STACK_USER {$IRONICCLIENT_DIR/tools/,/etc/bash_completion.d/}ironic.bash_completion
126
156
}
127
157
 
 
158
# _cleanup_ironic_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
 
159
function _cleanup_ironic_apache_wsgi {
 
160
    sudo rm -rf $IRONIC_HTTP_DIR
 
161
    disable_apache_site ironic
 
162
    sudo rm -f $(apache_site_config_for ironic)
 
163
    restart_apache_server
 
164
}
 
165
 
 
166
# _config_ironic_apache_wsgi() - Set WSGI config files of Ironic
 
167
function _config_ironic_apache_wsgi {
 
168
    local ironic_apache_conf=$(apache_site_config_for ironic)
 
169
    sudo cp $FILES/apache-ironic.template $ironic_apache_conf
 
170
    sudo sed -e "
 
171
        s|%PUBLICPORT%|$IRONIC_HTTP_PORT|g;
 
172
        s|%HTTPROOT%|$IRONIC_HTTP_DIR|g;
 
173
    " -i $ironic_apache_conf
 
174
    enable_apache_site ironic
 
175
}
 
176
 
128
177
# cleanup_ironic() - Remove residual data files, anything left over from previous
129
178
# runs that would need to clean up.
130
179
function cleanup_ironic {
137
186
    if [[ ! -d $IRONIC_CONF_DIR ]]; then
138
187
        sudo mkdir -p $IRONIC_CONF_DIR
139
188
    fi
 
189
 
 
190
    if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
 
191
        sudo mkdir -p $IRONIC_HTTP_DIR
 
192
        sudo chown -R $STACK_USER:$LIBVIRT_GROUP $IRONIC_HTTP_DIR
 
193
    fi
 
194
 
140
195
    sudo mkdir -p $IRONIC_DATA_DIR
141
196
    sudo mkdir -p $IRONIC_STATE_PATH
142
197
    sudo mkdir -p $IRONIC_TFTPBOOT_DIR
143
198
    sudo chown -R $STACK_USER $IRONIC_DATA_DIR $IRONIC_STATE_PATH
144
199
    sudo chown -R $STACK_USER:$LIBVIRT_GROUP $IRONIC_TFTPBOOT_DIR
145
 
    if is_ubuntu; then
146
 
        local pxebin=/usr/lib/syslinux/pxelinux.0
147
 
    elif is_fedora; then
148
 
        local pxebin=/usr/share/syslinux/pxelinux.0
149
 
    fi
150
 
    if [ ! -f $pxebin ]; then
151
 
        die $LINENO "pxelinux.0 (from SYSLINUX) not found."
152
 
    fi
153
 
 
154
 
    cp $pxebin $IRONIC_TFTPBOOT_DIR
155
200
    mkdir -p $IRONIC_TFTPBOOT_DIR/pxelinux.cfg
 
201
 
 
202
    if [ ! -f $IRONIC_PXE_BOOT_IMAGE ]; then
 
203
        die $LINENO "PXE boot file $IRONIC_PXE_BOOT_IMAGE not found."
 
204
    fi
 
205
 
 
206
    cp $IRONIC_PXE_BOOT_IMAGE $IRONIC_TFTPBOOT_DIR
156
207
}
157
208
 
158
209
# configure_ironic() - Set config files, create data dirs, etc
181
232
    if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
182
233
        setup_colorized_logging $IRONIC_CONF_FILE DEFAULT
183
234
    fi
 
235
 
 
236
    if [[ "$IRONIC_IPXE_ENABLED" == "True" ]]; then
 
237
        _config_ironic_apache_wsgi
 
238
    fi
184
239
}
185
240
 
186
241
# configure_ironic_api() - Is used by configure_ironic(). Performs
240
295
            iniset $IRONIC_CONF_FILE agent agent_pxe_append_params "nofb nomodeset vga=normal console=ttyS0"
241
296
        fi
242
297
    fi
 
298
 
 
299
    if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
 
300
        local pxebin=`basename $IRONIC_PXE_BOOT_IMAGE`
 
301
        iniset $IRONIC_CONF_FILE pxe ipxe_enabled True
 
302
        iniset $IRONIC_CONF_FILE pxe pxe_config_template '\$pybasedir/drivers/modules/ipxe_config.template'
 
303
        iniset $IRONIC_CONF_FILE pxe pxe_bootfile_name $pxebin
 
304
        iniset $IRONIC_CONF_FILE pxe http_root $IRONIC_HTTP_DIR
 
305
        iniset $IRONIC_CONF_FILE pxe http_url "http://$IRONIC_HTTP_SERVER:$IRONIC_HTTP_PORT"
 
306
    fi
243
307
}
244
308
 
245
309
# create_ironic_cache_dir() - Part of the init_ironic() process
307
371
    if is_service_enabled ir-cond; then
308
372
        start_ironic_conductor
309
373
    fi
 
374
 
 
375
    # Start Apache if iPXE is enabled
 
376
    if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
 
377
        restart_apache_server
 
378
    fi
310
379
}
311
380
 
312
381
# start_ironic_api() - Used by start_ironic().
331
400
    # Kill the Ironic screen windows
332
401
    screen -S $SCREEN_NAME -p ir-api -X kill
333
402
    screen -S $SCREEN_NAME -p ir-cond -X kill
 
403
 
 
404
    # Cleanup the WSGI files
 
405
    if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
 
406
        _cleanup_ironic_apache_wsgi
 
407
    fi
334
408
}
335
409
 
336
410
function is_ironic {
438
512
}
439
513
 
440
514
function configure_tftpd {
441
 
    if is_ubuntu; then
442
 
        local pxebin=/usr/lib/syslinux/pxelinux.0
443
 
    elif is_fedora; then
444
 
        local pxebin=/usr/share/syslinux/pxelinux.0
445
 
    fi
446
 
    if [ ! -f $pxebin ]; then
447
 
        die $LINENO "pxelinux.0 (from SYSLINUX) not found."
448
 
    fi
449
 
 
450
515
    # stop tftpd and setup serving via xinetd
451
516
    stop_service tftpd-hpa || true
452
517
    [ -f /etc/init/tftpd-hpa.conf ] && echo "manual" | sudo tee /etc/init/tftpd-hpa.override