[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Ovirt-devel] [PATCH ovirt-node] Allow the appliance to manage the hardware it is running on - part 2



From: Chris Lalancette <clalance redhat com>

    A rather large re-write of the ovirt-node.spec file.  The reason
    for this is so that we can introduce the concept of the "stateful" oVirt
    node; that is, one which is already installed and running with an OS.
    To accomplish this, we add two subpackages: ovirt-node-stateless,
    and ovirt-node-stateful.  They both depend on ovirt-node,
    which holds most of the necessary binaries.  The two subpackages have
    subtly different %post scripts, since you don't necessarily want to do all
    of the stuff from stateless on a stateful box.  There is also a minor change
    to common-pkgs to require ovirt-node-stateless, the addition of
    an init script for ovirt-node-stateful, and the addition of two
    helper scripts for the stateful case to let you turn your machine into
    an oVirt node.

    Signed-off-by: Chris Lalancette <clalance redhat com>
---
 ovirt-listen-awake/ovirt-convert-host      |   51 +++++++++++++++++
 ovirt-listen-awake/ovirt-listen-awake.init |   49 ++++++++++++++++
 ovirt-listen-awake/ovirt-unconvert-host    |   30 ++++++++++
 ovirt-node.spec                            |   85 ++++++++++++++++-----------
 scripts/ovirt-functions                    |   25 ++++++++
 5 files changed, 205 insertions(+), 35 deletions(-)
 create mode 100755 ovirt-listen-awake/ovirt-convert-host
 create mode 100644 ovirt-listen-awake/ovirt-listen-awake.init
 create mode 100755 ovirt-listen-awake/ovirt-unconvert-host

diff --git a/ovirt-listen-awake/ovirt-convert-host b/ovirt-listen-awake/ovirt-convert-host
new file mode 100755
index 0000000..0ef374d
--- /dev/null
+++ b/ovirt-listen-awake/ovirt-convert-host
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+. /etc/init.d/ovirt-functions
+
+if [ $# -ne 0 ]; then
+    echo "Usage: ovirt-convert-host"
+    exit 1
+fi
+
+backup_file() {
+    dir=$(dirname $1)
+    mkdir -p $OVIRT_BACKUP_DIR/${dir:1}
+    cp -pf $1 $OVIRT_BACKUP_DIR/${dir:1}
+}
+
+echo "This script will make a number of changes to your system to enable it to"
+echo "work as an oVirt node.  You can later undo these changes by"
+echo "running /usr/sbin/ovirt-unconvert-host.  Do you want to proceed? [y/N]?"
+read yesno
+
+if [ "$yesno" != "y" -a "$yesno" != "Y" ]; then
+    exit 2
+fi
+
+mkdir -p $OVIRT_BACKUP_DIR
+
+backup_file /etc/sysconfig/network
+sed -i -e 's/^HOSTNAME=.*/HOSTNAME=physical.priv.ovirt.org/' /etc/sysconfig/network
+
+backup_file /etc/hosts
+if [ $( grep -c "physical.priv.ovirt.org" /etc/hosts ) -eq 0 ]; then
+    echo "192.168.50.1 physical.priv.ovirt.org" >> /etc/hosts
+fi
+if [ $( grep -c "management.priv.ovirt.org" /etc/hosts ) -eq 0 ]; then
+    echo "192.168.50.2 management.priv.ovirt.org" >> /etc/hosts
+fi
+
+/sbin/chkconfig ovirt-listen-awake on
+/sbin/chkconfig collectd on
+
+backup_file /etc/sysconfig/libvirtd
+backup_file /etc/libvirt/qemu.conf
+backup_file /etc/libvirt/libvirtd.conf
+backup_file /etc/sasl2/libvirt.conf
+ovirt_setup_libvirtd
+
+backup_file /etc/sysconfig/iptables
+/usr/sbin/lokkit -n -t ovirtbr
+
+echo "Setup complete.  To make the changes take effect, shut down any running
+guests and reboot the host"
diff --git a/ovirt-listen-awake/ovirt-listen-awake.init b/ovirt-listen-awake/ovirt-listen-awake.init
new file mode 100644
index 0000000..a6bb78a
--- /dev/null
+++ b/ovirt-listen-awake/ovirt-listen-awake.init
@@ -0,0 +1,49 @@
+#!/bin/bash
+#
+#
+# ovirt-listen-awake       startup script for ovirt-listen-awake
+#
+# chkconfig: - 97 03
+# description: ovirt-listen-awake is a daemon to listen for requests from
+#    the ovirt VM manager.  When it receives one, it contacts the machine
+#    back with details so that it is added to the ovirt host pool.
+
+DAEMON=/usr/sbin/ovirt-listen-awake
+
+. /etc/init.d/functions
+
+start() {
+    echo -n "Starting ovirt-listen-awake: "
+    daemon $DAEMON
+    RETVAL=$?
+    echo
+}
+
+stop() {
+    echo -n "Shutting down ovirt-listen-awake: "
+    killproc ovirt-listen-awake
+    RETVAL=$?
+    echo
+}
+
+case "$1" in
+    start)
+	start
+	;;
+    stop)
+	stop
+	;;
+    restart)
+	stop
+	start
+	;;
+    status)
+	status $DAEMON
+	RETVAL=$?
+	;;
+    *)
+      echo "Usage: ovirt-listen-awake {start|stop|restart|status}"
+      exit 1
+  ;;
+esac
+exit $RETVAL
diff --git a/ovirt-listen-awake/ovirt-unconvert-host b/ovirt-listen-awake/ovirt-unconvert-host
new file mode 100755
index 0000000..cfaa51d
--- /dev/null
+++ b/ovirt-listen-awake/ovirt-unconvert-host
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+. /etc/init.d/ovirt-functions
+
+if [ $# -ne 0 ]; then
+    echo "Usage: ovirt-unconvert-host"
+    exit 1
+fi
+
+if [ ! -d $OVIRT_BACKUP_DIR ]; then
+    echo "The oVirt backup directory $OVIRT_BACKUP_DIR doesn't exist; can't"
+    echo "unconvert the host"
+    exit 2
+fi
+
+unbackup_file() {
+    # note that $1 will have a / on the front, so we don't need to add our own
+    cp -pf $OVIRT_BACKUP_DIR$1 $1
+}
+
+/sbin/chkconfig ovirt-listen-awake off
+/sbin/chkconfig collectd off
+
+unbackup_file /etc/sysconfig/network
+unbackup_file /etc/hosts
+unbackup_file /etc/sysconfig/libvirtd
+unbackup_file /etc/libvirt/qemu.conf
+unbackup_file /etc/libvirt/libvirtd.conf
+unbackup_file /etc/sasl2/libvirt.conf
+unbackup_file /etc/sysconfig/iptables
diff --git a/ovirt-node.spec b/ovirt-node.spec
index 736338d..d0a699c 100644
--- a/ovirt-node.spec
+++ b/ovirt-node.spec
@@ -15,6 +15,8 @@ BuildRequires:  libvirt-devel
 BuildRequires:  dbus-devel hal-devel
 Requires:       libvirt
 Requires:       hal
+Requires:       collectd
+Requires:       cyrus-sasl-gssapi
 ExclusiveArch:  %{ix86} x86_64
 
 %define app_root %{_datadir}/%{name}
@@ -23,6 +25,20 @@ ExclusiveArch:  %{ix86} x86_64
 Provides a series of daemons and support utilities to allow an
 oVirt Node to interact with the oVirt server.
 
+%package stateless
+Summary:  The oVirt Node scripts for stateless
+Group:    Applications/System
+Requires: %{name} = %{version}-%{release}
+%description stateless
+This package does configuration for a stateless oVirt Node.
+
+%package stateful
+Summary:  The oVirt node scripts for existing machines
+Group:    Applications/System
+Requires: %{name} = %{version}-%{release}
+%description stateful
+This package does configuration for a stateful oVirt node.
+
 %prep
 
 %setup -q
@@ -44,6 +60,9 @@ make
 %{__install} -p -m0755 scripts/ovirt-awake %{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-convert-host %{buildroot}%{_sbindir}
+%{__install} -Dp -m0755 ovirt-listen-awake/ovirt-unconvert-host %{buildroot}%{_sbindir}
 
 %{__install} -p -m0644 scripts/ovirt-functions %{buildroot}%{_initrddir}
 %{__install} -p -m0755 scripts/ovirt-early %{buildroot}%{_initrddir}
@@ -52,8 +71,6 @@ make
 
 %{__install} -p -m0644 scripts/collectd %{buildroot}%{_sysconfdir}/chkconfig.d
 %{__install} -p -m0644 scripts/collectd.conf.in %{buildroot}%{_sysconfdir}
-%{__install} -p -m0755 scripts/kvm-ifup %{buildroot}%{_sysconfdir}
-%{__install} -p -m0755 scripts/dhclient-exit-hooks %{buildroot}%{_sysconfdir}
 
 %{__install} -p -m0755 logrotate/ovirt-logrotate %{buildroot}%{_sysconfdir}/cron.hourly
 %{__install} -p -m0644 logrotate/ovirt-logrotate.conf %{buildroot}%{_sysconfdir}/logrotate.d
@@ -63,40 +80,25 @@ echo "oVirt Node release %{version}-%{release}" > %{buildroot}%{_sysconfdir}/ovi
 %clean
 %{__rm} -rf %{buildroot}
 
-%post
+%post stateful
+/sbin/chkconfig --add ovirt-listen-awake
+# 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
+
+%post stateless
 /sbin/chkconfig --add ovirt-early
 /sbin/chkconfig ovirt-early on
 /sbin/chkconfig --add ovirt
 /sbin/chkconfig ovirt on
 /sbin/chkconfig --add ovirt-post
 /sbin/chkconfig ovirt-post on
-/sbin/chkconfig --add collectd
-/sbin/chkconfig collectd on
-
-# just to get a boot warning to shut up
-touch /etc/resolv.conf
-
-# make libvirtd listen on the external interfaces
-sed -i -e "s/^#\(LIBVIRTD_ARGS=\"--listen\"\).*/\1/" /etc/sysconfig/libvirtd
 
-# set up qemu daemon to allow outside VNC connections
-sed -i -e "s/^[[:space:]]*#[[:space:]]*\(vnc_listen = \"0.0.0.0\"\).*/\1/" \
-    /etc/libvirt/qemu.conf
-
-# set up libvirtd to listen on TCP (for kerberos)
-sed -i -e "s/^[[:space:]]*#[[:space:]]*\(listen_tcp\)\>.*/\1 = 1/" \
-    -e "s/^[[:space:]]*#[[:space:]]*\(listen_tls\)\>.*/\1 = 0/" \
-    /etc/libvirt/libvirtd.conf
+. /etc/init.d/ovirt-functions ; ovirt_setup_libvirtd
 
 # make sure we don't autostart virbr0 on libvirtd startup
 rm -f /etc/libvirt/qemu/networks/autostart/default.xml
 
-# with the new libvirt (0.4.0), make sure we we setup gssapi in the mech_list
-if [ `egrep -c "^mech_list: gssapi" /etc/sasl2/libvirt.conf` -eq 0 ]; then
-    sed -i -e "s/^\([[:space:]]*mech_list.*\)/#\1/" /etc/sasl2/libvirt.conf
-    echo "mech_list: gssapi" >> /etc/sasl2/libvirt.conf
-fi
-
 # remove the /etc/krb5.conf file; it will be fetched on bootup
 rm -f /etc/krb5.conf
 
@@ -120,25 +122,22 @@ cat <<EOF > /etc/issue
 EOF
 cp -p /etc/issue /etc/issue.net
 
-%preun
+%preun stateless
 if [ "$1" = 0 ] ; then
   /sbin/chkconfig --del ovirt-early
   /sbin/chkconfig --del ovirt
   /sbin/chkconfig --del ovirt-post
 fi
 
+%preun stateful
+if [ "$1" = 0 ] ; then
+   /sbin/chkconfig --del ovirt-listen-awake
+fi
+
 %files
 %defattr(-,root,root,0755)
 %{_sbindir}/ovirt-awake
 %{_sbindir}/ovirt-identify-node
-%{_sbindir}/ovirt-listen-awake
-%{_initrddir}/ovirt-early
-%{_initrddir}/ovirt
-%{_initrddir}/ovirt-post
-%{_sysconfdir}/kvm-ifup
-%{_sysconfdir}/dhclient-exit-hooks
-%config %{_sysconfdir}/logrotate.d/ovirt-logrotate.conf
-%config %{_sysconfdir}/cron.hourly/ovirt-logrotate
 %defattr(-,root,root,0644)
 %{_initrddir}/ovirt-functions
 %{_sysconfdir}/collectd.conf.in
@@ -148,10 +147,26 @@ fi
 %doc ovirt-identify-node/AUTHOR ovirt-identify-node/ChangeLog
 %doc ovirt-identify-node/COPYING
 
+%files stateful
+%{_initrddir}/ovirt-listen-awake
+%{_sbindir}/ovirt-listen-awake
+%{_sbindir}/ovirt-convert-host
+%{_sbindir}/ovirt-unconvert-host
+
+%files stateless
+%config %{_sysconfdir}/logrotate.d/ovirt-logrotate.conf
+%config %{_sysconfdir}/cron.hourly/ovirt-logrotate
+%{_initrddir}/ovirt-early
+%{_initrddir}/ovirt
+%{_initrddir}/ovirt-post
+
 %changelog
-* Mon Sep  8 2008 Jim Meyering <meyering redhat com> - 0.92 0.6
+* Mon Sep  8 2008 Jim Meyering <meyering redhat com> - 0.92 0.7
 - Update ovirt-identify-node's build rule.
 
+* Thu Aug 28 2008 Chris Lalancette <clalance redhat com> - 0.92 0.6
+- Rewrite the whole spec to make sub-packages for stateless vs. stateful
+
 * Fri Aug 22 2008 Chris Lalancette <clalance redhat com> - 0.92 0.5
 - Add the ovirt-listen-awake daemon to the RPM
 
diff --git a/scripts/ovirt-functions b/scripts/ovirt-functions
index 083e13d..24a28df 100644
--- a/scripts/ovirt-functions
+++ b/scripts/ovirt-functions
@@ -5,6 +5,8 @@ OVIRT_LOGFILE=/var/log/ovirt.log
 # label of the oVirt partition
 OVIRT_LABEL=OVIRT
 
+OVIRT_BACKUP_DIR=/var/lib/ovirt-backup
+
 find_srv()
 {
     local dnsreply
@@ -21,3 +23,26 @@ die()
 {
     echo "$@" 1>&2; failure; echo 1>&2; exit 1
 }
+
+ovirt_setup_libvirtd() {
+    # just to get a boot warning to shut up
+    touch /etc/resolv.conf
+
+    # make libvirtd listen on the external interfaces
+    sed -i -e 's/^#\(LIBVIRTD_ARGS="--listen"\).*/\1/' \
+	/etc/sysconfig/libvirtd
+
+    # set up qemu daemon to allow outside VNC connections
+    sed -i -e 's/^[[:space:]]*#[[:space:]]*\(vnc_listen = "0.0.0.0"\).*/\1/' \
+	/etc/libvirt/qemu.conf
+    # set up libvirtd to listen on TCP (for kerberos)
+    sed -i -e "s/^[[:space:]]*#[[:space:]]*\(listen_tcp\)\>.*/\1 = 1/" \
+	-e "s/^[[:space:]]*#[[:space:]]*\(listen_tls\)\>.*/\1 = 0/" \
+	/etc/libvirt/libvirtd.conf
+
+    # with libvirt (0.4.0), make sure we we setup gssapi in the mech_list
+    if [ `egrep -c "^mech_list: gssapi" /etc/sasl2/libvirt.conf` -eq 0 ]; then
+	sed -i -e "s/^\([[:space:]]*mech_list.*\)/#\1/" /etc/sasl2/libvirt.conf
+	echo "mech_list: gssapi" >> /etc/sasl2/libvirt.conf
+    fi
+}
-- 
1.5.5.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]