diff --git a/elements/deploy-ironic/binary-deps.d/deploy-ironic b/elements/deploy-ironic/binary-deps.d/deploy-ironic index 30127f76..32cb1ba0 100644 --- a/elements/deploy-ironic/binary-deps.d/deploy-ironic +++ b/elements/deploy-ironic/binary-deps.d/deploy-ironic @@ -1,5 +1,3 @@ curl -tgtadm -tgtd partprobe lsblk diff --git a/elements/deploy-ironic/package-installs.yaml b/elements/deploy-ironic/package-installs.yaml index a31cf546..80775fda 100644 --- a/elements/deploy-ironic/package-installs.yaml +++ b/elements/deploy-ironic/package-installs.yaml @@ -1,4 +1,3 @@ curl: -tgt: parted: util-linux: diff --git a/elements/deploy-targetcli/README.md b/elements/deploy-targetcli/README.md new file mode 100644 index 00000000..b79d6e86 --- /dev/null +++ b/elements/deploy-targetcli/README.md @@ -0,0 +1,7 @@ +Use targetcli for the deploy ramdisk + +Provides the necessary scripts and dependencies to use targetcli +for exporting the iscsi target in the deploy ramdisk. + +Implemented as a dracut module, so will only work with dracut-based +ramdisks. diff --git a/elements/deploy-targetcli/binary-deps.d/deploy-targetcli b/elements/deploy-targetcli/binary-deps.d/deploy-targetcli new file mode 100644 index 00000000..50698d32 --- /dev/null +++ b/elements/deploy-targetcli/binary-deps.d/deploy-targetcli @@ -0,0 +1 @@ +targetcli diff --git a/elements/deploy-targetcli/dracut-drivers.d/targetcli-drivers b/elements/deploy-targetcli/dracut-drivers.d/targetcli-drivers new file mode 100644 index 00000000..f9b4be99 --- /dev/null +++ b/elements/deploy-targetcli/dracut-drivers.d/targetcli-drivers @@ -0,0 +1,6 @@ +target_core_mod +iscsi_target_mod +target_core_iblock +target_core_file +target_core_pscsi +configfs diff --git a/elements/deploy-targetcli/element-deps b/elements/deploy-targetcli/element-deps new file mode 100644 index 00000000..7076aba9 --- /dev/null +++ b/elements/deploy-targetcli/element-deps @@ -0,0 +1 @@ +package-installs diff --git a/elements/deploy-targetcli/extra-data.d/50-add-targetcli-module b/elements/deploy-targetcli/extra-data.d/50-add-targetcli-module new file mode 100755 index 00000000..388c5124 --- /dev/null +++ b/elements/deploy-targetcli/extra-data.d/50-add-targetcli-module @@ -0,0 +1,11 @@ +#!/bin/bash + +set -eu +set -o pipefail + +if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then + set -x +fi + +MODULE_PATH="/usr/lib/dracut/modules.d" +sudo cp -r $(dirname $0)/module/ ${TMP_MOUNT_PATH}${MODULE_PATH}/50targetcli diff --git a/elements/deploy-targetcli/extra-data.d/module/iscsi-func b/elements/deploy-targetcli/extra-data.d/module/iscsi-func new file mode 100755 index 00000000..50ec3d80 --- /dev/null +++ b/elements/deploy-targetcli/extra-data.d/module/iscsi-func @@ -0,0 +1,22 @@ +function start_iscsi_target() { + local iqn=$1 + local dev=$2 + local cli=$3 + + # used by tgtd + mkdir -p /var/run + + ln -s /usr/bin/targetcli /targetcli_bin.py + /targetcli-wrapper /backstores/block create block1 dev=$dev + /targetcli-wrapper /iscsi create $iqn + /targetcli-wrapper /iscsi/$iqn/tpg1/luns create /backstores/block/block1 1 + /targetcli-wrapper /iscsi/$iqn/tpg1/portals create $BOOT_IP_ADDRESS + /targetcli-wrapper /iscsi/$iqn/tpg1 set attribute authentication=0 + /targetcli-wrapper /iscsi/$iqn/tpg1 set attribute demo_mode_write_protect=0 + /targetcli-wrapper /iscsi/$iqn/tpg1 set attribute generate_node_acls=1 + +} + +function stop_iscsi_target() { + /targetcli-wrapper clearconfig confirm=True +} diff --git a/elements/deploy-targetcli/extra-data.d/module/module-setup.sh b/elements/deploy-targetcli/extra-data.d/module/module-setup.sh new file mode 100755 index 00000000..36786759 --- /dev/null +++ b/elements/deploy-targetcli/extra-data.d/module/module-setup.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Dracut is bash too, and it doesn't play nicely with our usual sets +# dib-lint: disable=setu sete setpipefail dibdebugtrace + +check() { + return 0 +} + +depends() { + return 0 +} + +install() { + inst /bin/targetcli + inst "$moddir/targetcli-wrapper" /targetcli-wrapper + inst "$moddir/iscsi-func" /iscsi-func + # Install all of Python + # TODO(bnemec): At some point this will need to be extended to support + # Python 3, but for the moment we aren't using that anyway. + inst /usr/bin/python + for i in $(find /usr/lib64/python2.7/ -type f); do + inst $i + done + for i in $(find /usr/lib/python2.7/ -type f); do + inst $i + done +} diff --git a/elements/deploy-targetcli/extra-data.d/module/targetcli-wrapper b/elements/deploy-targetcli/extra-data.d/module/targetcli-wrapper new file mode 100755 index 00000000..9bf5d8a4 --- /dev/null +++ b/elements/deploy-targetcli/extra-data.d/module/targetcli-wrapper @@ -0,0 +1,31 @@ +#!/usr/bin/python + +# Copyright 2014 Red Hat, Inc. +# +# 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. + +import rtslib + +import targetcli_bin + + +class MyISCSIFabricModule(rtslib.fabric.ISCSIFabricModule): + def __init__(self): + super(rtslib.fabric.ISCSIFabricModule, self).__init__('iscsi') + self.wwn_types = ('free',) + + +rtslib.fabric.fabric_modules['iscsi'] = MyISCSIFabricModule + + +targetcli_bin.main() diff --git a/elements/deploy-targetcli/package-installs.yaml b/elements/deploy-targetcli/package-installs.yaml new file mode 100644 index 00000000..9c9c8767 --- /dev/null +++ b/elements/deploy-targetcli/package-installs.yaml @@ -0,0 +1 @@ +targetcli: diff --git a/elements/deploy-tgtadm/README.md b/elements/deploy-tgtadm/README.md new file mode 100644 index 00000000..b09487cd --- /dev/null +++ b/elements/deploy-tgtadm/README.md @@ -0,0 +1,6 @@ +Use tgtadm and tgtd for the deploy ramdisk + +Provides the necessary scripts and dependencies to use tgtadm +and tgtd for exporting the iscsi target in the deploy ramdisk. + +Will only work with the standard (not dracut) ramdisk. diff --git a/elements/deploy-tgtadm/binary-deps.d/deploy-tgtadm b/elements/deploy-tgtadm/binary-deps.d/deploy-tgtadm new file mode 100644 index 00000000..8ef4d780 --- /dev/null +++ b/elements/deploy-tgtadm/binary-deps.d/deploy-tgtadm @@ -0,0 +1,2 @@ +tgtadm +tgtd diff --git a/elements/deploy-tgtadm/extra-data.d/50-inject-tgtadm-iscsi-func b/elements/deploy-tgtadm/extra-data.d/50-inject-tgtadm-iscsi-func new file mode 100755 index 00000000..c599e396 --- /dev/null +++ b/elements/deploy-tgtadm/extra-data.d/50-inject-tgtadm-iscsi-func @@ -0,0 +1,12 @@ +#!/bin/bash + +set -eu +set -o pipefail + +if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then + set -x +fi + +RAMDISK_SCRIPT_PATH="$TMP_MOUNT_PATH/tmp/ramdisk-build/scripts/d" +mkdir -p ${RAMDISK_SCRIPT_PATH} +cp $(dirname $0)/scripts/iscsi-func ${RAMDISK_SCRIPT_PATH} diff --git a/elements/deploy-tgtadm/extra-data.d/scripts/iscsi-func b/elements/deploy-tgtadm/extra-data.d/scripts/iscsi-func new file mode 100644 index 00000000..d9dd1096 --- /dev/null +++ b/elements/deploy-tgtadm/extra-data.d/scripts/iscsi-func @@ -0,0 +1,21 @@ +function start_iscsi_target() { + local iqn=$1 + local dev=$2 + local cli=$3 + + # used by tgtd + mkdir -p /var/run + + tgtd + wait_for 10 0.5 check_tgtd_socket + + tgtadm --lld iscsi --mode target --op new --tid 1 --targetname "$iqn" + tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 1 --backing-store "$dev" + tgtadm --lld iscsi --mode target --op bind --tid 1 --initiator-address "$cli" +} + +function stop_iscsi_target() { + tgtadm --lld iscsi --mode logicalunit --op delete --tid 1 --lun 1 + tgtadm --lld iscsi --mode target --op delete --tid 1 + killall tgtd +} diff --git a/elements/deploy-tgtadm/package-installs.yaml b/elements/deploy-tgtadm/package-installs.yaml new file mode 100644 index 00000000..79df9f9a --- /dev/null +++ b/elements/deploy-tgtadm/package-installs.yaml @@ -0,0 +1 @@ +tgt: diff --git a/elements/dracut-ramdisk/element-deps b/elements/dracut-ramdisk/element-deps index c07f4133..24cee227 100644 --- a/elements/dracut-ramdisk/element-deps +++ b/elements/dracut-ramdisk/element-deps @@ -1,3 +1,4 @@ +deploy-targetcli pkg-map ramdisk-base source-repositories diff --git a/elements/ramdisk-base/extra-data.d/scripts/d/init-func b/elements/ramdisk-base/extra-data.d/scripts/d/init-func index f68a54a5..1d4b59ab 100755 --- a/elements/ramdisk-base/extra-data.d/scripts/d/init-func +++ b/elements/ramdisk-base/extra-data.d/scripts/d/init-func @@ -13,6 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +source /iscsi-func + function configure_vmedia_dir() { VMEDIA_MOUNT_POINT="/vfloppy_mnt" VMEDIA_DIR="/vfloppy" @@ -238,28 +240,6 @@ wait_for(){ return 1 } -function start_iscsi_target() { - local iqn=$1 - local dev=$2 - local cli=$3 - - # used by tgtd - mkdir -p /var/run - - tgtd - wait_for 10 0.5 check_tgtd_socket - - tgtadm --lld iscsi --mode target --op new --tid 1 --targetname "$iqn" - tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 1 --backing-store "$dev" - tgtadm --lld iscsi --mode target --op bind --tid 1 --initiator-address "$cli" -} - -function stop_iscsi_target() { - tgtadm --lld iscsi --mode logicalunit --op delete --tid 1 --lun 1 - tgtadm --lld iscsi --mode target --op delete --tid 1 - killall tgtd -} - function troubleshoot() { if [ "$TROUBLESHOOT" != 1 ]; then _DO_TROUBLESHOOT="" diff --git a/elements/ramdisk/element-deps b/elements/ramdisk/element-deps index 4fdba769..8d11fdb4 100644 --- a/elements/ramdisk/element-deps +++ b/elements/ramdisk/element-deps @@ -1,2 +1,3 @@ +deploy-tgtadm pkg-map ramdisk-base