| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 1 | # lib/ironic | 
|  | 2 | # Functions to control the configuration and operation of the **Ironic** service | 
|  | 3 |  | 
|  | 4 | # Dependencies: | 
| Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 5 | # | 
|  | 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 Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 11 |  | 
|  | 12 | # ``stack.sh`` calls the entry points in this order: | 
|  | 13 | # | 
| Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 14 | # - install_ironic | 
|  | 15 | # - install_ironicclient | 
|  | 16 | # - init_ironic | 
|  | 17 | # - start_ironic | 
|  | 18 | # - stop_ironic | 
|  | 19 | # - cleanup_ironic | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 20 |  | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 21 | # Save trace and pipefail settings | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 22 | XTRACE=$(set +o | grep xtrace) | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 23 | PIPEFAIL=$(set +o | grep pipefail) | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 24 | set +o xtrace | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 25 | set +o pipefail | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 26 |  | 
|  | 27 | # Defaults | 
|  | 28 | # -------- | 
|  | 29 |  | 
|  | 30 | # Set up default directories | 
|  | 31 | IRONIC_DIR=$DEST/ironic | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 32 | IRONIC_DATA_DIR=$DATA_DIR/ironic | 
|  | 33 | IRONIC_STATE_PATH=/var/lib/ironic | 
| Roman Prykhodchenko | 43e0066 | 2013-10-15 17:03:15 +0300 | [diff] [blame] | 34 | IRONICCLIENT_DIR=$DEST/python-ironicclient | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 35 | IRONIC_AUTH_CACHE_DIR=${IRONIC_AUTH_CACHE_DIR:-/var/cache/ironic} | 
|  | 36 | IRONIC_CONF_DIR=${IRONIC_CONF_DIR:-/etc/ironic} | 
|  | 37 | IRONIC_CONF_FILE=$IRONIC_CONF_DIR/ironic.conf | 
|  | 38 | IRONIC_ROOTWRAP_CONF=$IRONIC_CONF_DIR/rootwrap.conf | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 39 | IRONIC_POLICY_JSON=$IRONIC_CONF_DIR/policy.json | 
|  | 40 |  | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 41 | # Set up defaults for functional / integration testing | 
|  | 42 | IRONIC_SCRIPTS_DIR=${IRONIC_SCRIPTS_DIR:-$TOP_DIR/tools/ironic/scripts} | 
|  | 43 | IRONIC_TEMPLATES_DIR=${IRONIC_TEMPLATES_DIR:-$TOP_DIR/tools/ironic/templates} | 
|  | 44 | IRONIC_BAREMETAL_BASIC_OPS=$(trueorfalse False $IRONIC_BAREMETAL_BASIC_OPS) | 
| Devananda van der Veen | 83eeed0 | 2014-04-11 10:08:41 -0700 | [diff] [blame] | 45 | IRONIC_ENABLED_DRIVERS=${IRONIC_ENABLED_DRIVERS:-fake,pxe_ssh,pxe_ipmitool} | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 46 | IRONIC_SSH_USERNAME=${IRONIC_SSH_USERNAME:-`whoami`} | 
|  | 47 | IRONIC_SSH_KEY_DIR=${IRONIC_SSH_KEY_DIR:-$IRONIC_DATA_DIR/ssh_keys} | 
|  | 48 | IRONIC_SSH_KEY_FILENAME=${IRONIC_SSH_KEY_FILENAME:-ironic_key} | 
|  | 49 | IRONIC_KEY_FILE=$IRONIC_SSH_KEY_DIR/$IRONIC_SSH_KEY_FILENAME | 
|  | 50 | IRONIC_SSH_VIRT_TYPE=${IRONIC_SSH_VIRT_TYPE:-virsh} | 
|  | 51 | IRONIC_TFTPBOOT_DIR=${IRONIC_TFTPBOOT_DIR:-$IRONIC_DATA_DIR/tftpboot} | 
| Adam Gandelman | 8676510 | 2014-04-14 11:57:13 -0700 | [diff] [blame] | 52 | IRONIC_VM_SSH_PORT=${IRONIC_VM_SSH_PORT:-22} | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 53 | IRONIC_VM_SSH_ADDRESS=${IRONIC_VM_SSH_ADDRESS:-$HOST_IP} | 
|  | 54 | IRONIC_VM_COUNT=${IRONIC_VM_COUNT:-1} | 
|  | 55 | IRONIC_VM_SPECS_CPU=${IRONIC_VM_SPECS_CPU:-1} | 
| Adam Gandelman | ea335f4 | 2014-07-03 17:57:49 -0700 | [diff] [blame] | 56 | IRONIC_VM_SPECS_RAM=${IRONIC_VM_SPECS_RAM:-512} | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 57 | IRONIC_VM_SPECS_DISK=${IRONIC_VM_SPECS_DISK:-10} | 
| David Shrewsbury | 3e4612b | 2014-05-01 11:38:21 -0400 | [diff] [blame] | 58 | IRONIC_VM_EPHEMERAL_DISK=${IRONIC_VM_EPHEMERAL_DISK:-0} | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 59 | IRONIC_VM_EMULATOR=${IRONIC_VM_EMULATOR:-/usr/bin/qemu-system-x86_64} | 
|  | 60 | IRONIC_VM_NETWORK_BRIDGE=${IRONIC_VM_NETWORK_BRIDGE:-brbm} | 
|  | 61 | IRONIC_VM_NETWORK_RANGE=${IRONIC_VM_NETWORK_RANGE:-192.0.2.0/24} | 
|  | 62 | IRONIC_VM_MACS_CSV_FILE=${IRONIC_VM_MACS_CSV_FILE:-$IRONIC_DATA_DIR/ironic_macs.csv} | 
|  | 63 | IRONIC_AUTHORIZED_KEYS_FILE=${IRONIC_AUTHORIZED_KEYS_FILE:-$HOME/.ssh/authorized_keys} | 
|  | 64 |  | 
| Adam Gandelman | 8af6fae | 2014-04-11 17:06:14 -0700 | [diff] [blame] | 65 | # By default, baremetal VMs will console output to file. | 
|  | 66 | IRONIC_VM_LOG_CONSOLE=${IRONIC_VM_LOG_CONSOLE:-True} | 
|  | 67 | IRONIC_VM_LOG_DIR=${IRONIC_VM_LOG_DIR:-$IRONIC_DATA_DIR/logs/} | 
|  | 68 |  | 
| Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 69 | DIB_DIR=${DIB_DIR:-$DEST/diskimage-builder} | 
|  | 70 |  | 
|  | 71 | # Use DIB to create deploy ramdisk and kernel. | 
|  | 72 | IRONIC_BUILD_DEPLOY_RAMDISK=`trueorfalse True $IRONIC_BUILD_DEPLOY_RAMDISK` | 
|  | 73 | # If not use DIB, these files are used as deploy ramdisk/kernel. | 
|  | 74 | # (The value must be a absolute path) | 
|  | 75 | IRONIC_DEPLOY_RAMDISK=${IRONIC_DEPLOY_RAMDISK:-} | 
|  | 76 | IRONIC_DEPLOY_KERNEL=${IRONIC_DEPLOY_KERNEL:-} | 
|  | 77 | IRONIC_DEPLOY_ELEMENT=${IRONIC_DEPLOY_ELEMENT:-deploy-ironic} | 
|  | 78 |  | 
| Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 79 | IRONIC_AGENT_TARBALL=${IRONIC_AGENT_TARBALL:-http://tarballs.openstack.org/ironic-python-agent/coreos/ipa-coreos.tar.gz} | 
|  | 80 |  | 
|  | 81 | # Which deploy driver to use - valid choices right now | 
|  | 82 | # are 'pxe_ssh' and 'agent_ssh'. | 
|  | 83 | IRONIC_DEPLOY_DRIVER=${IRONIC_DEPLOY_DRIVER:-pxe_ssh} | 
|  | 84 |  | 
| Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 85 | #TODO(agordeev): replace 'ubuntu' with host distro name getting | 
|  | 86 | IRONIC_DEPLOY_FLAVOR=${IRONIC_DEPLOY_FLAVOR:-ubuntu $IRONIC_DEPLOY_ELEMENT} | 
|  | 87 |  | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 88 | # Support entry points installation of console scripts | 
|  | 89 | IRONIC_BIN_DIR=$(get_python_exec_prefix) | 
|  | 90 |  | 
|  | 91 | # Ironic connection info.  Note the port must be specified. | 
|  | 92 | IRONIC_SERVICE_PROTOCOL=http | 
|  | 93 | IRONIC_HOSTPORT=${IRONIC_HOSTPORT:-$SERVICE_HOST:6385} | 
|  | 94 |  | 
| Dean Troyer | 4237f59 | 2014-01-29 16:22:11 -0600 | [diff] [blame] | 95 | # Tell Tempest this project is present | 
|  | 96 | TEMPEST_SERVICES+=,ironic | 
|  | 97 |  | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 98 |  | 
|  | 99 | # Functions | 
|  | 100 | # --------- | 
|  | 101 |  | 
| Dean Troyer | 1023ff7 | 2014-01-27 14:56:44 -0600 | [diff] [blame] | 102 | # Test if any Ironic services are enabled | 
|  | 103 | # is_ironic_enabled | 
|  | 104 | function is_ironic_enabled { | 
|  | 105 | [[ ,${ENABLED_SERVICES} =~ ,"ir-" ]] && return 0 | 
|  | 106 | return 1 | 
|  | 107 | } | 
|  | 108 |  | 
| Roman Prykhodchenko | 43e0066 | 2013-10-15 17:03:15 +0300 | [diff] [blame] | 109 | # install_ironic() - Collect source and prepare | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 110 | function install_ironic { | 
| Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 111 | # make sure all needed service were enabled | 
|  | 112 | for srv in nova glance key; do | 
|  | 113 | if ! is_service_enabled "$srv"; then | 
|  | 114 | die $LINENO "$srv should be enabled for Ironic." | 
|  | 115 | fi | 
|  | 116 | done | 
| Roman Prykhodchenko | 43e0066 | 2013-10-15 17:03:15 +0300 | [diff] [blame] | 117 | git_clone $IRONIC_REPO $IRONIC_DIR $IRONIC_BRANCH | 
|  | 118 | setup_develop $IRONIC_DIR | 
|  | 119 | } | 
|  | 120 |  | 
|  | 121 | # install_ironicclient() - Collect sources and prepare | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 122 | function install_ironicclient { | 
| Roman Prykhodchenko | 43e0066 | 2013-10-15 17:03:15 +0300 | [diff] [blame] | 123 | git_clone $IRONICCLIENT_REPO $IRONICCLIENT_DIR $IRONICCLIENT_BRANCH | 
|  | 124 | setup_develop $IRONICCLIENT_DIR | 
| Ramakrishnan G | c294c50 | 2014-07-24 16:00:47 +0530 | [diff] [blame] | 125 | sudo install -D -m 0644 -o $STACK_USER {$IRONICCLIENT_DIR/tools/,/etc/bash_completion.d/}ironic.bash_completion | 
| Roman Prykhodchenko | 43e0066 | 2013-10-15 17:03:15 +0300 | [diff] [blame] | 126 | } | 
|  | 127 |  | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 128 | # cleanup_ironic() - Remove residual data files, anything left over from previous | 
|  | 129 | # runs that would need to clean up. | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 130 | function cleanup_ironic { | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 131 | sudo rm -rf $IRONIC_AUTH_CACHE_DIR | 
|  | 132 | } | 
|  | 133 |  | 
| Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 134 | # configure_ironic_dirs() - Create all directories required by Ironic and | 
|  | 135 | # associated services. | 
|  | 136 | function configure_ironic_dirs { | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 137 | if [[ ! -d $IRONIC_CONF_DIR ]]; then | 
|  | 138 | sudo mkdir -p $IRONIC_CONF_DIR | 
|  | 139 | fi | 
| Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 140 | sudo mkdir -p $IRONIC_DATA_DIR | 
|  | 141 | sudo mkdir -p $IRONIC_STATE_PATH | 
|  | 142 | sudo mkdir -p $IRONIC_TFTPBOOT_DIR | 
|  | 143 | sudo chown -R $STACK_USER $IRONIC_DATA_DIR $IRONIC_STATE_PATH | 
|  | 144 | 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 | mkdir -p $IRONIC_TFTPBOOT_DIR/pxelinux.cfg | 
|  | 156 | } | 
|  | 157 |  | 
|  | 158 | # configure_ironic() - Set config files, create data dirs, etc | 
|  | 159 | function configure_ironic { | 
|  | 160 | configure_ironic_dirs | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 161 | sudo chown $STACK_USER $IRONIC_CONF_DIR | 
|  | 162 |  | 
|  | 163 | # Copy over ironic configuration file and configure common parameters. | 
|  | 164 | cp $IRONIC_DIR/etc/ironic/ironic.conf.sample $IRONIC_CONF_FILE | 
|  | 165 | iniset $IRONIC_CONF_FILE DEFAULT debug True | 
|  | 166 | inicomment $IRONIC_CONF_FILE DEFAULT log_file | 
|  | 167 | iniset $IRONIC_CONF_FILE DEFAULT sql_connection `database_connection_url ironic` | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 168 | iniset $IRONIC_CONF_FILE DEFAULT state_path $IRONIC_STATE_PATH | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 169 | iniset $IRONIC_CONF_FILE DEFAULT use_syslog $SYSLOG | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 170 | # Configure Ironic conductor, if it was enabled. | 
|  | 171 | if is_service_enabled ir-cond; then | 
|  | 172 | configure_ironic_conductor | 
|  | 173 | fi | 
|  | 174 |  | 
|  | 175 | # Configure Ironic API, if it was enabled. | 
|  | 176 | if is_service_enabled ir-api; then | 
|  | 177 | configure_ironic_api | 
|  | 178 | fi | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 179 |  | 
| Adam Gandelman | ab59293 | 2014-06-06 15:12:32 -0700 | [diff] [blame] | 180 | # Format logging | 
|  | 181 | if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then | 
|  | 182 | setup_colorized_logging $IRONIC_CONF_FILE DEFAULT | 
|  | 183 | fi | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 184 | } | 
|  | 185 |  | 
|  | 186 | # configure_ironic_api() - Is used by configure_ironic(). Performs | 
|  | 187 | # API specific configuration. | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 188 | function configure_ironic_api { | 
| Roman Prykhodchenko | c48c312 | 2013-10-01 17:19:05 +0300 | [diff] [blame] | 189 | iniset $IRONIC_CONF_FILE DEFAULT auth_strategy keystone | 
|  | 190 | iniset $IRONIC_CONF_FILE DEFAULT policy_file $IRONIC_POLICY_JSON | 
| Jamie Lennox | 3561d7f | 2014-05-21 17:18:43 +1000 | [diff] [blame] | 191 | iniset $IRONIC_CONF_FILE keystone_authtoken identity_uri $KEYSTONE_AUTH_URI | 
| Jamie Lennox | bd24a8d | 2013-09-20 16:26:42 +1000 | [diff] [blame] | 192 | iniset $IRONIC_CONF_FILE keystone_authtoken cafile $KEYSTONE_SSL_CA | 
| Jamie Lennox | 3561d7f | 2014-05-21 17:18:43 +1000 | [diff] [blame] | 193 | iniset $IRONIC_CONF_FILE keystone_authtoken auth_uri $KEYSTONE_SERVICE_URI | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 194 | iniset $IRONIC_CONF_FILE keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME | 
|  | 195 | iniset $IRONIC_CONF_FILE keystone_authtoken admin_user ironic | 
|  | 196 | iniset $IRONIC_CONF_FILE keystone_authtoken admin_password $SERVICE_PASSWORD | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 197 | iniset_rpc_backend ironic $IRONIC_CONF_FILE DEFAULT | 
|  | 198 | iniset $IRONIC_CONF_FILE keystone_authtoken signing_dir $IRONIC_AUTH_CACHE_DIR/api | 
|  | 199 |  | 
|  | 200 | cp -p $IRONIC_DIR/etc/ironic/policy.json $IRONIC_POLICY_JSON | 
|  | 201 | } | 
|  | 202 |  | 
|  | 203 | # configure_ironic_conductor() - Is used by configure_ironic(). | 
|  | 204 | # Sets conductor specific settings. | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 205 | function configure_ironic_conductor { | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 206 | cp $IRONIC_DIR/etc/ironic/rootwrap.conf $IRONIC_ROOTWRAP_CONF | 
| Lucas Alvares Gomes | 279295c | 2014-01-14 11:37:51 +0000 | [diff] [blame] | 207 | cp -r $IRONIC_DIR/etc/ironic/rootwrap.d $IRONIC_CONF_DIR | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 208 | local ironic_rootwrap=$(get_rootwrap_location ironic) | 
|  | 209 | local rootwrap_isudoer_cmd="$ironic_rootwrap $IRONIC_CONF_DIR/rootwrap.conf *" | 
| Adam Gandelman | 3f2a7b7 | 2014-04-14 16:14:33 -0700 | [diff] [blame] | 210 |  | 
|  | 211 | # Set up the rootwrap sudoers for ironic | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 212 | local tempfile=`mktemp` | 
|  | 213 | echo "$STACK_USER ALL=(root) NOPASSWD: $rootwrap_isudoer_cmd" >$tempfile | 
|  | 214 | chmod 0440 $tempfile | 
|  | 215 | sudo chown root:root $tempfile | 
|  | 216 | sudo mv $tempfile /etc/sudoers.d/ironic-rootwrap | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 217 |  | 
| Alexander Gordeev | a67cb1a | 2014-03-04 18:38:33 +0400 | [diff] [blame] | 218 | iniset $IRONIC_CONF_FILE DEFAULT rootwrap_config $IRONIC_ROOTWRAP_CONF | 
| Devananda van der Veen | 83eeed0 | 2014-04-11 10:08:41 -0700 | [diff] [blame] | 219 | iniset $IRONIC_CONF_FILE DEFAULT enabled_drivers $IRONIC_ENABLED_DRIVERS | 
| Adam Gandelman | d301198 | 2014-03-24 13:55:34 -0700 | [diff] [blame] | 220 | iniset $IRONIC_CONF_FILE conductor api_url http://$HOST_IP:6385 | 
|  | 221 | iniset $IRONIC_CONF_FILE pxe tftp_server $HOST_IP | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 222 | iniset $IRONIC_CONF_FILE pxe tftp_root $IRONIC_TFTPBOOT_DIR | 
|  | 223 | iniset $IRONIC_CONF_FILE pxe tftp_master_path $IRONIC_TFTPBOOT_DIR/master_images | 
| Adam Gandelman | 8af6fae | 2014-04-11 17:06:14 -0700 | [diff] [blame] | 224 | if [[ "$IRONIC_VM_LOG_CONSOLE" == "True" ]] ; then | 
|  | 225 | iniset $IRONIC_CONF_FILE pxe pxe_append_params "nofb nomodeset vga=normal console=ttyS0" | 
|  | 226 | fi | 
| Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 227 | if [[ "$IRONIC_DEPLOY_DRIVER" == "agent_ssh" ]] ; then | 
|  | 228 | if [[ "$SWIFT_ENABLE_TEMPURLS" == "True" ]] ; then | 
|  | 229 | iniset $IRONIC_CONF_FILE glance swift_temp_url_key $SWIFT_TEMPURL_KEY | 
|  | 230 | else | 
|  | 231 | die $LINENO "SWIFT_ENABLE_TEMPURLS must be True to use agent_ssh driver in Ironic." | 
|  | 232 | fi | 
|  | 233 | iniset $IRONIC_CONF_FILE glance swift_endpoint_url http://${HOST_IP}:8080 | 
|  | 234 | iniset $IRONIC_CONF_FILE glance swift_api_version v1 | 
|  | 235 | iniset $IRONIC_CONF_FILE glance swift_account AUTH_${SERVICE_TENANT} | 
|  | 236 | iniset $IRONIC_CONF_FILE glance swift_container glance | 
|  | 237 | iniset $IRONIC_CONF_FILE glance swift_temp_url_duration 3600 | 
|  | 238 | iniset $IRONIC_CONF_FILE agent heartbeat_timeout 30 | 
|  | 239 | if [[ "$IRONIC_VM_LOG_CONSOLE" == "True" ]] ; then | 
|  | 240 | iniset $IRONIC_CONF_FILE agent agent_pxe_append_params "nofb nomodeset vga=normal console=ttyS0" | 
|  | 241 | fi | 
|  | 242 | fi | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 243 | } | 
|  | 244 |  | 
|  | 245 | # create_ironic_cache_dir() - Part of the init_ironic() process | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 246 | function create_ironic_cache_dir { | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 247 | # Create cache dir | 
|  | 248 | sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/api | 
|  | 249 | sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/api | 
|  | 250 | rm -f $IRONIC_AUTH_CACHE_DIR/api/* | 
|  | 251 | sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/registry | 
|  | 252 | sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/registry | 
|  | 253 | rm -f $IRONIC_AUTH_CACHE_DIR/registry/* | 
|  | 254 | } | 
|  | 255 |  | 
|  | 256 | # create_ironic_accounts() - Set up common required ironic accounts | 
|  | 257 |  | 
|  | 258 | # Tenant               User       Roles | 
|  | 259 | # ------------------------------------------------------------------ | 
|  | 260 | # service              ironic     admin        # if enabled | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 261 | function create_ironic_accounts { | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 262 |  | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 263 | local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") | 
|  | 264 | local admin_role=$(openstack role list | awk "/ admin / { print \$2 }") | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 265 |  | 
|  | 266 | # Ironic | 
|  | 267 | if [[ "$ENABLED_SERVICES" =~ "ir-api" ]]; then | 
| Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 268 | # Get ironic user if exists | 
|  | 269 |  | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 270 | local ironic_user=$(get_or_create_user "ironic" \ | 
|  | 271 | "$SERVICE_PASSWORD" $service_tenant) | 
|  | 272 | get_or_add_user_role $admin_role $ironic_user $service_tenant | 
| Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 273 |  | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 274 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then | 
| Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 275 |  | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 276 | local ironic_service=$(get_or_create_service "ironic" \ | 
| Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 277 | "baremetal" "Ironic baremetal provisioning service") | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 278 | get_or_create_endpoint $ironic_service \ | 
| Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 279 | "$REGION_NAME" \ | 
|  | 280 | "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \ | 
|  | 281 | "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \ | 
|  | 282 | "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 283 | fi | 
|  | 284 | fi | 
|  | 285 | } | 
|  | 286 |  | 
|  | 287 |  | 
|  | 288 | # init_ironic() - Initialize databases, etc. | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 289 | function init_ironic { | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 290 | # (Re)create  ironic database | 
|  | 291 | recreate_database ironic utf8 | 
|  | 292 |  | 
|  | 293 | # Migrate ironic database | 
| Dmitry Tantsur | 0c6a654 | 2014-06-02 20:19:33 +0200 | [diff] [blame] | 294 | $IRONIC_BIN_DIR/ironic-dbsync --config-file=$IRONIC_CONF_FILE | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 295 |  | 
|  | 296 | create_ironic_cache_dir | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 297 | } | 
|  | 298 |  | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 299 | # start_ironic() - Start running processes, including screen | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 300 | function start_ironic { | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 301 | # Start Ironic API server, if enabled. | 
|  | 302 | if is_service_enabled ir-api; then | 
|  | 303 | start_ironic_api | 
|  | 304 | fi | 
|  | 305 |  | 
|  | 306 | # Start Ironic conductor, if enabled. | 
|  | 307 | if is_service_enabled ir-cond; then | 
|  | 308 | start_ironic_conductor | 
|  | 309 | fi | 
|  | 310 | } | 
|  | 311 |  | 
|  | 312 | # start_ironic_api() - Used by start_ironic(). | 
|  | 313 | # Starts Ironic API server. | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 314 | function start_ironic_api { | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 315 | screen_it ir-api "cd $IRONIC_DIR; $IRONIC_BIN_DIR/ironic-api --config-file=$IRONIC_CONF_FILE" | 
|  | 316 | echo "Waiting for ir-api ($IRONIC_HOSTPORT) to start..." | 
| JUN JIE NAN | 0aa8534 | 2013-09-13 15:47:09 +0800 | [diff] [blame] | 317 | if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q -O- http://$IRONIC_HOSTPORT; do sleep 1; done"; then | 
| Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 318 | die $LINENO "ir-api did not start" | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 319 | fi | 
|  | 320 | } | 
|  | 321 |  | 
|  | 322 | # start_ironic_conductor() - Used by start_ironic(). | 
|  | 323 | # Starts Ironic conductor. | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 324 | function start_ironic_conductor { | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 325 | screen_it ir-cond "cd $IRONIC_DIR; $IRONIC_BIN_DIR/ironic-conductor --config-file=$IRONIC_CONF_FILE" | 
|  | 326 | # TODO(romcheg): Find a way to check whether the conductor has started. | 
|  | 327 | } | 
|  | 328 |  | 
|  | 329 | # stop_ironic() - Stop running processes | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 330 | function stop_ironic { | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 331 | # Kill the Ironic screen windows | 
|  | 332 | screen -S $SCREEN_NAME -p ir-api -X kill | 
|  | 333 | screen -S $SCREEN_NAME -p ir-cond -X kill | 
|  | 334 | } | 
|  | 335 |  | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 336 | function is_ironic { | 
|  | 337 | if ( is_service_enabled ir-cond && is_service_enabled ir-api ); then | 
|  | 338 | return 0 | 
|  | 339 | fi | 
|  | 340 | return 1 | 
|  | 341 | } | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 342 |  | 
| Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 343 | function create_ovs_taps { | 
|  | 344 | local ironic_net_id=$(neutron net-list | grep private | get_field 1) | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 345 |  | 
| Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 346 | # Work around: No netns exists on host until a Neutron port is created.  We | 
|  | 347 | # need to create one in Neutron to know what netns to tap into prior to the | 
|  | 348 | # first node booting. | 
|  | 349 | local port_id=$(neutron port-create private | grep " id " | get_field 2) | 
|  | 350 |  | 
|  | 351 | # intentional sleep to make sure the tag has been set to port | 
|  | 352 | sleep 10 | 
|  | 353 |  | 
|  | 354 | local tapdev=$(sudo ip netns exec qdhcp-${ironic_net_id} ip link list | grep tap | cut -d':' -f2 | cut -b2-) | 
|  | 355 | local tag_id=$(sudo ovs-vsctl show |grep ${tapdev} -A1 -m1 | grep tag | cut -d':' -f2 | cut -b2-) | 
|  | 356 |  | 
|  | 357 | # make sure veth pair is not existing, otherwise delete its links | 
|  | 358 | sudo ip link show ovs-tap1 && sudo ip link delete ovs-tap1 | 
|  | 359 | sudo ip link show brbm-tap1 && sudo ip link delete brbm-tap1 | 
|  | 360 | # create veth pair for future interconnection between br-int and brbm | 
|  | 361 | sudo ip link add brbm-tap1 type veth peer name ovs-tap1 | 
|  | 362 | sudo ip link set dev brbm-tap1 up | 
|  | 363 | sudo ip link set dev ovs-tap1 up | 
|  | 364 |  | 
|  | 365 | sudo ovs-vsctl -- --if-exists del-port ovs-tap1 -- add-port br-int ovs-tap1 tag=$tag_id | 
|  | 366 | sudo ovs-vsctl -- --if-exists del-port brbm-tap1 -- add-port $IRONIC_VM_NETWORK_BRIDGE brbm-tap1 | 
|  | 367 |  | 
|  | 368 | # Remove the port needed only for workaround. | 
|  | 369 | neutron port-delete $port_id | 
| Adam Gandelman | cec9792 | 2014-07-29 18:43:18 -0700 | [diff] [blame^] | 370 |  | 
|  | 371 | # Finally, share the fixed tenant network across all tenants.  This allows the host | 
|  | 372 | # to serve TFTP to a single network namespace via the tap device created above. | 
|  | 373 | neutron net-update $ironic_net_id --shared true | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 374 | } | 
|  | 375 |  | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 376 | function create_bridge_and_vms { | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 377 | # Call libvirt setup scripts in a new shell to ensure any new group membership | 
|  | 378 | sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/setup-network" | 
| Adam Gandelman | 8af6fae | 2014-04-11 17:06:14 -0700 | [diff] [blame] | 379 | if [[ "$IRONIC_VM_LOG_CONSOLE" == "True" ]] ; then | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 380 | local log_arg="$IRONIC_VM_LOG_DIR" | 
| Adam Gandelman | 8af6fae | 2014-04-11 17:06:14 -0700 | [diff] [blame] | 381 | else | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 382 | local log_arg="" | 
| Adam Gandelman | 8af6fae | 2014-04-11 17:06:14 -0700 | [diff] [blame] | 383 | fi | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 384 | sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/create-nodes \ | 
|  | 385 | $IRONIC_VM_SPECS_CPU $IRONIC_VM_SPECS_RAM $IRONIC_VM_SPECS_DISK \ | 
| Adam Gandelman | 8af6fae | 2014-04-11 17:06:14 -0700 | [diff] [blame] | 386 | amd64 $IRONIC_VM_COUNT $IRONIC_VM_NETWORK_BRIDGE $IRONIC_VM_EMULATOR \ | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 387 | $log_arg" >> $IRONIC_VM_MACS_CSV_FILE | 
| Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 388 | create_ovs_taps | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 389 | } | 
|  | 390 |  | 
|  | 391 | function enroll_vms { | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 392 | local chassis_id=$(ironic chassis-create -d "ironic test chassis" | grep " uuid " | get_field 2) | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 393 | local idx=0 | 
| Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 394 |  | 
|  | 395 | if [[ "$IRONIC_DEPLOY_DRIVER" == "pxe_ssh" ]] ; then | 
|  | 396 | local _IRONIC_DEPLOY_KERNEL_KEY=pxe_deploy_kernel | 
|  | 397 | local _IRONIC_DEPLOY_RAMDISK_KEY=pxe_deploy_ramdisk | 
|  | 398 | elif [[ "$IRONIC_DEPLOY_DRIVER" == "agent_ssh" ]] ; then | 
|  | 399 | local _IRONIC_DEPLOY_KERNEL_KEY=deploy_kernel | 
|  | 400 | local _IRONIC_DEPLOY_RAMDISK_KEY=deploy_ramdisk | 
|  | 401 | fi | 
|  | 402 |  | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 403 | while read MAC; do | 
| Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 404 |  | 
|  | 405 | local node_id=$(ironic node-create --chassis_uuid $chassis_id \ | 
|  | 406 | --driver $IRONIC_DEPLOY_DRIVER \ | 
|  | 407 | -i $_IRONIC_DEPLOY_KERNEL_KEY=$IRONIC_DEPLOY_KERNEL_ID \ | 
|  | 408 | -i $_IRONIC_DEPLOY_RAMDISK_KEY=$IRONIC_DEPLOY_RAMDISK_ID \ | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 409 | -i ssh_virt_type=$IRONIC_SSH_VIRT_TYPE \ | 
|  | 410 | -i ssh_address=$IRONIC_VM_SSH_ADDRESS \ | 
|  | 411 | -i ssh_port=$IRONIC_VM_SSH_PORT \ | 
|  | 412 | -i ssh_username=$IRONIC_SSH_USERNAME \ | 
|  | 413 | -i ssh_key_filename=$IRONIC_SSH_KEY_DIR/$IRONIC_SSH_KEY_FILENAME \ | 
|  | 414 | -p cpus=$IRONIC_VM_SPECS_CPU \ | 
|  | 415 | -p memory_mb=$IRONIC_VM_SPECS_RAM \ | 
|  | 416 | -p local_gb=$IRONIC_VM_SPECS_DISK \ | 
|  | 417 | -p cpu_arch=x86_64 \ | 
|  | 418 | | grep " uuid " | get_field 2) | 
|  | 419 |  | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 420 | ironic port-create --address $MAC --node_uuid $node_id | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 421 |  | 
|  | 422 | idx=$((idx+1)) | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 423 | done < $IRONIC_VM_MACS_CSV_FILE | 
|  | 424 |  | 
|  | 425 | # create the nova flavor | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 426 | local adjusted_disk=$(($IRONIC_VM_SPECS_DISK - $IRONIC_VM_EPHEMERAL_DISK)) | 
| David Shrewsbury | 3e4612b | 2014-05-01 11:38:21 -0400 | [diff] [blame] | 427 | nova flavor-create --ephemeral $IRONIC_VM_EPHEMERAL_DISK baremetal auto $IRONIC_VM_SPECS_RAM $adjusted_disk $IRONIC_VM_SPECS_CPU | 
| Lucas Alvares Gomes | cd7cfef | 2014-05-26 14:58:37 +0100 | [diff] [blame] | 428 | # TODO(lucasagomes): Remove the 'baremetal:deploy_kernel_id' | 
|  | 429 | # and 'baremetal:deploy_ramdisk_id' parameters | 
|  | 430 | # from the flavor after the completion of | 
|  | 431 | # https://blueprints.launchpad.net/ironic/+spec/add-node-instance-info | 
| Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 432 | nova flavor-key baremetal set "cpu_arch"="x86_64" "baremetal:deploy_kernel_id"="$IRONIC_DEPLOY_KERNEL_ID" "baremetal:deploy_ramdisk_id"="$IRONIC_DEPLOY_RAMDISK_ID" | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 433 | } | 
|  | 434 |  | 
| Adam Gandelman | c1f0db2 | 2014-04-14 13:21:22 -0700 | [diff] [blame] | 435 | function configure_iptables { | 
|  | 436 | # enable tftp natting for allowing connections to HOST_IP's tftp server | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 437 | sudo modprobe nf_conntrack_tftp | 
|  | 438 | sudo modprobe nf_nat_tftp | 
| Adam Gandelman | c1f0db2 | 2014-04-14 13:21:22 -0700 | [diff] [blame] | 439 | # nodes boot from TFTP and callback to the API server listening on $HOST_IP | 
|  | 440 | sudo iptables -I INPUT -d $HOST_IP -p udp --dport 69 -j ACCEPT || true | 
|  | 441 | sudo iptables -I INPUT -d $HOST_IP -p tcp --dport 6385 -j ACCEPT || true | 
|  | 442 | } | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 443 |  | 
| Adam Gandelman | c1f0db2 | 2014-04-14 13:21:22 -0700 | [diff] [blame] | 444 | function configure_tftpd { | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 445 | if is_ubuntu; then | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 446 | local pxebin=/usr/lib/syslinux/pxelinux.0 | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 447 | elif is_fedora; then | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 448 | local pxebin=/usr/share/syslinux/pxelinux.0 | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 449 | fi | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 450 | if [ ! -f $pxebin ]; then | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 451 | die $LINENO "pxelinux.0 (from SYSLINUX) not found." | 
|  | 452 | fi | 
|  | 453 |  | 
|  | 454 | # stop tftpd and setup serving via xinetd | 
|  | 455 | stop_service tftpd-hpa || true | 
|  | 456 | [ -f /etc/init/tftpd-hpa.conf ] && echo "manual" | sudo tee /etc/init/tftpd-hpa.override | 
|  | 457 | sudo cp $IRONIC_TEMPLATES_DIR/tftpd-xinetd.template /etc/xinetd.d/tftp | 
|  | 458 | sudo sed -e "s|%TFTPBOOT_DIR%|$IRONIC_TFTPBOOT_DIR|g" -i /etc/xinetd.d/tftp | 
|  | 459 |  | 
|  | 460 | # setup tftp file mapping to satisfy requests at the root (booting) and | 
|  | 461 | # /tftpboot/ sub-dir (as per deploy-ironic elements) | 
|  | 462 | echo "r ^([^/]) $IRONIC_TFTPBOOT_DIR/\1" >$IRONIC_TFTPBOOT_DIR/map-file | 
|  | 463 | echo "r ^(/tftpboot/) $IRONIC_TFTPBOOT_DIR/\2" >>$IRONIC_TFTPBOOT_DIR/map-file | 
|  | 464 |  | 
|  | 465 | chmod -R 0755 $IRONIC_TFTPBOOT_DIR | 
|  | 466 | restart_service xinetd | 
|  | 467 | } | 
|  | 468 |  | 
|  | 469 | function configure_ironic_ssh_keypair { | 
|  | 470 | # Generating ssh key pair for stack user | 
|  | 471 | if [[ ! -d $IRONIC_SSH_KEY_DIR ]]; then | 
|  | 472 | mkdir -p $IRONIC_SSH_KEY_DIR | 
|  | 473 | fi | 
|  | 474 | if [[ ! -d $HOME/.ssh ]]; then | 
|  | 475 | mkdir -p $HOME/.ssh | 
|  | 476 | chmod 700 $HOME/.ssh | 
|  | 477 | fi | 
|  | 478 | echo -e 'n\n' | ssh-keygen -q -t rsa -P '' -f $IRONIC_KEY_FILE | 
|  | 479 | cat $IRONIC_KEY_FILE.pub | tee -a $IRONIC_AUTHORIZED_KEYS_FILE | 
|  | 480 | } | 
|  | 481 |  | 
|  | 482 | function ironic_ssh_check { | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 483 | local key_file=$1 | 
|  | 484 | local floating_ip=$2 | 
|  | 485 | local port=$3 | 
|  | 486 | local default_instance_user=$4 | 
|  | 487 | local active_timeout=$5 | 
|  | 488 | 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 Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 489 | die $LINENO "server didn't become ssh-able!" | 
|  | 490 | fi | 
|  | 491 | } | 
|  | 492 |  | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 493 | function configure_ironic_auxiliary { | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 494 | configure_ironic_ssh_keypair | 
| Adam Gandelman | 8676510 | 2014-04-14 11:57:13 -0700 | [diff] [blame] | 495 | ironic_ssh_check $IRONIC_SSH_KEY_DIR/$IRONIC_SSH_KEY_FILENAME $IRONIC_VM_SSH_ADDRESS $IRONIC_VM_SSH_PORT $IRONIC_SSH_USERNAME 10 | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 496 | } | 
|  | 497 |  | 
| Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 498 | # build deploy kernel+ramdisk, then upload them to glance | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 499 | # this function sets ``IRONIC_DEPLOY_KERNEL_ID``, ``IRONIC_DEPLOY_RAMDISK_ID`` | 
| Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 500 | function upload_baremetal_ironic_deploy { | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 501 | declare -g IRONIC_DEPLOY_KERNEL_ID IRONIC_DEPLOY_RAMDISK_ID | 
| Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 502 | echo_summary "Creating and uploading baremetal images for ironic" | 
|  | 503 |  | 
|  | 504 | # install diskimage-builder | 
|  | 505 | git_clone $DIB_REPO $DIB_DIR $DIB_BRANCH | 
| Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 506 |  | 
|  | 507 | if [ -z "$IRONIC_DEPLOY_KERNEL" -o -z "$IRONIC_DEPLOY_RAMDISK" ]; then | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 508 | local IRONIC_DEPLOY_KERNEL_PATH=$TOP_DIR/files/ir-deploy.kernel | 
|  | 509 | local IRONIC_DEPLOY_RAMDISK_PATH=$TOP_DIR/files/ir-deploy.initramfs | 
| Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 510 | else | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 511 | local IRONIC_DEPLOY_KERNEL_PATH=$IRONIC_DEPLOY_KERNEL | 
|  | 512 | local IRONIC_DEPLOY_RAMDISK_PATH=$IRONIC_DEPLOY_RAMDISK | 
| Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 513 | fi | 
|  | 514 |  | 
|  | 515 | if [ ! -e "$IRONIC_DEPLOY_RAMDISK_PATH" -o ! -e "$IRONIC_DEPLOY_KERNEL_PATH" ]; then | 
|  | 516 | # files don't exist, need to build them | 
|  | 517 | if [ "$IRONIC_BUILD_DEPLOY_RAMDISK" = "True" ]; then | 
|  | 518 | # we can build them only if we're not offline | 
|  | 519 | if [ "$OFFLINE" != "True" ]; then | 
| Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 520 | if [ "$IRONIC_DEPLOY_RAMDISK" == "agent_ssh" ]; then | 
|  | 521 | die $LINENO "Ironic-python-agent build is not yet supported" | 
|  | 522 | else | 
|  | 523 | $DIB_DIR/bin/ramdisk-image-create $IRONIC_DEPLOY_FLAVOR \ | 
|  | 524 | -o $TOP_DIR/files/ir-deploy | 
|  | 525 | fi | 
| Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 526 | else | 
|  | 527 | die $LINENO "Deploy kernel+ramdisk files don't exist and cannot be build in OFFLINE mode" | 
|  | 528 | fi | 
|  | 529 | else | 
| Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 530 | if [ "$IRONIC_DEPLOY_DRIVER" == "agent_ssh" ]; then | 
|  | 531 | # download the agent image tarball | 
|  | 532 | wget "$IRONIC_AGENT_TARBALL" -O ironic_agent_tarball.tar.gz | 
|  | 533 | tar zxfv ironic_agent_tarball.tar.gz | 
|  | 534 | mv UPLOAD/coreos_production_pxe.vmlinuz $IRONIC_DEPLOY_KERNEL_PATH | 
|  | 535 | mv UPLOAD/coreos_production_pxe_image-oem.cpio.gz $IRONIC_DEPLOY_RAMDISK_PATH | 
|  | 536 | rm -rf UPLOAD | 
|  | 537 | rm ironic_agent_tarball.tar.gz | 
|  | 538 | else | 
|  | 539 | die $LINENO "Deploy kernel+ramdisk files don't exist and their building was disabled explicitly by IRONIC_BUILD_DEPLOY_RAMDISK" | 
|  | 540 | fi | 
| Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 541 | fi | 
|  | 542 | fi | 
|  | 543 |  | 
| Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 544 | local token=$(keystone token-get | grep ' id ' | get_field 2) | 
|  | 545 | die_if_not_set $LINENO token "Keystone fail to get token" | 
|  | 546 |  | 
| Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 547 | # load them into glance | 
| Steve Martinelli | 8d3ac2d | 2014-08-02 23:47:15 -0400 | [diff] [blame] | 548 | IRONIC_DEPLOY_KERNEL_ID=$(openstack \ | 
|  | 549 | --os-token $token \ | 
|  | 550 | --os-url http://$GLANCE_HOSTPORT \ | 
|  | 551 | image create \ | 
|  | 552 | $(basename $IRONIC_DEPLOY_KERNEL_PATH) \ | 
|  | 553 | --public --disk-format=aki \ | 
| Jim Rollenhagen | 722284f | 2014-08-15 18:04:02 +0000 | [diff] [blame] | 554 | --container-format=aki \ | 
| Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 555 | < $IRONIC_DEPLOY_KERNEL_PATH  | grep ' id ' | get_field 2) | 
| Steve Martinelli | 8d3ac2d | 2014-08-02 23:47:15 -0400 | [diff] [blame] | 556 | IRONIC_DEPLOY_RAMDISK_ID=$(openstack \ | 
|  | 557 | --os-token $token \ | 
|  | 558 | --os-url http://$GLANCE_HOSTPORT \ | 
|  | 559 | image create \ | 
|  | 560 | $(basename $IRONIC_DEPLOY_RAMDISK_PATH) \ | 
|  | 561 | --public --disk-format=ari \ | 
| Jim Rollenhagen | 722284f | 2014-08-15 18:04:02 +0000 | [diff] [blame] | 562 | --container-format=ari \ | 
| Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 563 | < $IRONIC_DEPLOY_RAMDISK_PATH  | grep ' id ' | get_field 2) | 
|  | 564 | } | 
|  | 565 |  | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 566 | function prepare_baremetal_basic_ops { | 
| Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 567 | upload_baremetal_ironic_deploy | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 568 | create_bridge_and_vms | 
|  | 569 | enroll_vms | 
|  | 570 | configure_tftpd | 
| Adam Gandelman | c1f0db2 | 2014-04-14 13:21:22 -0700 | [diff] [blame] | 571 | configure_iptables | 
| Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 572 | configure_ironic_auxiliary | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 573 | } | 
|  | 574 |  | 
|  | 575 | function cleanup_baremetal_basic_ops { | 
|  | 576 | rm -f $IRONIC_VM_MACS_CSV_FILE | 
|  | 577 | if [ -f $IRONIC_KEY_FILE ]; then | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 578 | local key=$(cat $IRONIC_KEY_FILE.pub) | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 579 | # remove public key from authorized_keys | 
| Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 580 | grep -v "$key" $IRONIC_AUTHORIZED_KEYS_FILE > temp && mv temp $IRONIC_AUTHORIZED_KEYS_FILE | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 581 | chmod 0600 $IRONIC_AUTHORIZED_KEYS_FILE | 
|  | 582 | fi | 
|  | 583 | sudo rm -rf $IRONIC_DATA_DIR $IRONIC_STATE_PATH | 
|  | 584 | sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/cleanup-nodes $IRONIC_VM_COUNT $IRONIC_VM_NETWORK_BRIDGE" | 
|  | 585 | sudo rm -rf /etc/xinetd.d/tftp /etc/init/tftpd-hpa.override | 
|  | 586 | restart_service xinetd | 
| Adam Gandelman | c1f0db2 | 2014-04-14 13:21:22 -0700 | [diff] [blame] | 587 | sudo iptables -D INPUT -d $HOST_IP -p udp --dport 69 -j ACCEPT || true | 
|  | 588 | sudo iptables -D INPUT -d $HOST_IP -p tcp --dport 6385 -j ACCEPT || true | 
|  | 589 | sudo rmmod nf_conntrack_tftp || true | 
|  | 590 | sudo rmmod nf_nat_tftp || true | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 591 | } | 
|  | 592 |  | 
|  | 593 | # Restore xtrace + pipefail | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 594 | $XTRACE | 
| Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 595 | $PIPEFAIL | 
| Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 596 |  | 
| Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 597 | # Tell emacs to use shell-script-mode | 
|  | 598 | ## Local variables: | 
|  | 599 | ## mode: shell-script | 
|  | 600 | ## End: |