[Ovirt-devel] [PATCH node] Creates a standalone mode entry point script.

Darryl L. Pierce dpierce at redhat.com
Tue Oct 28 16:40:14 UTC 2008


NOTE: I'm looking for feedback on this initial design. It only has
networking support at the moment.

The script will execute only when the node is booted without the support of
a server suite. If it determines that the node is running in standalone mode,
it will then kick over to a node setup script.

This iteration defines the general flow for the standalone mode's firstboot
use case. When the node boots and determines it's in standalone mode, it
goes through the following steps:

1. Prompt for an administrator password
2. Prompt the user to configure disk storage
3. Prompt the user to configure networking
4. Prompt the user to configure logging

The node then continues to boot normally.

Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
 Makefile.am                     |   34 +++++++++------
 ovirt-node.spec.in              |   15 ++++++-
 scripts/ovirt-config-logging    |    1 +
 scripts/ovirt-config-networking |   90 +++++++++++++++++++++++++++++++++++++++
 scripts/ovirt-config-password   |    1 +
 scripts/ovirt-config-setup      |   43 ++++++++++++++++++
 scripts/ovirt-config-storage    |    1 +
 scripts/ovirt-functions         |    5 ++
 scripts/ovirt-standalone-mode   |   38 ++++++++++++++++
 9 files changed, 213 insertions(+), 15 deletions(-)
 create mode 100755 scripts/ovirt-config-logging
 create mode 100755 scripts/ovirt-config-networking
 create mode 100755 scripts/ovirt-config-password
 create mode 100755 scripts/ovirt-config-setup
 create mode 100755 scripts/ovirt-config-storage
 create mode 100755 scripts/ovirt-standalone-mode

diff --git a/Makefile.am b/Makefile.am
index c55db13..3d824db 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -18,20 +18,26 @@
 OVIRT_CACHE_DIR	?= $(HOME)/ovirt-cache
 SUBDIRS = ovirt-identify-node ovirt-listen-awake
 
-EXTRA_DIST =			\
-  .gitignore			\
-  ovirt-node.spec		\
-  ovirt-node.spec.in		\
-  ovirt-node-selinux.te		\
-  scripts/collectd		\
-  scripts/collectd.conf.in	\
-  scripts/ovirt			\
-  scripts/ovirt-awake		\
-  scripts/ovirt-early		\
-  scripts/ovirt-functions	\
-  scripts/ovirt-post		\
-  scripts/ovirt-process-config  \
-  logrotate/ovirt-logrotate	\
+EXTRA_DIST =			  \
+  .gitignore			  \
+  ovirt-node.spec		  \
+  ovirt-node.spec.in		  \
+  ovirt-node-selinux.te		  \
+  scripts/collectd		  \
+  scripts/collectd.conf.in	  \
+  scripts/ovirt			  \
+  scripts/ovirt-awake		  \
+  scripts/ovirt-config-logging    \
+  scripts/ovirt-config-networking \
+  scripts/ovirt-config-password   \
+  scripts/ovirt-config-setup      \
+  scripts/ovirt-config-storage    \
+  scripts/ovirt-early		  \
+  scripts/ovirt-functions	  \
+  scripts/ovirt-post		  \
+  scripts/ovirt-process-config    \
+  scripts/ovirt-standalone-mode   \
+  logrotate/ovirt-logrotate	  \
   logrotate/ovirt-logrotate.conf
 
 # For Release: 0..., set _ovirt_dev=1 so that we get extra_release.GIT-
diff --git a/ovirt-node.spec.in b/ovirt-node.spec.in
index 912192e..02f8f0f 100644
--- a/ovirt-node.spec.in
+++ b/ovirt-node.spec.in
@@ -88,17 +88,22 @@ cd -
 
 %{__install} -p -m0755 scripts/ovirt-awake %{buildroot}%{_sbindir}
 %{__install} -p -m0755 scripts/ovirt-process-config %{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}
+%{__install} -p -m0755 scripts/ovirt-config-setup %{buildroot}%{_sbindir}
+%{__install} -p -m0755 scripts/ovirt-config-storage %{buildroot}%{_sbindir}
 %{__install} -p -m0755 ovirt-identify-node/ovirt-identify-node %{buildroot}%{_sbindir}
 %{__install} -p -m0755 ovirt-listen-awake/ovirt-listen-awake %{buildroot}%{_sbindir}
 %{__install} -Dp -m0755 ovirt-listen-awake/ovirt-listen-awake.init %{buildroot}%{_initrddir}/ovirt-listen-awake
 %{__install} -Dp -m0755 ovirt-listen-awake/ovirt-install-node %{buildroot}%{_sbindir}
 %{__install} -Dp -m0755 ovirt-listen-awake/ovirt-uninstall-node %{buildroot}%{_sbindir}
 
-
 %{__install} -p -m0644 scripts/ovirt-functions %{buildroot}%{_initrddir}
 %{__install} -p -m0755 scripts/ovirt-early %{buildroot}%{_initrddir}
 %{__install} -p -m0755 scripts/ovirt %{buildroot}%{_initrddir}
 %{__install} -p -m0755 scripts/ovirt-post %{buildroot}%{_initrddir}
+%{__install} -p -m0755 scripts/ovirt-standalone-mode %{buildroot}%{_initrddir}
 
 %{__install} -p -m0644 scripts/collectd %{buildroot}%{_sysconfdir}/chkconfig.d
 %{__install} -p -m0644 scripts/collectd.conf.in %{buildroot}%{_sysconfdir}
@@ -125,6 +130,7 @@ cd -
 /sbin/chkconfig --add ovirt-early
 /sbin/chkconfig --add ovirt
 /sbin/chkconfig --add ovirt-post
+/sbin/chkconfig --add ovirt-standalone-mode
 # this is ugly; we need collectd to start *after* libvirtd, so we own the
 # /etc/chkconfig.d/collectd file, and then have to re-define collectd here
 /sbin/chkconfig --add collectd
@@ -136,6 +142,7 @@ if [ "$1" = 0 ] ; then
   /sbin/chkconfig --del ovirt
   /sbin/chkconfig --del ovirt-post
   /sbin/chkconfig --del ovirt-listen-awake
+  /sbin/chkconfig --del ovirt-standalone-mode
 fi
 
 %post selinux
@@ -159,6 +166,11 @@ fi
 %files
 %defattr(-,root,root,0755)
 %{_sbindir}/ovirt-awake
+%{_sbindir}/ovirt-config-logging
+%{_sbindir}/ovirt-config-networking
+%{_sbindir}/ovirt-config-password
+%{_sbindir}/ovirt-config-setup
+%{_sbindir}/ovirt-config-storage
 %{_sbindir}/ovirt-process-config
 %{_sbindir}/ovirt-identify-node
 %{_sbindir}/ovirt-listen-awake
@@ -168,6 +180,7 @@ fi
 %{_initrddir}/ovirt
 %{_initrddir}/ovirt-post
 %{_initrddir}/ovirt-listen-awake
+%{_initrddir}/ovirt-standalone-mode
 %config %{_sysconfdir}/logrotate.d/ovirt-logrotate.conf
 %config %{_sysconfdir}/cron.hourly/ovirt-logrotate
 %defattr(-,root,root,0644)
diff --git a/scripts/ovirt-config-logging b/scripts/ovirt-config-logging
new file mode 100755
index 0000000..8b13789
--- /dev/null
+++ b/scripts/ovirt-config-logging
@@ -0,0 +1 @@
+
diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking
new file mode 100755
index 0000000..4d72bae
--- /dev/null
+++ b/scripts/ovirt-config-networking
@@ -0,0 +1,90 @@
+#!/bin/bash
+#
+# Iterates over the list of network devices on the node and prompts the user
+# to configure each.
+
+CONFIG_FILE_ROOT="/file/etc/sysconfig/network-scripts/ifcfg"
+
+function configure_interface
+{
+    NIC=$1
+    FILENAME="/var/tmp/augtool-$NIC"
+
+    printf "\nCONFIGURE INTERFACE: $NIC\n\n"
+
+    THIS_ROOT="$CONFIG_FILE_ROOT-$NIC"
+    CONFIG="rm $THIS_ROOT\nset $THIS_ROOT/DEVICE $NIC"
+
+    # Is this NIC shared?
+    while true; do
+        printf "Is $NIC a shared interface? (Y/N) "
+        read
+        case $REPLY in
+            Y|y) CONFIG="$CONFIG\nset $THIS_ROOT/TYPE bridge"; break ;;
+            N|n) bridge="N"; break ;;
+        esac
+    done
+
+    # how do you want to configure this device? (dhcp, static IP)
+    while true; do
+        printf "Does $NIC use dynamic addressing? (Y/N) "
+        read
+        case $REPLY in
+            Y|y) CONFIG="$CONFIG\nset $THIS_ROOT/BOOTPROTO dhcp"; break ;;
+            N|n)
+                printf "\tIP Address: "; read; IPADDR=$REPLY
+                printf "\t   Netmask: "; read; NETMASK=$REPLY
+                printf "\t Broadcast: "; read; BROADCAST=$REPLY
+                printf "\t   Gateway: "; read; GATEWAY=$REPLY
+
+                printf "\nIP Address: $IPADDR\nNetmask: $NETMASK\nBroadcast: $BROADCAST\nGateway: $GATEWAY\n"
+                printf "Is this correct? (Y/N) "
+                read
+                case $REPLY in
+                    Y|y)
+                        CONFIG="$CONFIG\nset $THIS_ROOT/IPADDR $IPADDR"
+                        CONFIG="$CONFIG\nset $THIS_ROOT/BROADCAST $BROADCAST"
+                        CONFIG="$CONFIG\nset $THIS_ROOT/NETMASK $NETMASK"
+                        break
+                        ;;
+                esac
+                ;;
+        esac
+    done
+
+    if [ "$bridge" == "N" ]; then
+        printf "Is $NIC bridged? (Y/N) "
+        read
+        case $REPLY in
+            Y|y) 
+                printf "What is the bridge name? "
+                read 
+                CONFIG="$CONFIG\n set $THIS_ROOT/BRIDGE $REPLY"
+                ;;
+        esac
+    fi
+
+    CONFIG="$CONFIG\nset $THIS_ROOT/ONBOOT yes"
+    printf "$CONFIG\n" > $FILENAME
+}
+
+# get the list of network cards on this machine
+NICS=$(hal-device | awk '/net.interface/ {
+    match($0, "= '"'"'(.*)'"'"' ", nic); printf("%s ", nic[1]); }')
+
+# Append a quit option
+NICS="$NICS Quit"
+
+PS3="Please select a network interface to configure:"
+select NIC in $NICS
+do
+    case "$NIC" in
+        "Quit")
+            exit 0
+            ;;
+
+        *)
+            configure_interface $NIC
+            ;;
+    esac
+done
diff --git a/scripts/ovirt-config-password b/scripts/ovirt-config-password
new file mode 100755
index 0000000..8b13789
--- /dev/null
+++ b/scripts/ovirt-config-password
@@ -0,0 +1 @@
+
diff --git a/scripts/ovirt-config-setup b/scripts/ovirt-config-setup
new file mode 100755
index 0000000..6db49db
--- /dev/null
+++ b/scripts/ovirt-config-setup
@@ -0,0 +1,43 @@
+#!/bin/bash
+# 
+# Entry point for configuring an oVirt node when running in standalone mode.
+
+PS3="Please select an option: "
+
+# TODO should we make this optional, based on whether the password was already set?
+PASSWORD_OPTION="Password"
+
+LIST="Networking Storage Logging ${PASSWORD_OPTION} Quit"
+
+select OPT in $LIST
+do
+    printf "\n"
+
+    case "$OPT" in
+        "Networking")
+            ovirt-config-networking
+            ;;
+
+        "Storage")
+            ovirt-config-storage
+            ;;
+
+        "Logging")
+            ovirt-config-logging
+            ;;
+
+        "Password")
+            # TODO only do this if we allow it
+            ovirt-config-password
+            ;;
+
+        "Quit")
+            printf "Finished.\n"
+            exit 0
+            ;;
+
+        "*")
+            printf "Invalid option \"${OPT}\".\n"
+            ;;
+    esac
+done
diff --git a/scripts/ovirt-config-storage b/scripts/ovirt-config-storage
new file mode 100755
index 0000000..8b13789
--- /dev/null
+++ b/scripts/ovirt-config-storage
@@ -0,0 +1 @@
+
diff --git a/scripts/ovirt-functions b/scripts/ovirt-functions
index e251eac..53e9f62 100644
--- a/scripts/ovirt-functions
+++ b/scripts/ovirt-functions
@@ -7,6 +7,11 @@ OVIRT_LABEL=OVIRT
 
 OVIRT_BACKUP_DIR=/var/lib/ovirt-backup
 
+is_standalone()
+{
+    return 0
+}
+
 find_srv()
 {
     local dnsreply
diff --git a/scripts/ovirt-standalone-mode b/scripts/ovirt-standalone-mode
new file mode 100755
index 0000000..869b77c
--- /dev/null
+++ b/scripts/ovirt-standalone-mode
@@ -0,0 +1,38 @@
+#!/bin/bash
+#
+# ovirt-standalone-mode Starts the node in standalone mode.
+#
+# chkconfig: - 01 99
+# description: ovirt-standalone-mode services
+#
+
+# Source functions library
+. /etc/init.d/functions
+. /etc/init.d/ovirt-functions
+
+start ()
+{
+    ovirt-config-setup
+}
+
+case "$1" in
+    start)
+        #is_standalone
+        #if [ $? -ne 0 ]; then
+        #    exit 0
+        #fi
+
+        printf "Starting ovirt-standalong-mode: "
+
+        {
+            start
+        } >> $OVIRT_LOGFILE 2>&1
+
+        test $? == 0 && success || failure
+        echo
+        ;;
+
+    *)
+        echo "Usage: ovirt-early {start}"
+        exit 2
+esac
-- 
1.5.6.5




More information about the ovirt-devel mailing list