From bf222fe7bc85f25d7f8ac63b549b87db89984e1b Mon Sep 17 00:00:00 2001 From: Yuriy Zveryanskyy Date: Tue, 3 Dec 2013 17:52:50 +0200 Subject: [PATCH] Add deploy ramdisk element for Ironic Ironic requires callback from deploy ramdisk via API with json data. Auth token also required if Keystone auth enabled for Ironic API. This patch adds separate element 'deploy-ironic' for Ironic deploy ramdisk creation. Change-Id: I5ef96711763e50307cfa17c406a9e16bffb937bc --- elements/deploy-ironic/README.md | 2 + .../deploy-ironic/binary-deps.d/deploy-ironic | 4 ++ .../deploy-ironic/init.d/80-deploy-ironic | 51 +++++++++++++++++++ .../deploy-ironic/install.d/51-install-tgt | 2 + .../install.d/52-install-busybox | 2 + .../deploy-ironic/install.d/53-install-curl | 2 + 6 files changed, 63 insertions(+) create mode 100644 elements/deploy-ironic/README.md create mode 100644 elements/deploy-ironic/binary-deps.d/deploy-ironic create mode 100644 elements/deploy-ironic/init.d/80-deploy-ironic create mode 100755 elements/deploy-ironic/install.d/51-install-tgt create mode 100755 elements/deploy-ironic/install.d/52-install-busybox create mode 100755 elements/deploy-ironic/install.d/53-install-curl diff --git a/elements/deploy-ironic/README.md b/elements/deploy-ironic/README.md new file mode 100644 index 00000000..0645312b --- /dev/null +++ b/elements/deploy-ironic/README.md @@ -0,0 +1,2 @@ +A ramdisk that will expose the machine primary disk over iSCSI and reboot +once Ironic signals it is finished. diff --git a/elements/deploy-ironic/binary-deps.d/deploy-ironic b/elements/deploy-ironic/binary-deps.d/deploy-ironic new file mode 100644 index 00000000..dee62a0b --- /dev/null +++ b/elements/deploy-ironic/binary-deps.d/deploy-ironic @@ -0,0 +1,4 @@ +busybox +curl +tgtadm +tgtd diff --git a/elements/deploy-ironic/init.d/80-deploy-ironic b/elements/deploy-ironic/init.d/80-deploy-ironic new file mode 100644 index 00000000..5402e86d --- /dev/null +++ b/elements/deploy-ironic/init.d/80-deploy-ironic @@ -0,0 +1,51 @@ +readonly IRONIC_API_URL=$(get_kernel_parameter ironic_api_url) + +if [ -z "$ISCSI_TARGET_IQN" ]; then + err_msg "iscsi_target_iqn is not defined" + troubleshoot +fi + +t=0 +while ! target_disk=$(find_disk "$DISK"); do + if [ $t -eq 10 ]; then + break + fi + t=$(($t + 1)) + sleep 1 +done + +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 + +TOKEN_FILE=token-$DEPLOYMENT_ID + +if tftp -r /tftpboot/$TOKEN_FILE -g $BOOT_SERVER +then TOKEN_HEADER="-H 'X-Auth-Token: `cat $TOKEN_FILE`'" +else TOKEN_HEADER="" +fi + +DATA="'{\"address\":\"$BOOT_IP_ADDRESS\",\"key\":\"$DEPLOYMENT_KEY\",\"iqn\":\"$ISCSI_TARGET_IQN\",\"error\":\"$FIRST_ERR_MSG\"}'" + +echo "request Ironic API to deploy image" +curl \ + -X POST \ + -H 'Content-Type: application/json' \ + $TOKEN_HEADER \ + -d $DATA \ + $IRONIC_API_URL/nodes/$DEPLOYMENT_ID/vendor_passthru/pass_deploy_info + +echo "waiting for notice of complete" +nc -l -p 10000 + +echo "stop iSCSI target on $target_disk" + +stop_iscsi_target diff --git a/elements/deploy-ironic/install.d/51-install-tgt b/elements/deploy-ironic/install.d/51-install-tgt new file mode 100755 index 00000000..9c36dcae --- /dev/null +++ b/elements/deploy-ironic/install.d/51-install-tgt @@ -0,0 +1,2 @@ +#!/bin/bash +install-packages tgt diff --git a/elements/deploy-ironic/install.d/52-install-busybox b/elements/deploy-ironic/install.d/52-install-busybox new file mode 100755 index 00000000..fdecb5dd --- /dev/null +++ b/elements/deploy-ironic/install.d/52-install-busybox @@ -0,0 +1,2 @@ +#!/bin/bash +install-packages busybox diff --git a/elements/deploy-ironic/install.d/53-install-curl b/elements/deploy-ironic/install.d/53-install-curl new file mode 100755 index 00000000..369b77a3 --- /dev/null +++ b/elements/deploy-ironic/install.d/53-install-curl @@ -0,0 +1,2 @@ +#!/bin/bash +install-packages curl