[Ovirt-devel] [PATCH node] Add iSCSI initiator setup option

Joey Boggs
Fri, 23 Oct 2009 19:53:33 -0000

This add an iscsi initiator name setup option to the main menu in
ovirt-config-setup and can also be accessed via ovirt-config-iscsi.

Also accepts AUTO setup by running ovirt-config-iscsi AUTO and generates a
random name as before

---
 Makefile.am                |    1 +
 ovirt-node.spec.in         |    3 ++
 scripts/ovirt-config-boot  |    4 ---
 scripts/ovirt-config-iscsi |   56 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+), 4 deletions(-)
 create mode 100755 scripts/ovirt-config-iscsi

diff --git a/Makefile.am b/Makefile.am
index abb7c33..b2419cd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -58,6 +58,7 @@ EXTRA_DIST =			\
   scripts/ovirt-config-boot-wrapper  \
   scripts/ovirt-config-collectd  \
   scripts/ovirt-config-hostname  \
+  scripts/ovirt-config-iscsi	\
   scripts/ovirt-config-logging  \
   scripts/ovirt-config-networking \
   scripts/ovirt-config-password \
diff --git a/ovirt-node.spec.in b/ovirt-node.spec.in
index 2a6b7b6..4a68c44 100644
--- a/ovirt-node.spec.in
+++ b/ovirt-node.spec.in
@@ -160,6 +160,7 @@ cd -
 %{__install} -p -m0755 scripts/ovirt-config-boot-wrapper
%{buildroot}%{_sbindir}
 %{__install} -p -m0755 scripts/ovirt-config-collectd %{buildroot}%{_sbindir}
 %{__install} -p -m0755 scripts/ovirt-config-hostname %{buildroot}%{_sbindir}
+%{__install} -p -m0755 scripts/ovirt-config-iscsi %{buildroot}%{_sbindir}
 %{__install} -p -m0755 scripts/ovirt-config-logging %{buildroot}%{_sbindir}
 %{__install} -p -m0755 scripts/ovirt-config-networking %{buildroot}%{_sbindir}
 %{__install} -p -m0755 scripts/ovirt-config-password %{buildroot}%{_sbindir}
@@ -265,6 +266,7 @@ ln -s ovirt-release %{buildroot}/etc/system-release
 %{__ln_s} ../..%{_sbindir}/ovirt-config-storage
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"00_Disk Partitioning"
 %{__ln_s} ../..%{_sbindir}/ovirt-config-password
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"05_Administrator
Password"
 %{__ln_s} ../..%{_sbindir}/ovirt-config-hostname
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"10_Set Hostname"
+%{__ln_s} ../..%{_sbindir}/ovirt-config-iscsi
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"12_iSCSI Initiator
Setup"
 %{__ln_s} ../..%{_sbindir}/ovirt-config-networking
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"15_Networking Setup"
 %{__ln_s} ../..%{_sbindir}/ovirt-config-logging
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"30_Logging Setup"
 %{__ln_s} ../..%{_sbindir}/ovirt-config-collectd
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"35_Collectd Setup"
@@ -334,6 +336,7 @@ fi
 %{_sbindir}/ovirt-config-boot
 %{_sbindir}/ovirt-config-boot-wrapper
 %{_sbindir}/ovirt-config-collectd
+%{_sbindir}/ovirt-config-iscsi
 %{_sbindir}/ovirt-config-hostname
 %{_sbindir}/ovirt-config-logging
 %{_sbindir}/ovirt-config-networking
diff --git a/scripts/ovirt-config-boot b/scripts/ovirt-config-boot
index dd53988..b2efe71 100755
--- a/scripts/ovirt-config-boot
+++ b/scripts/ovirt-config-boot
@@ -170,10 +170,6 @@ EOF
         return $rc
     fi

-    # install iscsi initiator name for this machine
-    echo "InitiatorName=$(iscsi-iname)" >
/etc/iscsi/initiatorname.iscsi
-    ovirt_store_config /etc/iscsi/initiatorname.iscsi
-
     umount /liveos
     umount /boot
     # mark new Root ready to go, reboot() in ovirt-function switches it to
active
diff --git a/scripts/ovirt-config-iscsi b/scripts/ovirt-config-iscsi
new file mode 100755
index 0000000..8e1bbaf
--- /dev/null
+++ b/scripts/ovirt-config-iscsi
@@ -0,0 +1,56 @@
+#!/bin/bash
+#
+# Configures the hostname file based on kernel cmdline or user prompt
+# Source functions library
+. /etc/init.d/functions
+. /etc/init.d/ovirt-functions
+
+trap '__st=$?; stop_log; exit $__st' 0
+trap 'exit $?' 1 2 13 15
+
+warn() { printf '%s\n' "$*" >&2; }
+
+if ! is_local_storage_configured; then
+    warn "Local storage must be configured prior to setting the iSCSI
Initiator Name."
+    exit 99
+fi
+
+INITIATOR_FILE="/etc/iscsi/initiatorname.iscsi"
+
+function prompt_user {
+    printf "\n"
+    printf "Enter iSCSI Initiator Name (If blank one will be automatically
generated)\n"
+    printf "Enter Q to quit\n"
+    read REPLY
+    if [[ $REPLY == "q" || $REPLY == "Q" ]]; then
+        printf "Aborting due to user request"
+        return
+    fi
+
+    set_initiator $REPLY
+}
+
+function set_initiator {
+    if [ -z "$1" ]; then
+        INITIATOR_NAME=$(iscsi-iname)
+    else
+        INITIATOR_NAME=$1
+    fi
+
+    echo "InitiatorName=$INITIATOR_NAME" > $INITIATOR_FILE
+    ovirt_store_config $INITIATOR_FILE
+    rc=$?
+    if [ $rc = 0 ]; then
+        printf "Initiator name set as: $INITIATOR_NAME\n"
+    else
+        printf "Setting initiator name failed\n"
+    fi
+}
+
+# AUTO for auto-install
+if [ "$1" = "AUTO" ]; then
+    set_initiator
+else
+    printf "\n\n iSCSI Initiator Configuration\n\n"
+    prompt_user
+fi
--
1.6.2.5