Sean Dague | e263c82 | 2014-12-05 14:25:28 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 3 | # lib/ironic |
| 4 | # Functions to control the configuration and operation of the **Ironic** service |
| 5 | |
| 6 | # Dependencies: |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 7 | # |
| 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 Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 13 | |
| 14 | # ``stack.sh`` calls the entry points in this order: |
| 15 | # |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 16 | # - install_ironic |
| 17 | # - install_ironicclient |
| 18 | # - init_ironic |
| 19 | # - start_ironic |
| 20 | # - stop_ironic |
| 21 | # - cleanup_ironic |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 22 | |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 23 | # Save trace and pipefail settings |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 24 | XTRACE=$(set +o | grep xtrace) |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 25 | PIPEFAIL=$(set +o | grep pipefail) |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 26 | set +o xtrace |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 27 | set +o pipefail |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 28 | |
| 29 | # Defaults |
| 30 | # -------- |
| 31 | |
| 32 | # Set up default directories |
Sean Dague | e08ab10 | 2014-11-13 17:09:28 -0500 | [diff] [blame] | 33 | GITDIR["python-ironicclient"]=$DEST/python-ironicclient |
Sean Dague | 5cb1906 | 2014-11-01 01:37:45 +0100 | [diff] [blame] | 34 | |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 35 | IRONIC_DIR=$DEST/ironic |
Jim Rollenhagen | f00766b | 2014-08-15 01:08:11 +0000 | [diff] [blame] | 36 | IRONIC_PYTHON_AGENT_DIR=$DEST/ironic-python-agent |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 37 | IRONIC_DATA_DIR=$DATA_DIR/ironic |
| 38 | IRONIC_STATE_PATH=/var/lib/ironic |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 39 | IRONIC_AUTH_CACHE_DIR=${IRONIC_AUTH_CACHE_DIR:-/var/cache/ironic} |
| 40 | IRONIC_CONF_DIR=${IRONIC_CONF_DIR:-/etc/ironic} |
| 41 | IRONIC_CONF_FILE=$IRONIC_CONF_DIR/ironic.conf |
| 42 | IRONIC_ROOTWRAP_CONF=$IRONIC_CONF_DIR/rootwrap.conf |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 43 | IRONIC_POLICY_JSON=$IRONIC_CONF_DIR/policy.json |
| 44 | |
yunhong jiang | ae9ee6b | 2014-10-08 07:01:02 -0700 | [diff] [blame] | 45 | # Deploy to hardware platform |
| 46 | IRONIC_HW_NODE_CPU=${IRONIC_HW_NODE_CPU:-1} |
| 47 | IRONIC_HW_NODE_RAM=${IRONIC_HW_NODE_RAM:-512} |
| 48 | IRONIC_HW_NODE_DISK=${IRONIC_HW_NODE_DISK:-10} |
| 49 | IRONIC_HW_EPHEMERAL_DISK=${IRONIC_HW_EPHEMERAL_DISK:-0} |
| 50 | # The file is composed of multiple lines, each line includes four field |
| 51 | # separated by white space: IPMI address, MAC address, IPMI username |
| 52 | # and IPMI password. |
| 53 | # An example: |
| 54 | # 192.168.110.107 00:1e:67:57:50:4c root otc123 |
| 55 | IRONIC_IPMIINFO_FILE=${IRONIC_IPMIINFO_FILE:-$IRONIC_DATA_DIR/hardware_info} |
| 56 | |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 57 | # Set up defaults for functional / integration testing |
| 58 | IRONIC_SCRIPTS_DIR=${IRONIC_SCRIPTS_DIR:-$TOP_DIR/tools/ironic/scripts} |
| 59 | IRONIC_TEMPLATES_DIR=${IRONIC_TEMPLATES_DIR:-$TOP_DIR/tools/ironic/templates} |
| 60 | IRONIC_BAREMETAL_BASIC_OPS=$(trueorfalse False $IRONIC_BAREMETAL_BASIC_OPS) |
Devananda van der Veen | 83eeed0 | 2014-04-11 10:08:41 -0700 | [diff] [blame] | 61 | IRONIC_ENABLED_DRIVERS=${IRONIC_ENABLED_DRIVERS:-fake,pxe_ssh,pxe_ipmitool} |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 62 | IRONIC_SSH_USERNAME=${IRONIC_SSH_USERNAME:-`whoami`} |
| 63 | IRONIC_SSH_KEY_DIR=${IRONIC_SSH_KEY_DIR:-$IRONIC_DATA_DIR/ssh_keys} |
| 64 | IRONIC_SSH_KEY_FILENAME=${IRONIC_SSH_KEY_FILENAME:-ironic_key} |
Adam Gandelman | 6c74932 | 2014-12-02 16:20:50 -0800 | [diff] [blame] | 65 | IRONIC_KEY_FILE=${IRONIC_KEY_FILE:-$IRONIC_SSH_KEY_DIR/$IRONIC_SSH_KEY_FILENAME} |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 66 | IRONIC_SSH_VIRT_TYPE=${IRONIC_SSH_VIRT_TYPE:-virsh} |
| 67 | IRONIC_TFTPBOOT_DIR=${IRONIC_TFTPBOOT_DIR:-$IRONIC_DATA_DIR/tftpboot} |
yunhong jiang | ae9ee6b | 2014-10-08 07:01:02 -0700 | [diff] [blame] | 68 | IRONIC_TFTPSERVER_IP=${IRONIC_TFTPSERVER_IP:-$HOST_IP} |
Adam Gandelman | 8676510 | 2014-04-14 11:57:13 -0700 | [diff] [blame] | 69 | IRONIC_VM_SSH_PORT=${IRONIC_VM_SSH_PORT:-22} |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 70 | IRONIC_VM_SSH_ADDRESS=${IRONIC_VM_SSH_ADDRESS:-$HOST_IP} |
| 71 | IRONIC_VM_COUNT=${IRONIC_VM_COUNT:-1} |
| 72 | IRONIC_VM_SPECS_CPU=${IRONIC_VM_SPECS_CPU:-1} |
Adam Gandelman | ea335f4 | 2014-07-03 17:57:49 -0700 | [diff] [blame] | 73 | IRONIC_VM_SPECS_RAM=${IRONIC_VM_SPECS_RAM:-512} |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 74 | IRONIC_VM_SPECS_DISK=${IRONIC_VM_SPECS_DISK:-10} |
David Shrewsbury | 3e4612b | 2014-05-01 11:38:21 -0400 | [diff] [blame] | 75 | IRONIC_VM_EPHEMERAL_DISK=${IRONIC_VM_EPHEMERAL_DISK:-0} |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 76 | IRONIC_VM_EMULATOR=${IRONIC_VM_EMULATOR:-/usr/bin/qemu-system-x86_64} |
| 77 | IRONIC_VM_NETWORK_BRIDGE=${IRONIC_VM_NETWORK_BRIDGE:-brbm} |
| 78 | IRONIC_VM_NETWORK_RANGE=${IRONIC_VM_NETWORK_RANGE:-192.0.2.0/24} |
| 79 | IRONIC_VM_MACS_CSV_FILE=${IRONIC_VM_MACS_CSV_FILE:-$IRONIC_DATA_DIR/ironic_macs.csv} |
| 80 | IRONIC_AUTHORIZED_KEYS_FILE=${IRONIC_AUTHORIZED_KEYS_FILE:-$HOME/.ssh/authorized_keys} |
| 81 | |
Adam Gandelman | 8af6fae | 2014-04-11 17:06:14 -0700 | [diff] [blame] | 82 | # By default, baremetal VMs will console output to file. |
| 83 | IRONIC_VM_LOG_CONSOLE=${IRONIC_VM_LOG_CONSOLE:-True} |
| 84 | IRONIC_VM_LOG_DIR=${IRONIC_VM_LOG_DIR:-$IRONIC_DATA_DIR/logs/} |
| 85 | |
Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 86 | # Use DIB to create deploy ramdisk and kernel. |
| 87 | IRONIC_BUILD_DEPLOY_RAMDISK=`trueorfalse True $IRONIC_BUILD_DEPLOY_RAMDISK` |
| 88 | # If not use DIB, these files are used as deploy ramdisk/kernel. |
| 89 | # (The value must be a absolute path) |
| 90 | IRONIC_DEPLOY_RAMDISK=${IRONIC_DEPLOY_RAMDISK:-} |
| 91 | IRONIC_DEPLOY_KERNEL=${IRONIC_DEPLOY_KERNEL:-} |
| 92 | IRONIC_DEPLOY_ELEMENT=${IRONIC_DEPLOY_ELEMENT:-deploy-ironic} |
| 93 | |
Jim Rollenhagen | 792dc5f | 2014-08-27 17:03:00 -0700 | [diff] [blame] | 94 | IRONIC_AGENT_KERNEL_URL=${IRONIC_AGENT_KERNEL_URL:-http://tarballs.openstack.org/ironic-python-agent/coreos/files/coreos_production_pxe.vmlinuz} |
Jim Rollenhagen | 4cb0d8c | 2014-09-11 16:45:58 -0700 | [diff] [blame] | 95 | IRONIC_AGENT_RAMDISK_URL=${IRONIC_AGENT_RAMDISK_URL:-http://tarballs.openstack.org/ironic-python-agent/coreos/files/coreos_production_pxe_image-oem.cpio.gz} |
Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 96 | |
| 97 | # Which deploy driver to use - valid choices right now |
yunhong jiang | fe96ed6 | 2014-11-05 03:30:25 -0700 | [diff] [blame] | 98 | # are 'pxe_ssh', 'pxe_ipmitool', 'agent_ssh' and 'agent_ipmitool'. |
Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 99 | IRONIC_DEPLOY_DRIVER=${IRONIC_DEPLOY_DRIVER:-pxe_ssh} |
| 100 | |
Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 101 | #TODO(agordeev): replace 'ubuntu' with host distro name getting |
| 102 | IRONIC_DEPLOY_FLAVOR=${IRONIC_DEPLOY_FLAVOR:-ubuntu $IRONIC_DEPLOY_ELEMENT} |
| 103 | |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 104 | # Support entry points installation of console scripts |
| 105 | IRONIC_BIN_DIR=$(get_python_exec_prefix) |
| 106 | |
| 107 | # Ironic connection info. Note the port must be specified. |
| 108 | IRONIC_SERVICE_PROTOCOL=http |
Adam Gandelman | 4b45fca | 2014-11-17 09:59:23 -0800 | [diff] [blame] | 109 | IRONIC_SERVICE_PORT=${IRONIC_SERVICE_PORT:-6385} |
| 110 | IRONIC_HOSTPORT=${IRONIC_HOSTPORT:-$SERVICE_HOST:$IRONIC_SERVICE_PORT} |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 111 | |
Dean Troyer | 4237f59 | 2014-01-29 16:22:11 -0600 | [diff] [blame] | 112 | # Tell Tempest this project is present |
| 113 | TEMPEST_SERVICES+=,ironic |
| 114 | |
Lucas Alvares Gomes | 5851e5f | 2014-08-19 10:01:45 +0100 | [diff] [blame] | 115 | # Enable iPXE |
| 116 | IRONIC_IPXE_ENABLED=$(trueorfalse False $IRONIC_IPXE_ENABLED) |
| 117 | IRONIC_HTTP_DIR=${IRONIC_HTTP_DIR:-$IRONIC_DATA_DIR/httpboot} |
| 118 | IRONIC_HTTP_SERVER=${IRONIC_HTTP_SERVER:-$HOST_IP} |
| 119 | IRONIC_HTTP_PORT=${IRONIC_HTTP_PORT:-8088} |
| 120 | |
| 121 | # get_pxe_boot_file() - Get the PXE/iPXE boot file path |
| 122 | function get_pxe_boot_file { |
| 123 | local relpath=syslinux/pxelinux.0 |
| 124 | if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then |
| 125 | relpath=ipxe/undionly.kpxe |
| 126 | fi |
| 127 | |
| 128 | local pxe_boot_file |
| 129 | if is_ubuntu; then |
| 130 | pxe_boot_file=/usr/lib/$relpath |
| 131 | elif is_fedora || is_suse; then |
| 132 | pxe_boot_file=/usr/share/$relpath |
| 133 | fi |
| 134 | |
| 135 | echo $pxe_boot_file |
| 136 | } |
| 137 | |
| 138 | # PXE boot image |
| 139 | IRONIC_PXE_BOOT_IMAGE=${IRONIC_PXE_BOOT_IMAGE:-$(get_pxe_boot_file)} |
| 140 | |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 141 | |
| 142 | # Functions |
| 143 | # --------- |
| 144 | |
Dean Troyer | 1023ff7 | 2014-01-27 14:56:44 -0600 | [diff] [blame] | 145 | # Test if any Ironic services are enabled |
| 146 | # is_ironic_enabled |
| 147 | function is_ironic_enabled { |
| 148 | [[ ,${ENABLED_SERVICES} =~ ,"ir-" ]] && return 0 |
| 149 | return 1 |
| 150 | } |
| 151 | |
yunhong jiang | ae9ee6b | 2014-10-08 07:01:02 -0700 | [diff] [blame] | 152 | function is_ironic_hardware { |
| 153 | is_ironic_enabled && [[ -n "${IRONIC_DEPLOY_DRIVER##*_ssh}" ]] && return 0 |
| 154 | return 1 |
| 155 | } |
| 156 | |
yunhong jiang | fe96ed6 | 2014-11-05 03:30:25 -0700 | [diff] [blame] | 157 | function is_deployed_by_agent { |
| 158 | [[ -z "${IRONIC_DEPLOY_DRIVER%%agent*}" ]] && return 0 |
| 159 | return 1 |
| 160 | } |
| 161 | |
Roman Prykhodchenko | 43e0066 | 2013-10-15 17:03:15 +0300 | [diff] [blame] | 162 | # install_ironic() - Collect source and prepare |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 163 | function install_ironic { |
Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 164 | # make sure all needed service were enabled |
| 165 | for srv in nova glance key; do |
| 166 | if ! is_service_enabled "$srv"; then |
| 167 | die $LINENO "$srv should be enabled for Ironic." |
| 168 | fi |
| 169 | done |
Roman Prykhodchenko | 43e0066 | 2013-10-15 17:03:15 +0300 | [diff] [blame] | 170 | git_clone $IRONIC_REPO $IRONIC_DIR $IRONIC_BRANCH |
| 171 | setup_develop $IRONIC_DIR |
Lucas Alvares Gomes | 5851e5f | 2014-08-19 10:01:45 +0100 | [diff] [blame] | 172 | |
| 173 | if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then |
| 174 | install_apache_wsgi |
| 175 | fi |
Roman Prykhodchenko | 43e0066 | 2013-10-15 17:03:15 +0300 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | # install_ironicclient() - Collect sources and prepare |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 179 | function install_ironicclient { |
Sean Dague | e08ab10 | 2014-11-13 17:09:28 -0500 | [diff] [blame] | 180 | if use_library_from_git "python-ironicclient"; then |
| 181 | git_clone_by_name "python-ironicclient" |
| 182 | setup_dev_lib "python-ironicclient" |
| 183 | sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-ironicclient"]}/tools/,/etc/bash_completion.d/}ironic.bash_completion |
Sean Dague | 5cb1906 | 2014-11-01 01:37:45 +0100 | [diff] [blame] | 184 | else |
| 185 | # nothing actually "requires" ironicclient, so force instally from pypi |
| 186 | pip_install python-ironicclient |
| 187 | fi |
Roman Prykhodchenko | 43e0066 | 2013-10-15 17:03:15 +0300 | [diff] [blame] | 188 | } |
| 189 | |
Lucas Alvares Gomes | 5851e5f | 2014-08-19 10:01:45 +0100 | [diff] [blame] | 190 | # _cleanup_ironic_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file |
| 191 | function _cleanup_ironic_apache_wsgi { |
| 192 | sudo rm -rf $IRONIC_HTTP_DIR |
| 193 | disable_apache_site ironic |
| 194 | sudo rm -f $(apache_site_config_for ironic) |
| 195 | restart_apache_server |
| 196 | } |
| 197 | |
| 198 | # _config_ironic_apache_wsgi() - Set WSGI config files of Ironic |
| 199 | function _config_ironic_apache_wsgi { |
| 200 | local ironic_apache_conf=$(apache_site_config_for ironic) |
| 201 | sudo cp $FILES/apache-ironic.template $ironic_apache_conf |
| 202 | sudo sed -e " |
| 203 | s|%PUBLICPORT%|$IRONIC_HTTP_PORT|g; |
| 204 | s|%HTTPROOT%|$IRONIC_HTTP_DIR|g; |
| 205 | " -i $ironic_apache_conf |
| 206 | enable_apache_site ironic |
| 207 | } |
| 208 | |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 209 | # cleanup_ironic() - Remove residual data files, anything left over from previous |
| 210 | # runs that would need to clean up. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 211 | function cleanup_ironic { |
lokesh | 683ed9e | 2014-11-10 15:07:59 +0530 | [diff] [blame] | 212 | sudo rm -rf $IRONIC_AUTH_CACHE_DIR $IRONIC_CONF_DIR |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 213 | } |
| 214 | |
Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 215 | # configure_ironic_dirs() - Create all directories required by Ironic and |
| 216 | # associated services. |
| 217 | function configure_ironic_dirs { |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 218 | if [[ ! -d $IRONIC_CONF_DIR ]]; then |
| 219 | sudo mkdir -p $IRONIC_CONF_DIR |
| 220 | fi |
Lucas Alvares Gomes | 5851e5f | 2014-08-19 10:01:45 +0100 | [diff] [blame] | 221 | |
| 222 | if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then |
| 223 | sudo mkdir -p $IRONIC_HTTP_DIR |
| 224 | sudo chown -R $STACK_USER:$LIBVIRT_GROUP $IRONIC_HTTP_DIR |
| 225 | fi |
| 226 | |
Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 227 | sudo mkdir -p $IRONIC_DATA_DIR |
| 228 | sudo mkdir -p $IRONIC_STATE_PATH |
| 229 | sudo mkdir -p $IRONIC_TFTPBOOT_DIR |
| 230 | sudo chown -R $STACK_USER $IRONIC_DATA_DIR $IRONIC_STATE_PATH |
| 231 | sudo chown -R $STACK_USER:$LIBVIRT_GROUP $IRONIC_TFTPBOOT_DIR |
Lucas Alvares Gomes | 5851e5f | 2014-08-19 10:01:45 +0100 | [diff] [blame] | 232 | mkdir -p $IRONIC_TFTPBOOT_DIR/pxelinux.cfg |
| 233 | |
| 234 | if [ ! -f $IRONIC_PXE_BOOT_IMAGE ]; then |
| 235 | die $LINENO "PXE boot file $IRONIC_PXE_BOOT_IMAGE not found." |
Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 236 | fi |
| 237 | |
Lucas Alvares Gomes | 5851e5f | 2014-08-19 10:01:45 +0100 | [diff] [blame] | 238 | cp $IRONIC_PXE_BOOT_IMAGE $IRONIC_TFTPBOOT_DIR |
Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | # configure_ironic() - Set config files, create data dirs, etc |
| 242 | function configure_ironic { |
| 243 | configure_ironic_dirs |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 244 | sudo chown $STACK_USER $IRONIC_CONF_DIR |
| 245 | |
| 246 | # Copy over ironic configuration file and configure common parameters. |
| 247 | cp $IRONIC_DIR/etc/ironic/ironic.conf.sample $IRONIC_CONF_FILE |
| 248 | iniset $IRONIC_CONF_FILE DEFAULT debug True |
| 249 | inicomment $IRONIC_CONF_FILE DEFAULT log_file |
| 250 | iniset $IRONIC_CONF_FILE DEFAULT sql_connection `database_connection_url ironic` |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 251 | iniset $IRONIC_CONF_FILE DEFAULT state_path $IRONIC_STATE_PATH |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 252 | iniset $IRONIC_CONF_FILE DEFAULT use_syslog $SYSLOG |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 253 | # Configure Ironic conductor, if it was enabled. |
| 254 | if is_service_enabled ir-cond; then |
| 255 | configure_ironic_conductor |
| 256 | fi |
| 257 | |
| 258 | # Configure Ironic API, if it was enabled. |
| 259 | if is_service_enabled ir-api; then |
| 260 | configure_ironic_api |
| 261 | fi |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 262 | |
Adam Gandelman | ab59293 | 2014-06-06 15:12:32 -0700 | [diff] [blame] | 263 | # Format logging |
| 264 | if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then |
| 265 | setup_colorized_logging $IRONIC_CONF_FILE DEFAULT |
| 266 | fi |
Lucas Alvares Gomes | 5851e5f | 2014-08-19 10:01:45 +0100 | [diff] [blame] | 267 | |
| 268 | if [[ "$IRONIC_IPXE_ENABLED" == "True" ]]; then |
| 269 | _config_ironic_apache_wsgi |
| 270 | fi |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | # configure_ironic_api() - Is used by configure_ironic(). Performs |
| 274 | # API specific configuration. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 275 | function configure_ironic_api { |
Roman Prykhodchenko | c48c312 | 2013-10-01 17:19:05 +0300 | [diff] [blame] | 276 | iniset $IRONIC_CONF_FILE DEFAULT auth_strategy keystone |
| 277 | iniset $IRONIC_CONF_FILE DEFAULT policy_file $IRONIC_POLICY_JSON |
Brant Knudson | 0595237 | 2014-09-19 17:22:22 -0500 | [diff] [blame] | 278 | configure_auth_token_middleware $IRONIC_CONF_FILE ironic $IRONIC_AUTH_CACHE_DIR/api |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 279 | iniset_rpc_backend ironic $IRONIC_CONF_FILE DEFAULT |
Adam Gandelman | 4b45fca | 2014-11-17 09:59:23 -0800 | [diff] [blame] | 280 | iniset $IRONIC_CONF_FILE api port $IRONIC_SERVICE_PORT |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 281 | |
| 282 | cp -p $IRONIC_DIR/etc/ironic/policy.json $IRONIC_POLICY_JSON |
| 283 | } |
| 284 | |
| 285 | # configure_ironic_conductor() - Is used by configure_ironic(). |
| 286 | # Sets conductor specific settings. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 287 | function configure_ironic_conductor { |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 288 | cp $IRONIC_DIR/etc/ironic/rootwrap.conf $IRONIC_ROOTWRAP_CONF |
Lucas Alvares Gomes | 279295c | 2014-01-14 11:37:51 +0000 | [diff] [blame] | 289 | cp -r $IRONIC_DIR/etc/ironic/rootwrap.d $IRONIC_CONF_DIR |
Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 290 | local ironic_rootwrap=$(get_rootwrap_location ironic) |
| 291 | local rootwrap_isudoer_cmd="$ironic_rootwrap $IRONIC_CONF_DIR/rootwrap.conf *" |
Adam Gandelman | 3f2a7b7 | 2014-04-14 16:14:33 -0700 | [diff] [blame] | 292 | |
| 293 | # Set up the rootwrap sudoers for ironic |
Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 294 | local tempfile=`mktemp` |
| 295 | echo "$STACK_USER ALL=(root) NOPASSWD: $rootwrap_isudoer_cmd" >$tempfile |
| 296 | chmod 0440 $tempfile |
| 297 | sudo chown root:root $tempfile |
| 298 | sudo mv $tempfile /etc/sudoers.d/ironic-rootwrap |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 299 | |
Alexander Gordeev | a67cb1a | 2014-03-04 18:38:33 +0400 | [diff] [blame] | 300 | iniset $IRONIC_CONF_FILE DEFAULT rootwrap_config $IRONIC_ROOTWRAP_CONF |
Devananda van der Veen | 83eeed0 | 2014-04-11 10:08:41 -0700 | [diff] [blame] | 301 | iniset $IRONIC_CONF_FILE DEFAULT enabled_drivers $IRONIC_ENABLED_DRIVERS |
Adam Gandelman | 4b45fca | 2014-11-17 09:59:23 -0800 | [diff] [blame] | 302 | iniset $IRONIC_CONF_FILE conductor api_url $IRONIC_SERVICE_PROTOCOL://$HOST_IP:$IRONIC_SERVICE_PORT |
yunhong jiang | ae9ee6b | 2014-10-08 07:01:02 -0700 | [diff] [blame] | 303 | iniset $IRONIC_CONF_FILE pxe tftp_server $IRONIC_TFTPSERVER_IP |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 304 | iniset $IRONIC_CONF_FILE pxe tftp_root $IRONIC_TFTPBOOT_DIR |
| 305 | 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] | 306 | if [[ "$IRONIC_VM_LOG_CONSOLE" == "True" ]] ; then |
| 307 | iniset $IRONIC_CONF_FILE pxe pxe_append_params "nofb nomodeset vga=normal console=ttyS0" |
| 308 | fi |
yunhong jiang | fe96ed6 | 2014-11-05 03:30:25 -0700 | [diff] [blame] | 309 | if is_deployed_by_agent; then |
Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 310 | if [[ "$SWIFT_ENABLE_TEMPURLS" == "True" ]] ; then |
| 311 | iniset $IRONIC_CONF_FILE glance swift_temp_url_key $SWIFT_TEMPURL_KEY |
| 312 | else |
| 313 | die $LINENO "SWIFT_ENABLE_TEMPURLS must be True to use agent_ssh driver in Ironic." |
| 314 | fi |
Jim Rollenhagen | 74b28bc | 2014-10-29 14:15:22 -0700 | [diff] [blame] | 315 | iniset $IRONIC_CONF_FILE glance swift_endpoint_url http://${HOST_IP}:${SWIFT_DEFAULT_BIND_PORT:-8080} |
Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 316 | iniset $IRONIC_CONF_FILE glance swift_api_version v1 |
Adam Gandelman | ab50c70 | 2014-10-22 13:21:22 -0700 | [diff] [blame] | 317 | local tenant_id=$(get_or_create_project $SERVICE_TENANT_NAME) |
| 318 | iniset $IRONIC_CONF_FILE glance swift_account AUTH_${tenant_id} |
Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 319 | iniset $IRONIC_CONF_FILE glance swift_container glance |
| 320 | iniset $IRONIC_CONF_FILE glance swift_temp_url_duration 3600 |
| 321 | iniset $IRONIC_CONF_FILE agent heartbeat_timeout 30 |
| 322 | if [[ "$IRONIC_VM_LOG_CONSOLE" == "True" ]] ; then |
Jay Faulkner | 7f8a27d | 2014-11-24 11:12:20 -0800 | [diff] [blame] | 323 | iniset $IRONIC_CONF_FILE agent agent_pxe_append_params "nofb nomodeset vga=normal console=ttyS0 systemd.journald.forward_to_console=yes" |
Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 324 | fi |
| 325 | fi |
Lucas Alvares Gomes | 5851e5f | 2014-08-19 10:01:45 +0100 | [diff] [blame] | 326 | |
| 327 | if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then |
| 328 | local pxebin=`basename $IRONIC_PXE_BOOT_IMAGE` |
| 329 | iniset $IRONIC_CONF_FILE pxe ipxe_enabled True |
| 330 | iniset $IRONIC_CONF_FILE pxe pxe_config_template '\$pybasedir/drivers/modules/ipxe_config.template' |
| 331 | iniset $IRONIC_CONF_FILE pxe pxe_bootfile_name $pxebin |
| 332 | iniset $IRONIC_CONF_FILE pxe http_root $IRONIC_HTTP_DIR |
| 333 | iniset $IRONIC_CONF_FILE pxe http_url "http://$IRONIC_HTTP_SERVER:$IRONIC_HTTP_PORT" |
| 334 | fi |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | # create_ironic_cache_dir() - Part of the init_ironic() process |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 338 | function create_ironic_cache_dir { |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 339 | # Create cache dir |
| 340 | sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/api |
| 341 | sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/api |
| 342 | rm -f $IRONIC_AUTH_CACHE_DIR/api/* |
| 343 | sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/registry |
| 344 | sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/registry |
| 345 | rm -f $IRONIC_AUTH_CACHE_DIR/registry/* |
| 346 | } |
| 347 | |
| 348 | # create_ironic_accounts() - Set up common required ironic accounts |
| 349 | |
| 350 | # Tenant User Roles |
| 351 | # ------------------------------------------------------------------ |
| 352 | # service ironic admin # if enabled |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 353 | function create_ironic_accounts { |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 354 | |
Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 355 | local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") |
| 356 | local admin_role=$(openstack role list | awk "/ admin / { print \$2 }") |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 357 | |
| 358 | # Ironic |
| 359 | if [[ "$ENABLED_SERVICES" =~ "ir-api" ]]; then |
Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 360 | # Get ironic user if exists |
| 361 | |
Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 362 | local ironic_user=$(get_or_create_user "ironic" \ |
| 363 | "$SERVICE_PASSWORD" $service_tenant) |
| 364 | get_or_add_user_role $admin_role $ironic_user $service_tenant |
Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 365 | |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 366 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 367 | |
Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 368 | local ironic_service=$(get_or_create_service "ironic" \ |
Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 369 | "baremetal" "Ironic baremetal provisioning service") |
Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 370 | get_or_create_endpoint $ironic_service \ |
Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 371 | "$REGION_NAME" \ |
| 372 | "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \ |
| 373 | "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \ |
| 374 | "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 375 | fi |
| 376 | fi |
| 377 | } |
| 378 | |
| 379 | |
| 380 | # init_ironic() - Initialize databases, etc. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 381 | function init_ironic { |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 382 | # (Re)create ironic database |
| 383 | recreate_database ironic utf8 |
| 384 | |
| 385 | # Migrate ironic database |
Dmitry Tantsur | 0c6a654 | 2014-06-02 20:19:33 +0200 | [diff] [blame] | 386 | $IRONIC_BIN_DIR/ironic-dbsync --config-file=$IRONIC_CONF_FILE |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 387 | |
| 388 | create_ironic_cache_dir |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 389 | } |
| 390 | |
Adam Gandelman | 22ec45e | 2014-10-16 17:41:22 -0700 | [diff] [blame] | 391 | # _ironic_bm_vm_names() - Generates list of names for baremetal VMs. |
| 392 | function _ironic_bm_vm_names { |
| 393 | local idx |
| 394 | local num_vms=$(($IRONIC_VM_COUNT - 1)) |
| 395 | for idx in $(seq 0 $num_vms); do |
| 396 | echo "baremetal${IRONIC_VM_NETWORK_BRIDGE}_${idx}" |
| 397 | done |
| 398 | } |
| 399 | |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 400 | # start_ironic() - Start running processes, including screen |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 401 | function start_ironic { |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 402 | # Start Ironic API server, if enabled. |
| 403 | if is_service_enabled ir-api; then |
| 404 | start_ironic_api |
| 405 | fi |
| 406 | |
| 407 | # Start Ironic conductor, if enabled. |
| 408 | if is_service_enabled ir-cond; then |
| 409 | start_ironic_conductor |
| 410 | fi |
Lucas Alvares Gomes | 5851e5f | 2014-08-19 10:01:45 +0100 | [diff] [blame] | 411 | |
| 412 | # Start Apache if iPXE is enabled |
| 413 | if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then |
| 414 | restart_apache_server |
| 415 | fi |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | # start_ironic_api() - Used by start_ironic(). |
| 419 | # Starts Ironic API server. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 420 | function start_ironic_api { |
Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 421 | run_process ir-api "$IRONIC_BIN_DIR/ironic-api --config-file=$IRONIC_CONF_FILE" |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 422 | echo "Waiting for ir-api ($IRONIC_HOSTPORT) to start..." |
Adam Gandelman | 4b45fca | 2014-11-17 09:59:23 -0800 | [diff] [blame] | 423 | if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q -O- $IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT; do sleep 1; done"; then |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 424 | die $LINENO "ir-api did not start" |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 425 | fi |
| 426 | } |
| 427 | |
| 428 | # start_ironic_conductor() - Used by start_ironic(). |
| 429 | # Starts Ironic conductor. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 430 | function start_ironic_conductor { |
Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 431 | run_process ir-cond "$IRONIC_BIN_DIR/ironic-conductor --config-file=$IRONIC_CONF_FILE" |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 432 | # TODO(romcheg): Find a way to check whether the conductor has started. |
| 433 | } |
| 434 | |
| 435 | # stop_ironic() - Stop running processes |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 436 | function stop_ironic { |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 437 | # Kill the Ironic screen windows |
| 438 | screen -S $SCREEN_NAME -p ir-api -X kill |
| 439 | screen -S $SCREEN_NAME -p ir-cond -X kill |
Lucas Alvares Gomes | 5851e5f | 2014-08-19 10:01:45 +0100 | [diff] [blame] | 440 | |
| 441 | # Cleanup the WSGI files |
| 442 | if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then |
| 443 | _cleanup_ironic_apache_wsgi |
| 444 | fi |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 445 | } |
| 446 | |
Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 447 | function create_ovs_taps { |
| 448 | local ironic_net_id=$(neutron net-list | grep private | get_field 1) |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 449 | |
Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 450 | # Work around: No netns exists on host until a Neutron port is created. We |
| 451 | # need to create one in Neutron to know what netns to tap into prior to the |
| 452 | # first node booting. |
| 453 | local port_id=$(neutron port-create private | grep " id " | get_field 2) |
| 454 | |
| 455 | # intentional sleep to make sure the tag has been set to port |
| 456 | sleep 10 |
| 457 | |
Adam Gandelman | 9bc3459 | 2014-12-02 16:49:14 -0800 | [diff] [blame] | 458 | local tapdev=$(sudo ip netns exec qdhcp-${ironic_net_id} ip link list | grep " tap" | cut -d':' -f2 | cut -b2-) |
Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 459 | local tag_id=$(sudo ovs-vsctl show |grep ${tapdev} -A1 -m1 | grep tag | cut -d':' -f2 | cut -b2-) |
| 460 | |
| 461 | # make sure veth pair is not existing, otherwise delete its links |
| 462 | sudo ip link show ovs-tap1 && sudo ip link delete ovs-tap1 |
| 463 | sudo ip link show brbm-tap1 && sudo ip link delete brbm-tap1 |
| 464 | # create veth pair for future interconnection between br-int and brbm |
| 465 | sudo ip link add brbm-tap1 type veth peer name ovs-tap1 |
| 466 | sudo ip link set dev brbm-tap1 up |
| 467 | sudo ip link set dev ovs-tap1 up |
| 468 | |
| 469 | sudo ovs-vsctl -- --if-exists del-port ovs-tap1 -- add-port br-int ovs-tap1 tag=$tag_id |
| 470 | sudo ovs-vsctl -- --if-exists del-port brbm-tap1 -- add-port $IRONIC_VM_NETWORK_BRIDGE brbm-tap1 |
| 471 | |
| 472 | # Remove the port needed only for workaround. |
| 473 | neutron port-delete $port_id |
Adam Gandelman | cec9792 | 2014-07-29 18:43:18 -0700 | [diff] [blame] | 474 | |
| 475 | # Finally, share the fixed tenant network across all tenants. This allows the host |
| 476 | # to serve TFTP to a single network namespace via the tap device created above. |
| 477 | neutron net-update $ironic_net_id --shared true |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 478 | } |
| 479 | |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 480 | function create_bridge_and_vms { |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 481 | # Call libvirt setup scripts in a new shell to ensure any new group membership |
| 482 | sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/setup-network" |
Adam Gandelman | 8af6fae | 2014-04-11 17:06:14 -0700 | [diff] [blame] | 483 | if [[ "$IRONIC_VM_LOG_CONSOLE" == "True" ]] ; then |
Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 484 | local log_arg="$IRONIC_VM_LOG_DIR" |
Adam Gandelman | 8af6fae | 2014-04-11 17:06:14 -0700 | [diff] [blame] | 485 | else |
Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 486 | local log_arg="" |
Adam Gandelman | 8af6fae | 2014-04-11 17:06:14 -0700 | [diff] [blame] | 487 | fi |
Adam Gandelman | 22ec45e | 2014-10-16 17:41:22 -0700 | [diff] [blame] | 488 | local vm_name |
| 489 | for vm_name in $(_ironic_bm_vm_names); do |
| 490 | sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/create-node $vm_name \ |
| 491 | $IRONIC_VM_SPECS_CPU $IRONIC_VM_SPECS_RAM $IRONIC_VM_SPECS_DISK \ |
| 492 | amd64 $IRONIC_VM_NETWORK_BRIDGE $IRONIC_VM_EMULATOR \ |
| 493 | $log_arg" >> $IRONIC_VM_MACS_CSV_FILE |
| 494 | done |
Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 495 | create_ovs_taps |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 496 | } |
| 497 | |
Adam Gandelman | c78e467 | 2014-12-01 11:24:37 -0800 | [diff] [blame] | 498 | function wait_for_nova_resources { |
Adam Gandelman | 0c99e2f | 2014-12-09 14:44:24 -0800 | [diff] [blame] | 499 | # After nodes have been enrolled, we need to wait for both ironic and |
| 500 | # nova's periodic tasks to populate the resource tracker with available |
| 501 | # nodes and resources. Wait up to 2 minutes for a given resource before |
| 502 | # timing out. |
| 503 | local resource=$1 |
| 504 | local expected_count=$2 |
| 505 | echo_summary "Waiting 2 minutes for Nova resource tracker to pick up $resource >= $expected_count" |
Adam Gandelman | c78e467 | 2014-12-01 11:24:37 -0800 | [diff] [blame] | 506 | for i in $(seq 1 120); do |
Adam Gandelman | 0c99e2f | 2014-12-09 14:44:24 -0800 | [diff] [blame] | 507 | if [ $(nova hypervisor-stats | grep " $resource " | get_field 2) -ge $expected_count ]; then |
Adam Gandelman | c78e467 | 2014-12-01 11:24:37 -0800 | [diff] [blame] | 508 | return 0 |
| 509 | fi |
| 510 | sleep 1 |
| 511 | done |
Adam Gandelman | 0c99e2f | 2014-12-09 14:44:24 -0800 | [diff] [blame] | 512 | die $LINENO "Timed out waiting for Nova hypervisor-stats $resource >= $expected_count" |
Adam Gandelman | c78e467 | 2014-12-01 11:24:37 -0800 | [diff] [blame] | 513 | } |
| 514 | |
yunhong jiang | ae9ee6b | 2014-10-08 07:01:02 -0700 | [diff] [blame] | 515 | function enroll_nodes { |
Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 516 | local chassis_id=$(ironic chassis-create -d "ironic test chassis" | grep " uuid " | get_field 2) |
Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 517 | |
| 518 | if [[ "$IRONIC_DEPLOY_DRIVER" == "pxe_ssh" ]] ; then |
| 519 | local _IRONIC_DEPLOY_KERNEL_KEY=pxe_deploy_kernel |
| 520 | local _IRONIC_DEPLOY_RAMDISK_KEY=pxe_deploy_ramdisk |
yunhong jiang | fe96ed6 | 2014-11-05 03:30:25 -0700 | [diff] [blame] | 521 | elif is_deployed_by_agent; then |
Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 522 | local _IRONIC_DEPLOY_KERNEL_KEY=deploy_kernel |
| 523 | local _IRONIC_DEPLOY_RAMDISK_KEY=deploy_ramdisk |
| 524 | fi |
| 525 | |
yunhong jiang | ae9ee6b | 2014-10-08 07:01:02 -0700 | [diff] [blame] | 526 | if ! is_ironic_hardware; then |
| 527 | local ironic_node_cpu=$IRONIC_VM_SPECS_CPU |
| 528 | local ironic_node_ram=$IRONIC_VM_SPECS_RAM |
| 529 | local ironic_node_disk=$IRONIC_VM_SPECS_DISK |
| 530 | local ironic_ephemeral_disk=$IRONIC_VM_EPHEMERAL_DISK |
| 531 | local ironic_hwinfo_file=$IRONIC_VM_MACS_CSV_FILE |
| 532 | local node_options="\ |
Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 533 | -i $_IRONIC_DEPLOY_KERNEL_KEY=$IRONIC_DEPLOY_KERNEL_ID \ |
| 534 | -i $_IRONIC_DEPLOY_RAMDISK_KEY=$IRONIC_DEPLOY_RAMDISK_ID \ |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 535 | -i ssh_virt_type=$IRONIC_SSH_VIRT_TYPE \ |
| 536 | -i ssh_address=$IRONIC_VM_SSH_ADDRESS \ |
| 537 | -i ssh_port=$IRONIC_VM_SSH_PORT \ |
| 538 | -i ssh_username=$IRONIC_SSH_USERNAME \ |
Adam Gandelman | d4a6e35 | 2014-12-11 14:53:17 -0800 | [diff] [blame] | 539 | -i ssh_key_filename=$IRONIC_KEY_FILE" |
yunhong jiang | ae9ee6b | 2014-10-08 07:01:02 -0700 | [diff] [blame] | 540 | else |
| 541 | local ironic_node_cpu=$IRONIC_HW_NODE_CPU |
| 542 | local ironic_node_ram=$IRONIC_HW_NODE_RAM |
| 543 | local ironic_node_disk=$IRONIC_HW_NODE_DISK |
| 544 | local ironic_ephemeral_disk=$IRONIC_HW_EPHEMERAL_DISK |
| 545 | if [[ -z "${IRONIC_DEPLOY_DRIVER##*_ipmitool}" ]]; then |
| 546 | local ironic_hwinfo_file=$IRONIC_IPMIINFO_FILE |
| 547 | fi |
| 548 | fi |
| 549 | |
Adam Gandelman | c78e467 | 2014-12-01 11:24:37 -0800 | [diff] [blame] | 550 | local total_nodes=0 |
Adam Gandelman | 0c99e2f | 2014-12-09 14:44:24 -0800 | [diff] [blame] | 551 | local total_cpus=0 |
yunhong jiang | ae9ee6b | 2014-10-08 07:01:02 -0700 | [diff] [blame] | 552 | while read hardware_info; do |
| 553 | if ! is_ironic_hardware; then |
| 554 | local mac_address=$hardware_info |
| 555 | elif [[ -z "${IRONIC_DEPLOY_DRIVER##*_ipmitool}" ]]; then |
| 556 | local ipmi_address=$(echo $hardware_info |awk '{print $1}') |
| 557 | local mac_address=$(echo $hardware_info |awk '{print $2}') |
| 558 | local ironic_ipmi_username=$(echo $hardware_info |awk '{print $3}') |
| 559 | local ironic_ipmi_passwd=$(echo $hardware_info |awk '{print $4}') |
| 560 | # Currently we require all hardware platform have same CPU/RAM/DISK info |
| 561 | # in future, this can be enhanced to support different type, and then |
| 562 | # we create the bare metal flavor with minimum value |
| 563 | local node_options="-i ipmi_address=$ipmi_address -i ipmi_password=$ironic_ipmi_passwd\ |
| 564 | -i ipmi_username=$ironic_ipmi_username" |
Yuiko Takada | b7d5bf6 | 2014-11-20 18:23:06 +0900 | [diff] [blame] | 565 | node_options+=" -i $_IRONIC_DEPLOY_KERNEL_KEY=$IRONIC_DEPLOY_KERNEL_ID" |
| 566 | node_options+=" -i $_IRONIC_DEPLOY_RAMDISK_KEY=$IRONIC_DEPLOY_RAMDISK_ID" |
yunhong jiang | ae9ee6b | 2014-10-08 07:01:02 -0700 | [diff] [blame] | 567 | fi |
| 568 | |
| 569 | local node_id=$(ironic node-create --chassis_uuid $chassis_id \ |
| 570 | --driver $IRONIC_DEPLOY_DRIVER \ |
| 571 | -p cpus=$ironic_node_cpu\ |
| 572 | -p memory_mb=$ironic_node_ram\ |
| 573 | -p local_gb=$ironic_node_disk\ |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 574 | -p cpu_arch=x86_64 \ |
yunhong jiang | ae9ee6b | 2014-10-08 07:01:02 -0700 | [diff] [blame] | 575 | $node_options \ |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 576 | | grep " uuid " | get_field 2) |
| 577 | |
yunhong jiang | ae9ee6b | 2014-10-08 07:01:02 -0700 | [diff] [blame] | 578 | ironic port-create --address $mac_address --node_uuid $node_id |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 579 | |
Adam Gandelman | c78e467 | 2014-12-01 11:24:37 -0800 | [diff] [blame] | 580 | total_nodes=$((total_nodes+1)) |
Adam Gandelman | 0c99e2f | 2014-12-09 14:44:24 -0800 | [diff] [blame] | 581 | total_cpus=$((total_cpus+$ironic_node_cpu)) |
yunhong jiang | ae9ee6b | 2014-10-08 07:01:02 -0700 | [diff] [blame] | 582 | done < $ironic_hwinfo_file |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 583 | |
| 584 | # create the nova flavor |
Adam Gandelman | 29c3d63 | 2014-07-17 12:53:21 -0700 | [diff] [blame] | 585 | # NOTE(adam_g): Attempting to use an autogenerated UUID for flavor id here uncovered |
| 586 | # bug (LP: #1333852) in Trove. This can be changed to use an auto flavor id when the |
| 587 | # bug is fixed in Juno. |
yunhong jiang | ae9ee6b | 2014-10-08 07:01:02 -0700 | [diff] [blame] | 588 | local adjusted_disk=$(($ironic_node_disk - $ironic_ephemeral_disk)) |
| 589 | nova flavor-create --ephemeral $ironic_ephemeral_disk baremetal 551 $ironic_node_ram $adjusted_disk $ironic_node_cpu |
Adam Gandelman | 29c3d63 | 2014-07-17 12:53:21 -0700 | [diff] [blame] | 590 | |
Yuiko Takada | b7d5bf6 | 2014-11-20 18:23:06 +0900 | [diff] [blame] | 591 | nova flavor-key baremetal set "cpu_arch"="x86_64" |
Adam Gandelman | c78e467 | 2014-12-01 11:24:37 -0800 | [diff] [blame] | 592 | |
| 593 | if [ "$VIRT_DRIVER" == "ironic" ]; then |
Adam Gandelman | 0c99e2f | 2014-12-09 14:44:24 -0800 | [diff] [blame] | 594 | wait_for_nova_resources "count" $total_nodes |
| 595 | wait_for_nova_resources "vcpus" $total_cpus |
Adam Gandelman | c78e467 | 2014-12-01 11:24:37 -0800 | [diff] [blame] | 596 | fi |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 597 | } |
| 598 | |
Adam Gandelman | c1f0db2 | 2014-04-14 13:21:22 -0700 | [diff] [blame] | 599 | function configure_iptables { |
| 600 | # enable tftp natting for allowing connections to HOST_IP's tftp server |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 601 | sudo modprobe nf_conntrack_tftp |
| 602 | sudo modprobe nf_nat_tftp |
Adam Gandelman | c1f0db2 | 2014-04-14 13:21:22 -0700 | [diff] [blame] | 603 | # nodes boot from TFTP and callback to the API server listening on $HOST_IP |
| 604 | sudo iptables -I INPUT -d $HOST_IP -p udp --dport 69 -j ACCEPT || true |
Adam Gandelman | 4b45fca | 2014-11-17 09:59:23 -0800 | [diff] [blame] | 605 | sudo iptables -I INPUT -d $HOST_IP -p tcp --dport $IRONIC_SERVICE_PORT -j ACCEPT || true |
yunhong jiang | fe96ed6 | 2014-11-05 03:30:25 -0700 | [diff] [blame] | 606 | if is_deployed_by_agent; then |
Jim Rollenhagen | 74b28bc | 2014-10-29 14:15:22 -0700 | [diff] [blame] | 607 | # agent ramdisk gets instance image from swift |
| 608 | sudo iptables -I INPUT -d $HOST_IP -p tcp --dport ${SWIFT_DEFAULT_BIND_PORT:-8080} -j ACCEPT || true |
| 609 | fi |
Adam Gandelman | c1f0db2 | 2014-04-14 13:21:22 -0700 | [diff] [blame] | 610 | } |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 611 | |
Adam Gandelman | c1f0db2 | 2014-04-14 13:21:22 -0700 | [diff] [blame] | 612 | function configure_tftpd { |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 613 | # stop tftpd and setup serving via xinetd |
| 614 | stop_service tftpd-hpa || true |
| 615 | [ -f /etc/init/tftpd-hpa.conf ] && echo "manual" | sudo tee /etc/init/tftpd-hpa.override |
| 616 | sudo cp $IRONIC_TEMPLATES_DIR/tftpd-xinetd.template /etc/xinetd.d/tftp |
| 617 | sudo sed -e "s|%TFTPBOOT_DIR%|$IRONIC_TFTPBOOT_DIR|g" -i /etc/xinetd.d/tftp |
| 618 | |
| 619 | # setup tftp file mapping to satisfy requests at the root (booting) and |
| 620 | # /tftpboot/ sub-dir (as per deploy-ironic elements) |
| 621 | echo "r ^([^/]) $IRONIC_TFTPBOOT_DIR/\1" >$IRONIC_TFTPBOOT_DIR/map-file |
| 622 | echo "r ^(/tftpboot/) $IRONIC_TFTPBOOT_DIR/\2" >>$IRONIC_TFTPBOOT_DIR/map-file |
| 623 | |
| 624 | chmod -R 0755 $IRONIC_TFTPBOOT_DIR |
| 625 | restart_service xinetd |
| 626 | } |
| 627 | |
| 628 | function configure_ironic_ssh_keypair { |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 629 | if [[ ! -d $HOME/.ssh ]]; then |
| 630 | mkdir -p $HOME/.ssh |
| 631 | chmod 700 $HOME/.ssh |
| 632 | fi |
Adam Gandelman | 6c74932 | 2014-12-02 16:20:50 -0800 | [diff] [blame] | 633 | if [[ ! -e $IRONIC_KEY_FILE ]]; then |
| 634 | if [[ ! -d $(dirname $IRONIC_KEY_FILE) ]]; then |
| 635 | mkdir -p $(dirname $IRONIC_KEY_FILE) |
| 636 | fi |
| 637 | echo -e 'n\n' | ssh-keygen -q -t rsa -P '' -f $IRONIC_KEY_FILE |
| 638 | fi |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 639 | cat $IRONIC_KEY_FILE.pub | tee -a $IRONIC_AUTHORIZED_KEYS_FILE |
| 640 | } |
| 641 | |
| 642 | function ironic_ssh_check { |
Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 643 | local key_file=$1 |
| 644 | local floating_ip=$2 |
| 645 | local port=$3 |
| 646 | local default_instance_user=$4 |
| 647 | local active_timeout=$5 |
| 648 | 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] | 649 | die $LINENO "server didn't become ssh-able!" |
| 650 | fi |
| 651 | } |
| 652 | |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 653 | function configure_ironic_auxiliary { |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 654 | configure_ironic_ssh_keypair |
Adam Gandelman | 6c74932 | 2014-12-02 16:20:50 -0800 | [diff] [blame] | 655 | ironic_ssh_check $IRONIC_KEY_FILE $IRONIC_VM_SSH_ADDRESS $IRONIC_VM_SSH_PORT $IRONIC_SSH_USERNAME 10 |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 656 | } |
| 657 | |
Jim Rollenhagen | f00766b | 2014-08-15 01:08:11 +0000 | [diff] [blame] | 658 | function build_ipa_coreos_ramdisk { |
| 659 | echo "Building ironic-python-agent deploy ramdisk" |
| 660 | local kernel_path=$1 |
| 661 | local ramdisk_path=$2 |
| 662 | git_clone $IRONIC_PYTHON_AGENT_REPO $IRONIC_PYTHON_AGENT_DIR $IRONIC_PYTHON_AGENT_BRANCH |
| 663 | cd $IRONIC_PYTHON_AGENT_DIR |
| 664 | imagebuild/coreos/build_coreos_image.sh |
| 665 | cp imagebuild/coreos/UPLOAD/coreos_production_pxe_image-oem.cpio.gz $ramdisk_path |
| 666 | cp imagebuild/coreos/UPLOAD/coreos_production_pxe.vmlinuz $kernel_path |
| 667 | sudo rm -rf UPLOAD |
| 668 | cd - |
| 669 | } |
| 670 | |
Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 671 | # build deploy kernel+ramdisk, then upload them to glance |
Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 672 | # this function sets ``IRONIC_DEPLOY_KERNEL_ID``, ``IRONIC_DEPLOY_RAMDISK_ID`` |
Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 673 | function upload_baremetal_ironic_deploy { |
Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 674 | declare -g IRONIC_DEPLOY_KERNEL_ID IRONIC_DEPLOY_RAMDISK_ID |
Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 675 | echo_summary "Creating and uploading baremetal images for ironic" |
| 676 | |
| 677 | # install diskimage-builder |
Steve Baker | cbfb3ae | 2014-05-05 16:06:47 +1200 | [diff] [blame] | 678 | if [[ $(type -P ramdisk-image-create) == "" ]]; then |
| 679 | pip_install diskimage_builder |
| 680 | fi |
Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 681 | |
| 682 | if [ -z "$IRONIC_DEPLOY_KERNEL" -o -z "$IRONIC_DEPLOY_RAMDISK" ]; then |
yunhong jiang | fe96ed6 | 2014-11-05 03:30:25 -0700 | [diff] [blame] | 683 | local IRONIC_DEPLOY_KERNEL_PATH=$TOP_DIR/files/ir-deploy-$IRONIC_DEPLOY_DRIVER.kernel |
| 684 | local IRONIC_DEPLOY_RAMDISK_PATH=$TOP_DIR/files/ir-deploy-$IRONIC_DEPLOY_DRIVER.initramfs |
Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 685 | else |
Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 686 | local IRONIC_DEPLOY_KERNEL_PATH=$IRONIC_DEPLOY_KERNEL |
| 687 | local IRONIC_DEPLOY_RAMDISK_PATH=$IRONIC_DEPLOY_RAMDISK |
Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 688 | fi |
| 689 | |
| 690 | if [ ! -e "$IRONIC_DEPLOY_RAMDISK_PATH" -o ! -e "$IRONIC_DEPLOY_KERNEL_PATH" ]; then |
| 691 | # files don't exist, need to build them |
| 692 | if [ "$IRONIC_BUILD_DEPLOY_RAMDISK" = "True" ]; then |
| 693 | # we can build them only if we're not offline |
| 694 | if [ "$OFFLINE" != "True" ]; then |
yunhong jiang | fe96ed6 | 2014-11-05 03:30:25 -0700 | [diff] [blame] | 695 | if is_deployed_by_agent; then |
Jim Rollenhagen | f00766b | 2014-08-15 01:08:11 +0000 | [diff] [blame] | 696 | build_ipa_coreos_ramdisk $IRONIC_DEPLOY_KERNEL_PATH $IRONIC_DEPLOY_RAMDISK_PATH |
Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 697 | else |
Steve Baker | cbfb3ae | 2014-05-05 16:06:47 +1200 | [diff] [blame] | 698 | ramdisk-image-create $IRONIC_DEPLOY_FLAVOR \ |
yunhong jiang | fe96ed6 | 2014-11-05 03:30:25 -0700 | [diff] [blame] | 699 | -o $TOP_DIR/files/ir-deploy-$IRONIC_DEPLOY_DRIVER |
Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 700 | fi |
Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 701 | else |
| 702 | die $LINENO "Deploy kernel+ramdisk files don't exist and cannot be build in OFFLINE mode" |
| 703 | fi |
| 704 | else |
yunhong jiang | fe96ed6 | 2014-11-05 03:30:25 -0700 | [diff] [blame] | 705 | if is_deployed_by_agent; then |
Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 706 | # download the agent image tarball |
Jim Rollenhagen | 792dc5f | 2014-08-27 17:03:00 -0700 | [diff] [blame] | 707 | wget "$IRONIC_AGENT_KERNEL_URL" -O $IRONIC_DEPLOY_KERNEL_PATH |
| 708 | wget "$IRONIC_AGENT_RAMDISK_URL" -O $IRONIC_DEPLOY_RAMDISK_PATH |
Jim Rollenhagen | a6a4546 | 2014-08-05 18:08:29 +0000 | [diff] [blame] | 709 | else |
| 710 | die $LINENO "Deploy kernel+ramdisk files don't exist and their building was disabled explicitly by IRONIC_BUILD_DEPLOY_RAMDISK" |
| 711 | fi |
Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 712 | fi |
| 713 | fi |
| 714 | |
Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 715 | local token=$(keystone token-get | grep ' id ' | get_field 2) |
| 716 | die_if_not_set $LINENO token "Keystone fail to get token" |
| 717 | |
Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 718 | # load them into glance |
Steve Martinelli | 8d3ac2d | 2014-08-02 23:47:15 -0400 | [diff] [blame] | 719 | IRONIC_DEPLOY_KERNEL_ID=$(openstack \ |
| 720 | --os-token $token \ |
| 721 | --os-url http://$GLANCE_HOSTPORT \ |
| 722 | image create \ |
| 723 | $(basename $IRONIC_DEPLOY_KERNEL_PATH) \ |
| 724 | --public --disk-format=aki \ |
Jim Rollenhagen | 722284f | 2014-08-15 18:04:02 +0000 | [diff] [blame] | 725 | --container-format=aki \ |
Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 726 | < $IRONIC_DEPLOY_KERNEL_PATH | grep ' id ' | get_field 2) |
Steve Martinelli | 8d3ac2d | 2014-08-02 23:47:15 -0400 | [diff] [blame] | 727 | IRONIC_DEPLOY_RAMDISK_ID=$(openstack \ |
| 728 | --os-token $token \ |
| 729 | --os-url http://$GLANCE_HOSTPORT \ |
| 730 | image create \ |
| 731 | $(basename $IRONIC_DEPLOY_RAMDISK_PATH) \ |
| 732 | --public --disk-format=ari \ |
Jim Rollenhagen | 722284f | 2014-08-15 18:04:02 +0000 | [diff] [blame] | 733 | --container-format=ari \ |
Alexander Gordeev | f177f72 | 2014-03-14 18:44:48 +0400 | [diff] [blame] | 734 | < $IRONIC_DEPLOY_RAMDISK_PATH | grep ' id ' | get_field 2) |
| 735 | } |
| 736 | |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 737 | function prepare_baremetal_basic_ops { |
Adam Gandelman | 0354640 | 2014-12-05 16:49:12 -0800 | [diff] [blame] | 738 | if ! is_ironic_hardware; then |
| 739 | configure_ironic_auxiliary |
| 740 | fi |
Adam Gandelman | 6d27148 | 2014-08-05 18:12:29 -0700 | [diff] [blame] | 741 | upload_baremetal_ironic_deploy |
yunhong jiang | ae9ee6b | 2014-10-08 07:01:02 -0700 | [diff] [blame] | 742 | if ! is_ironic_hardware; then |
| 743 | create_bridge_and_vms |
| 744 | fi |
| 745 | enroll_nodes |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 746 | configure_tftpd |
Adam Gandelman | c1f0db2 | 2014-04-14 13:21:22 -0700 | [diff] [blame] | 747 | configure_iptables |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | function cleanup_baremetal_basic_ops { |
| 751 | rm -f $IRONIC_VM_MACS_CSV_FILE |
| 752 | if [ -f $IRONIC_KEY_FILE ]; then |
Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 753 | local key=$(cat $IRONIC_KEY_FILE.pub) |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 754 | # remove public key from authorized_keys |
Dean Troyer | b52caa3 | 2014-07-25 13:04:13 -0500 | [diff] [blame] | 755 | 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] | 756 | chmod 0600 $IRONIC_AUTHORIZED_KEYS_FILE |
| 757 | fi |
| 758 | sudo rm -rf $IRONIC_DATA_DIR $IRONIC_STATE_PATH |
Adam Gandelman | 22ec45e | 2014-10-16 17:41:22 -0700 | [diff] [blame] | 759 | |
| 760 | local vm_name |
| 761 | for vm_name in $(_ironic_bm_vm_names); do |
| 762 | sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/cleanup-node $vm_name $IRONIC_VM_NETWORK_BRIDGE" |
| 763 | done |
| 764 | |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 765 | sudo rm -rf /etc/xinetd.d/tftp /etc/init/tftpd-hpa.override |
| 766 | restart_service xinetd |
Adam Gandelman | c1f0db2 | 2014-04-14 13:21:22 -0700 | [diff] [blame] | 767 | sudo iptables -D INPUT -d $HOST_IP -p udp --dport 69 -j ACCEPT || true |
Adam Gandelman | 4b45fca | 2014-11-17 09:59:23 -0800 | [diff] [blame] | 768 | sudo iptables -D INPUT -d $HOST_IP -p tcp --dport $IRONIC_SERVICE_PORT -j ACCEPT || true |
yunhong jiang | fe96ed6 | 2014-11-05 03:30:25 -0700 | [diff] [blame] | 769 | if is_deployed_by_agent; then |
Jim Rollenhagen | 74b28bc | 2014-10-29 14:15:22 -0700 | [diff] [blame] | 770 | # agent ramdisk gets instance image from swift |
| 771 | sudo iptables -D INPUT -d $HOST_IP -p tcp --dport ${SWIFT_DEFAULT_BIND_PORT:-8080} -j ACCEPT || true |
| 772 | fi |
Adam Gandelman | c1f0db2 | 2014-04-14 13:21:22 -0700 | [diff] [blame] | 773 | sudo rmmod nf_conntrack_tftp || true |
| 774 | sudo rmmod nf_nat_tftp || true |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | # Restore xtrace + pipefail |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 778 | $XTRACE |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 779 | $PIPEFAIL |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 780 | |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 781 | # Tell emacs to use shell-script-mode |
| 782 | ## Local variables: |
| 783 | ## mode: shell-script |
| 784 | ## End: |