Merge "Remove deprecated deploy-ironic element" into feature/v2
This commit is contained in:
commit
1d3d59470a
@ -1,9 +0,0 @@
|
|||||||
=============
|
|
||||||
deploy-ironic
|
|
||||||
=============
|
|
||||||
A ramdisk that will expose the machine primary disk over iSCSI and reboot
|
|
||||||
once Ironic signals it is finished.
|
|
||||||
|
|
||||||
.. warning::
|
|
||||||
This element is deprecated. Please use the ironic-agent element
|
|
||||||
instead.
|
|
@ -1,3 +0,0 @@
|
|||||||
curl
|
|
||||||
partprobe
|
|
||||||
lsblk
|
|
@ -1 +0,0 @@
|
|||||||
package-installs
|
|
@ -1 +0,0 @@
|
|||||||
deploy
|
|
@ -1,138 +0,0 @@
|
|||||||
CHECK_SIZE=false
|
|
||||||
CHECK_MODEL=false
|
|
||||||
CHECK_VENDOR=false
|
|
||||||
CHECK_UUID=false
|
|
||||||
CHECK_WWN=false
|
|
||||||
CHECK_HCTL=false
|
|
||||||
CHECK_SERIAL=false
|
|
||||||
|
|
||||||
|
|
||||||
# URL/Percent decode a text
|
|
||||||
function urldecode() {
|
|
||||||
local encoded="${1//+/ }"
|
|
||||||
printf '%b' "${encoded//%/\x}"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Lowercase and url decode the values
|
|
||||||
function normalize() {
|
|
||||||
echo `urldecode "${1,,}"`
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function _exec_lsblk() {
|
|
||||||
lsblk -Pbio $2 /dev/$1 | head -n 1 | grep -Po "(?<=^$2=).*" | tr "\"" " "
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function _exec_scsi_id() {
|
|
||||||
/lib/udev/scsi_id --whitelisted --export -d $1 | grep $2 | cut -d "=" -f 2
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Get the block device size in GiB
|
|
||||||
function get_size() {
|
|
||||||
echo $(( (512 * $(cat /sys/block/$1/size) ) / 2**30))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function get_model() {
|
|
||||||
local file
|
|
||||||
file=/sys/block/$1/device/model
|
|
||||||
if [ -f $file ]; then
|
|
||||||
normalize "$(cat $file)"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function get_vendor() {
|
|
||||||
local file
|
|
||||||
file=/sys/block/$1/device/vendor
|
|
||||||
if [ -f $file ]; then
|
|
||||||
normalize "$(cat $file)"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function get_wwn() {
|
|
||||||
normalize "$(_exec_lsblk "$1" WWN)"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function get_wwn_with_extension() {
|
|
||||||
normalize "$(_exec_scsi_id "$1" ID_WWN_WITH_EXTENSION)"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function get_wwn_vendor_extension() {
|
|
||||||
normalize "$(_exec_scsi_id "$1" ID_WWN_VENDOR_EXTENSION)"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function get_serial() {
|
|
||||||
normalize "$(_exec_lsblk "$1" SERIAL)"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Parse all the hints from the Kernel cmdline and set the CHECK_*
|
|
||||||
# variables
|
|
||||||
function parse_hints() {
|
|
||||||
IFS=',' read -ra H <<< "$ROOT_DEVICE"
|
|
||||||
for i in "${H[@]}"; do
|
|
||||||
case "$i" in
|
|
||||||
size=*)
|
|
||||||
CHECK_SIZE="${i#size=}"
|
|
||||||
;;
|
|
||||||
model=*)
|
|
||||||
CHECK_MODEL=`normalize "${i#model=}"`
|
|
||||||
;;
|
|
||||||
vendor=*)
|
|
||||||
CHECK_VENDOR=`normalize "${i#vendor=}"`
|
|
||||||
;;
|
|
||||||
wwn=*)
|
|
||||||
CHECK_WWN=`normalize "${i#wwn=}"`
|
|
||||||
;;
|
|
||||||
wwn_with_extension=*)
|
|
||||||
CHECK_WWN_WITH_EXT=`normalize "${i#wwn_with_extension=}"`
|
|
||||||
;;
|
|
||||||
wwn_vendor_extension=*)
|
|
||||||
CHECK_WWN_VENDOR_EXT=`normalize "${i#wwn_vendor_extension=}"`
|
|
||||||
;;
|
|
||||||
serial=*)
|
|
||||||
CHECK_SERIAL=`normalize "${i#serial=}"`
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function get_root_device() {
|
|
||||||
# Parse the hints
|
|
||||||
parse_hints
|
|
||||||
|
|
||||||
for DEV in /sys/block/* ; do
|
|
||||||
DEV_NAME=${DEV##*/}
|
|
||||||
DEV_PATH=/dev/$DEV_NAME
|
|
||||||
|
|
||||||
# Ignore loop and ram devices
|
|
||||||
[[ $DEV_NAME = *loop* || $DEV_NAME = *ram* ]] && continue || :
|
|
||||||
|
|
||||||
# Find out if it's a CDROM
|
|
||||||
TYPE=/sys/block/$DEV_NAME/device/type
|
|
||||||
[[ -f $TYPE ]] && (( $(cat "$TYPE") == 5 )) && continue || :
|
|
||||||
|
|
||||||
[[ $CHECK_SIZE != false && $(get_size "$DEV_NAME") != $CHECK_SIZE ]] && continue || :
|
|
||||||
[[ $CHECK_MODEL != false && $(get_model "$DEV_NAME") != $CHECK_MODEL ]] && continue || :
|
|
||||||
[[ $CHECK_VENDOR != false && $(get_vendor "$DEV_NAME") != $CHECK_VENDOR ]] && continue || :
|
|
||||||
[[ $CHECK_SERIAL != false && $(get_serial "$DEV_NAME") != $CHECK_SERIAL ]] && continue || :
|
|
||||||
[[ $CHECK_WWN != false && $(get_wwn "$DEV_NAME") != $CHECK_WWN ]] && continue || :
|
|
||||||
[[ $CHECK_WWN_WITH_EXT != false && $(get_wwn_with_extension "$DEV_NAME") != $CHECK_WWN_WITH_EXT ]] && continue || :
|
|
||||||
[[ $CHECK_WWN_VENDOR_EXT != false && $(get_wwn_vendor_extension "$DEV_NAME") != $CHECK_WWN_VENDOR_EXT ]] && continue || :
|
|
||||||
|
|
||||||
# A device that matches all hints was found
|
|
||||||
echo "$DEV_PATH"
|
|
||||||
break
|
|
||||||
done
|
|
||||||
}
|
|
@ -1,174 +0,0 @@
|
|||||||
function install_bootloader {
|
|
||||||
|
|
||||||
# We need to run partprobe to ensure all partitions are visible
|
|
||||||
partprobe $target_disk
|
|
||||||
|
|
||||||
# root partition is always the last partition of the disk
|
|
||||||
readonly root_part=$(ls $target_disk* | tr " " "\n" | tail -n1)
|
|
||||||
readonly root_part_mount=/mnt/rootfs
|
|
||||||
|
|
||||||
mkdir -p $root_part_mount
|
|
||||||
mkdir -p $root_part_mount/dev
|
|
||||||
mkdir -p $root_part_mount/sys
|
|
||||||
mkdir -p $root_part_mount/proc
|
|
||||||
|
|
||||||
mount $root_part $root_part_mount 2>&1
|
|
||||||
if [ $? != "0" ]; then
|
|
||||||
echo "Failed to mount root partition $root_part on $root_part_mount"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
mount -o bind /dev $root_part_mount/dev
|
|
||||||
mount -o bind /sys $root_part_mount/sys
|
|
||||||
mount -o bind /proc $root_part_mount/proc
|
|
||||||
|
|
||||||
# If boot mode is uefi, then mount the system partition in /boot/efi.
|
|
||||||
# Grub expects the efi system partition to be mounted here.
|
|
||||||
if [ "$IRONIC_BOOT_MODE" = "uefi" ]; then
|
|
||||||
|
|
||||||
# efi system partition is labelled as "efi-part" by Ironic.
|
|
||||||
# lsblk output looks like this:
|
|
||||||
# NAME="sda1" LABEL="efi-part"
|
|
||||||
readonly efi_system_part=$(lsblk -Pio NAME,LABEL $target_disk | \
|
|
||||||
awk -F'"' '/"efi-part"/{print $2}')
|
|
||||||
readonly efi_system_part_dev_file="/dev/$efi_system_part"
|
|
||||||
readonly efi_system_part_mount="$root_part_mount/boot/efi"
|
|
||||||
mkdir -p $efi_system_part_mount
|
|
||||||
mount $efi_system_part_dev_file $efi_system_part_mount 2>&1
|
|
||||||
if [ $? != "0" ]; then
|
|
||||||
echo "Failed to mount efi system partition \
|
|
||||||
$efi_system_part_dev_file on $efi_system_part_mount"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# TODO(lucasagomes): Add extlinux as a fallback
|
|
||||||
# Find grub version
|
|
||||||
V=
|
|
||||||
if [ -x $root_part_mount/usr/sbin/grub2-install ]; then
|
|
||||||
V=2
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Install grub
|
|
||||||
ret=1
|
|
||||||
if chroot $root_part_mount /bin/bash -c "/usr/sbin/grub$V-install ${target_disk}"; then
|
|
||||||
echo "Generating the grub configuration file"
|
|
||||||
|
|
||||||
# tell GRUB2 to preload its "lvm" module to gain LVM booting on direct-attached disks
|
|
||||||
if [ "$V" = "2" ]; then
|
|
||||||
echo "GRUB_PRELOAD_MODULES=lvm" >> $root_part_mount/etc/default/grub
|
|
||||||
fi
|
|
||||||
|
|
||||||
chroot $root_part_mount /bin/bash -c "/usr/sbin/grub$V-mkconfig -o /boot/grub$V/grub.cfg"
|
|
||||||
ret=$?
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If we had mounted efi system partition, umount it.
|
|
||||||
if [ "$IRONIC_BOOT_MODE" = "uefi" ]; then
|
|
||||||
umount $efi_system_part_mount
|
|
||||||
fi
|
|
||||||
|
|
||||||
umount $root_part_mount/dev
|
|
||||||
umount $root_part_mount/sys
|
|
||||||
umount $root_part_mount/proc
|
|
||||||
umount $root_part_mount
|
|
||||||
|
|
||||||
if [ $ret != "0" ]; then
|
|
||||||
echo "Installing grub bootloader failed"
|
|
||||||
fi
|
|
||||||
return $ret
|
|
||||||
}
|
|
||||||
|
|
||||||
function do_vendor_passthru_and_wait {
|
|
||||||
|
|
||||||
local data=$1
|
|
||||||
local vendor_passthru_name=$2
|
|
||||||
|
|
||||||
eval curl -i -X POST \
|
|
||||||
"$TOKEN_HEADER" \
|
|
||||||
"-H 'Accept: application/json'" \
|
|
||||||
"-H 'Content-Type: application/json'" \
|
|
||||||
-d "$data" \
|
|
||||||
"$IRONIC_API_URL/v1/nodes/$DEPLOYMENT_ID/vendor_passthru/$vendor_passthru_name"
|
|
||||||
|
|
||||||
echo "Waiting for notice of complete"
|
|
||||||
nc -l -p 10000
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
readonly IRONIC_API_URL=$(get_kernel_parameter ironic_api_url)
|
|
||||||
readonly IRONIC_BOOT_OPTION=$(get_kernel_parameter boot_option)
|
|
||||||
readonly IRONIC_BOOT_MODE=$(get_kernel_parameter boot_mode)
|
|
||||||
readonly ROOT_DEVICE=$(get_kernel_parameter root_device)
|
|
||||||
|
|
||||||
if [ -z "$ISCSI_TARGET_IQN" ]; then
|
|
||||||
err_msg "iscsi_target_iqn is not defined"
|
|
||||||
troubleshoot
|
|
||||||
fi
|
|
||||||
|
|
||||||
target_disk=
|
|
||||||
if [[ $ROOT_DEVICE ]]; then
|
|
||||||
target_disk="$(get_root_device)"
|
|
||||||
else
|
|
||||||
t=0
|
|
||||||
while ! target_disk=$(find_disk "$DISK"); do
|
|
||||||
if [ $t -eq 60 ]; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
t=$(($t + 1))
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$target_disk" ]; then
|
|
||||||
err_msg "Could not find disk to use."
|
|
||||||
troubleshoot
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "start iSCSI target on $target_disk"
|
|
||||||
start_iscsi_target "$ISCSI_TARGET_IQN" "$target_disk" ALL
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
err_msg "Failed to start iscsi target."
|
|
||||||
troubleshoot
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$BOOT_METHOD" = "$VMEDIA_BOOT_TAG" ]; then
|
|
||||||
TOKEN_FILE="$VMEDIA_DIR/token"
|
|
||||||
if [ -f "$TOKEN_FILE" ]; then
|
|
||||||
TOKEN_HEADER="-H 'X-Auth-Token: $(cat $TOKEN_FILE)'"
|
|
||||||
else TOKEN_HEADER=""
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
TOKEN_FILE=token-$DEPLOYMENT_ID
|
|
||||||
|
|
||||||
# Allow multiple versions of the tftp client
|
|
||||||
if tftp -r $TOKEN_FILE -g $BOOT_SERVER || tftp $BOOT_SERVER -c get $TOKEN_FILE; then
|
|
||||||
TOKEN_HEADER="-H 'X-Auth-Token: $(cat $TOKEN_FILE)'"
|
|
||||||
else
|
|
||||||
TOKEN_HEADER=""
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Requesting Ironic API to deploy image"
|
|
||||||
deploy_data="'{\"address\":\"$BOOT_IP_ADDRESS\",\"key\":\"$DEPLOYMENT_KEY\",\"iqn\":\"$ISCSI_TARGET_IQN\",\"error\":\"$FIRST_ERR_MSG\"}'"
|
|
||||||
do_vendor_passthru_and_wait "$deploy_data" "pass_deploy_info"
|
|
||||||
|
|
||||||
echo "Stopping iSCSI target on $target_disk"
|
|
||||||
stop_iscsi_target
|
|
||||||
|
|
||||||
# If localboot is set, install a bootloader
|
|
||||||
if [ "$IRONIC_BOOT_OPTION" = "local" ]; then
|
|
||||||
echo "Installing bootloader"
|
|
||||||
|
|
||||||
error_msg=$(install_bootloader)
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
status=SUCCEEDED
|
|
||||||
else
|
|
||||||
status=FAILED
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Requesting Ironic API to complete the deploy"
|
|
||||||
bootloader_install_data="'{\"address\":\"$BOOT_IP_ADDRESS\",\"status\":\"$status\",\"key\":\"$DEPLOYMENT_KEY\",\"error\":\"$error_msg\"}'"
|
|
||||||
do_vendor_passthru_and_wait "$bootloader_install_data" "pass_bootloader_install_info"
|
|
||||||
fi
|
|
@ -1,3 +0,0 @@
|
|||||||
curl:
|
|
||||||
parted:
|
|
||||||
util-linux:
|
|
@ -1,21 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then
|
|
||||||
set -x
|
|
||||||
fi
|
|
||||||
set -eu
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
echo "WARNING: The deploy-ironic element is deprecated. Please use the ironic-agent element instead." 1>&2
|
|
Loading…
Reference in New Issue
Block a user