Browse code

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

Lucas Alvares Gomes authored on 2014/08/19 18:01:45
Showing 4 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,12 @@
0
+Listen %PUBLICPORT%
1
+
2
+<VirtualHost *:%PUBLICPORT%>
3
+    DocumentRoot "%HTTPROOT%"
4
+    <Directory "%HTTPROOT%">
5
+        Options Indexes FollowSymLinks
6
+        AllowOverride None
7
+        Order allow,deny
8
+        Allow from all
9
+        Require all granted
10
+    </Directory>
11
+</VirtualHost>
... ...
@@ -1,5 +1,6 @@
1 1
 ipmitool
2 2
 iptables
3
+ipxe
3 4
 libguestfs0
4 5
 libvirt-bin
5 6
 openssh-client
... ...
@@ -1,5 +1,6 @@
1 1
 ipmitool
2 2
 iptables
3
+ipxe-bootimgs
3 4
 libguestfs
4 5
 libvirt
5 6
 libvirt-python
... ...
@@ -95,6 +95,32 @@ IRONIC_HOSTPORT=${IRONIC_HOSTPORT:-$SERVICE_HOST:6385}
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,6 +142,10 @@ function install_ironic {
116 116
     done
117 117
     git_clone $IRONIC_REPO $IRONIC_DIR $IRONIC_BRANCH
118 118
     setup_develop $IRONIC_DIR
119
+
120
+    if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
121
+        install_apache_wsgi
122
+    fi
119 123
 }
120 124
 
121 125
 # install_ironicclient() - Collect sources and prepare
... ...
@@ -125,6 +155,25 @@ function install_ironicclient {
125 125
     sudo install -D -m 0644 -o $STACK_USER {$IRONICCLIENT_DIR/tools/,/etc/bash_completion.d/}ironic.bash_completion
126 126
 }
127 127
 
128
+# _cleanup_ironic_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
129
+function _cleanup_ironic_apache_wsgi {
130
+    sudo rm -rf $IRONIC_HTTP_DIR
131
+    disable_apache_site ironic
132
+    sudo rm -f $(apache_site_config_for ironic)
133
+    restart_apache_server
134
+}
135
+
136
+# _config_ironic_apache_wsgi() - Set WSGI config files of Ironic
137
+function _config_ironic_apache_wsgi {
138
+    local ironic_apache_conf=$(apache_site_config_for ironic)
139
+    sudo cp $FILES/apache-ironic.template $ironic_apache_conf
140
+    sudo sed -e "
141
+        s|%PUBLICPORT%|$IRONIC_HTTP_PORT|g;
142
+        s|%HTTPROOT%|$IRONIC_HTTP_DIR|g;
143
+    " -i $ironic_apache_conf
144
+    enable_apache_site ironic
145
+}
146
+
128 147
 # cleanup_ironic() - Remove residual data files, anything left over from previous
129 148
 # runs that would need to clean up.
130 149
 function cleanup_ironic {
... ...
@@ -137,22 +186,24 @@ function configure_ironic_dirs {
137 137
     if [[ ! -d $IRONIC_CONF_DIR ]]; then
138 138
         sudo mkdir -p $IRONIC_CONF_DIR
139 139
     fi
140
+
141
+    if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
142
+        sudo mkdir -p $IRONIC_HTTP_DIR
143
+        sudo chown -R $STACK_USER:$LIBVIRT_GROUP $IRONIC_HTTP_DIR
144
+    fi
145
+
140 146
     sudo mkdir -p $IRONIC_DATA_DIR
141 147
     sudo mkdir -p $IRONIC_STATE_PATH
142 148
     sudo mkdir -p $IRONIC_TFTPBOOT_DIR
143 149
     sudo chown -R $STACK_USER $IRONIC_DATA_DIR $IRONIC_STATE_PATH
144 150
     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."
151
+    mkdir -p $IRONIC_TFTPBOOT_DIR/pxelinux.cfg
152
+
153
+    if [ ! -f $IRONIC_PXE_BOOT_IMAGE ]; then
154
+        die $LINENO "PXE boot file $IRONIC_PXE_BOOT_IMAGE not found."
152 155
     fi
153 156
 
154
-    cp $pxebin $IRONIC_TFTPBOOT_DIR
155
-    mkdir -p $IRONIC_TFTPBOOT_DIR/pxelinux.cfg
157
+    cp $IRONIC_PXE_BOOT_IMAGE $IRONIC_TFTPBOOT_DIR
156 158
 }
157 159
 
158 160
 # configure_ironic() - Set config files, create data dirs, etc
... ...
@@ -181,6 +232,10 @@ function configure_ironic {
181 181
     if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
182 182
         setup_colorized_logging $IRONIC_CONF_FILE DEFAULT
183 183
     fi
184
+
185
+    if [[ "$IRONIC_IPXE_ENABLED" == "True" ]]; then
186
+        _config_ironic_apache_wsgi
187
+    fi
184 188
 }
185 189
 
186 190
 # configure_ironic_api() - Is used by configure_ironic(). Performs
... ...
@@ -240,6 +295,15 @@ function configure_ironic_conductor {
240 240
             iniset $IRONIC_CONF_FILE agent agent_pxe_append_params "nofb nomodeset vga=normal console=ttyS0"
241 241
         fi
242 242
     fi
243
+
244
+    if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
245
+        local pxebin=`basename $IRONIC_PXE_BOOT_IMAGE`
246
+        iniset $IRONIC_CONF_FILE pxe ipxe_enabled True
247
+        iniset $IRONIC_CONF_FILE pxe pxe_config_template '\$pybasedir/drivers/modules/ipxe_config.template'
248
+        iniset $IRONIC_CONF_FILE pxe pxe_bootfile_name $pxebin
249
+        iniset $IRONIC_CONF_FILE pxe http_root $IRONIC_HTTP_DIR
250
+        iniset $IRONIC_CONF_FILE pxe http_url "http://$IRONIC_HTTP_SERVER:$IRONIC_HTTP_PORT"
251
+    fi
243 252
 }
244 253
 
245 254
 # create_ironic_cache_dir() - Part of the init_ironic() process
... ...
@@ -307,6 +371,11 @@ function start_ironic {
307 307
     if is_service_enabled ir-cond; then
308 308
         start_ironic_conductor
309 309
     fi
310
+
311
+    # Start Apache if iPXE is enabled
312
+    if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
313
+        restart_apache_server
314
+    fi
310 315
 }
311 316
 
312 317
 # start_ironic_api() - Used by start_ironic().
... ...
@@ -331,6 +400,11 @@ function stop_ironic {
331 331
     # Kill the Ironic screen windows
332 332
     screen -S $SCREEN_NAME -p ir-api -X kill
333 333
     screen -S $SCREEN_NAME -p ir-cond -X kill
334
+
335
+    # Cleanup the WSGI files
336
+    if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
337
+        _cleanup_ironic_apache_wsgi
338
+    fi
334 339
 }
335 340
 
336 341
 function is_ironic {
... ...
@@ -438,15 +512,6 @@ function configure_iptables {
438 438
 }
439 439
 
440 440
 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 441
     # stop tftpd and setup serving via xinetd
451 442
     stop_service tftpd-hpa || true
452 443
     [ -f /etc/init/tftpd-hpa.conf ] && echo "manual" | sudo tee /etc/init/tftpd-hpa.override