Darryl L. Pierce
2008-Oct-28 16:40 UTC
[Ovirt-devel] [PATCH node] Creates a standalone mode entry point script.
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
Darryl L. Pierce
2008-Nov-05 13:37 UTC
[Ovirt-devel] [PATCH node] Creates a standalone mode entry point script.
NOTE: This is for feedback and testing, and requires the patch for node-image to reintroduce hal-device. 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. --- Makefile.am | 34 +++++---- ovirt-node.spec.in | 15 ++++- scripts/ovirt-config-logging | 1 + scripts/ovirt-config-networking | 98 ++++++++++++++++++++++++++ scripts/ovirt-config-password | 1 + scripts/ovirt-config-setup | 43 +++++++++++ scripts/ovirt-config-storage | 147 +++++++++++++++++++++++++++++++++++++++ scripts/ovirt-functions | 5 ++ scripts/ovirt-standalone-mode | 55 +++++++++++++++ 9 files changed, 384 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 d029c57..10a544b 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..705521b --- /dev/null +++ b/scripts/ovirt-config-networking @@ -0,0 +1,98 @@ +#!/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 + + echo +} + +# TODO the menu doesn't redisplay unless you hit enter -- needs fixing +# 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") + break + ;; + + *) + configure_interface $NIC + ;; + esac +done + +# Merge together all generated files and run augtool + +cat /var/tmp/augtool-* > /var/tmp/config-augtool +augtool < /var/tmp/config-augtool 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..a8bdc5d --- /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..3a16411 --- /dev/null +++ b/scripts/ovirt-config-storage @@ -0,0 +1,147 @@ +#!/bin/bash +# + +function show_logical_volumes +{ + OUTPUT=$(lvdisplay | awk '/LV Name/ { print " "$3 }') + + printf "Current Logical Volumes:\n" + printf "========================\n" + printf "$OUTPUT\n" +} + +function create_partition +{ + PHYVOLS=$(pvdisplay | awk '/VG Name/ { print $3" " }') + PHYVOLS="$PHYVOLS Quit" + printf "\n" + + PS3="Please select a physical volume: " + select PHYVOL in $PHYVOLS + do + case "$PHYVOL" in + "Quit") + return + ;; + + *) + if [ "" != "$PHYVOL" ] + then + PVOLUME="$PHYVOL" + break + fi + ;; + esac + printf "\n" + done + + printf "\nWhat is the name for the new logical volume? " + read + if [[ "$REPLY" =~ '^\w+$' ]]; then + LVOLUME="$REPLY" + + printf "\nWhat size (in Gigabytes) is this new logical volume? " + read + if [[ "$REPLY" =~ '^[0-9.]+$' ]]; then + LVSIZE="$REPLY" + + printf "\nMount point for this new file system? " + read + if [[ "$REPLY" =~ '^\/(\w|\/)*$' ]]; then + MOUNTPT="$REPLY" + + printf "\nCreating /dev/${PHYVOL}/${LVOLUME} (${LVSIZE} GB), mounted at ${MOUNTPT} :\n\n" + printf " Is that correct? (Y/N) " + read + case $REPLY in + Y|y) + lvdevice="/dev/${PHYVOL}/${LVOLUME}" + lvcreate --size ${LVSIZE}G /dev/${PHYVOL} --name $LVOLUME; + printf "${lvdevice}\t${MOUNTPT}\text3\tdefaults\t1 2\n" >> /etc/fstab + ;; + + N|n) printf "Logical volume creation aborted.\n"; break ;; + esac + else + printf "\nInvalid mount point.\n" + fi + else + printf "\nLogical volume size must be a numeric value.\n" + fi + else + printf "\n'$REPLY' is an invalid logical volume name.\n" + fi + + printf "\n" +} + +function format_partition +{ + LVOLUMES=$(lvdisplay | awk '/LV Name/ { print $3" " }') + LVOLUMES="${LVOLUMES} Quit" + PS3="Select a volume to format: " + + select LVM in $LVOLUMES + do + case "$LVM" in + "Quit") + return + ;; + + *) + if [ "" != "$LVM" ]; then + break + fi + ;; + esac + printf "\n" + done + + printf "Formatting ${LVM} with EXT3..." + + mkfs -t ext3 ${LVM} +} + +function delete_partition +{ + echo "Delete" +} + + +declare -a OPTIONS +OPTIONS[${#OPTIONS[*]}]="Create Partition" +OPTIONS[${#OPTIONS[*]}]="Format Partition" +OPTIONS[${#OPTIONS[*]}]="Remove Partition" +OPTIONS[${#OPTIONS[*]}]="Quit" +eval set $OPTIONS + +show_logical_volumes + +PS3="Please select a storage operation to perform: " +printf "\n" + +eval set $OPTIONS +select OPTION in "${OPTIONS[@]}" +do + case "$OPTION" in + "Create Partition") + create_partition + ;; + + "Format Partition") + format_partition + ;; + + "Delete Partition") + delete_partition + ;; + + "Quit") + break + ;; + esac + + printf "\n" + show_logical_volumes + PS3="Please select a storage operation to perform: " +done 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..e503917 --- /dev/null +++ b/scripts/ovirt-standalone-mode @@ -0,0 +1,55 @@ +#!/bin/bash +# +# ovirt-standalone-mode Starts the node in standalone mode. +# +# chkconfig: 2345 01 99 +# description: ovirt-early services +# +# Copyright (C) 2008 Red Hat, Inc. +# Written by Darryl L. Pierce <dpierce at redhat.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. A copy of the GNU General Public License is +# also available at http://www.gnu.org/copyleft/gpl.html. + +## 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-standalone-mode: " + + { + start + } + + test $? == 0 && success || failure + echo + ;; + + *) + echo "Usage: ovirt-early {start}" + exit 2 +esac -- 1.5.6.5
Darryl L. Pierce
2008-Nov-06 16:41 UTC
[Ovirt-devel] [PATCH node] Creates a standalone mode entry point script.
Request for comments: This patch includes booting to firstboot/standalone mode, configure networking and also configure local storage (DESTRUCTIVE). 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 | 98 +++++++++++++++++++++++++++++++++ scripts/ovirt-config-password | 1 + scripts/ovirt-config-setup | 23 ++++++++ scripts/ovirt-config-storage | 113 +++++++++++++++++++++++++++++++++++++++ scripts/ovirt-functions | 5 ++ scripts/ovirt-standalone-mode | 55 +++++++++++++++++++ 9 files changed, 330 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 d029c57..10a544b 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..705521b --- /dev/null +++ b/scripts/ovirt-config-networking @@ -0,0 +1,98 @@ +#!/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 + + echo +} + +# TODO the menu doesn't redisplay unless you hit enter -- needs fixing +# 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") + break + ;; + + *) + configure_interface $NIC + ;; + esac +done + +# Merge together all generated files and run augtool + +cat /var/tmp/augtool-* > /var/tmp/config-augtool +augtool < /var/tmp/config-augtool 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..8408d14 --- /dev/null +++ b/scripts/ovirt-config-setup @@ -0,0 +1,23 @@ +#!/bin/bash +# +# Entry point for configuring an oVirt node when running in standalone mode. + +while true; do + PS3="Please select an option: " + # TODO should we make this optional, based on whether the password was already set? + PASSWORD_OPTION="Password" + OPTIONS="Networking Storage Logging ${PASSWORD_OPTION} Quit" + + select OPTION in $OPTIONS + do + printf "\n" + + case "$OPTION" in + "Networking") ovirt-config-networking ; break ;; + "Storage") ovirt-config-storage ; break ;; + "Logging") ovirt-config-logging ; break ;; + "Password") ovirt-config-password ; break ;; + "Quit") exit 0 ;; + esac + done +done diff --git a/scripts/ovirt-config-storage b/scripts/ovirt-config-storage new file mode 100755 index 0000000..91d50de --- /dev/null +++ b/scripts/ovirt-config-storage @@ -0,0 +1,113 @@ +#!/bin/bash +# +# All sizes are in gigabytes + +DRIVE=$(sfdisk -s | awk '/\/dev\/([sh]da)/ { match($0, "^(.*):.*", data); printf data[1] }') +BOOT_SIZE=1 +INSTALL_SIZE=10 +CONFIG_SIZE=5 +LOGGING_SIZE=2 + +MEM_SIZE=$(cat /proc/meminfo | awk '/MemTotal/ { print $2 }') +MEM_SIZE=$(( $MEM_SIZE / ( 1024 ** 2) )) +SWAP_SIZE=$(($MEM_SIZE * 2 + 1)) + +function do_configure +{ + read -p "Swap partition size (Currently ${SWAP_SIZE})? " + if [[ $REPLY =~ ^[0-9]+$ ]] && [[ $REPLY -gt 0 ]]; then + SWAP_SIZE=$REPLY + else + printf "Swap value is invalid.\n" + return + fi + + read -p "Boot partition size (Currently ${SWAP_SIZE})? " + if [[ $REPLY =~ ^[0-9]+$ ]] && [[ $REPLY -gt 0 ]]; then + BOOT_SIZE=$REPLY + else + printf "Boot value is invalid.\n" + return + fi + +} + +function do_review +{ + printf "\n" + printf "The local disk will be repartitioned as follows:\n" + printf "================================================\n" + printf " Physical Hard Disk: ${DRIVE}\n" + printf " Boot partition size: ${BOOT_SIZE} GB\n" + printf " Swap partition size: ${SWAP_SIZE} GB\n" + printf " Installation partition size: ${INSTALL_SIZE} GB\n" + printf " Configuration partition size: ${CONFIG_SIZE} GB\n" + printf " Logging partition size: ${LOGGING_SIZE} GB\n" + printf "\n" +} + +function do_partitioning +{ + while true; do + printf "\n" + printf "!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!\n" + printf "!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!\n" + printf "!!WARNING!! !!WARNING!!\n" + printf "!!WARNING!! !!WARNING!!\n" + printf "!!WARNING!! If you proceed this will destroy all data on your local system, and !!WARNING!!\n" + printf "!!WARNING!! your hard disk will be irreversably reconfiguration. !!WARNING!!\n" + printf "!!WARNING!! !!WARNING!!\n" + printf "!!WARNING!! !!WARNING!!\n" + printf "!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!\n" + printf "!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!\n" + printf "\n" + printf "\tContinue? (Y/n) " + read + case $REPLY in + Y|y) + { + dd if=/dev/zero of=/dev/sda bs=1K count=1 + blockdev --rereadpt /dev/sda + # Boot partition + # /dev/sda1 = Boot partition + # /dev/sda2 = Swap partition + # /dev/sda4 = LVM + echo -e "n\np\n1\n\n+$(( $BOOT_SIZE * 1024))M\na\n1\n + n\np\n2\n\n+$(( $SWAP_SIZE * 1024))M\nt\n2\n82\n + n\np\n4\n\n\nt\n4\n8e\n + w\n" | fdisk $DRIVE + pvcreate /dev/sda4 + vgcreate /dev/VolGroup00 /dev/sda4 + + lvcreate --name Ovirt /dev/VolGroup00 --size ${INSTALL_SIZE}G + lvcreate --name Config /dev/VolGroup00 --size ${CONFIG_SIZE}G + lvcreate --name Logging /dev/VolGroup00 --size ${LOGGING_SIZE}G + + mkfs -t ext3 /dev/sda1 + mkfs -t ext3 /dev/VolGroup00/Ovirt + mkfs -t ext3 /dev/VolGroup00/Config + mkfs -t ext3 /dev/VolGroup00/Logging + + } > partition.log + break ;; + N|n) return ;; + esac + done +} + +while true; do + OPTIONS="Configure Review Partition Quit" + PS3="Choose an option: " + + printf "\n" + + select OPTION in $OPTIONS + do + case "$OPTION" in + "Configure") do_configure ; break ;; + "Review") do_review ; break ;; + "Partition") do_partitioning ; break ;; + "Quit") exit ;; + esac + done +done 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..46d081a --- /dev/null +++ b/scripts/ovirt-standalone-mode @@ -0,0 +1,55 @@ +#!/bin/bash +# +# ovirt-standalone-mode Starts the node in standalone mode. +# +# chkconfig: 2345 99 01 +# description: ovirt-early services +# +# Copyright (C) 2008 Red Hat, Inc. +# Written by Darryl L. Pierce <dpierce at redhat.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. A copy of the GNU General Public License is +# also available at http://www.gnu.org/copyleft/gpl.html. + +## 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-standalone-mode: " + + { + start + } + + test $? == 0 && success || failure + echo + ;; + + *) + echo "Usage: ovirt-early {start}" + exit 2 +esac -- 1.5.6.5