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

[Ovirt-devel] [PATCH] configure Cobbler instance in oVirt appliance



Minimal Fedora install tree is imported into the image during appliance creation,
at appliance firstboot Cobbler distro and profiles are created,
using non-mirrored repositories to save appliance disk space and setup time.

Cobbler entries for each "fake" oVirt Node in developer setup is added
if you add more oVirt Nodes, define them as Cobbler system:
  cobbler system add --name=NodeName --profile=oVirt-Node-x86_64 --mac=00:11:22:33:44:55 --netboot-enabled=1
otherwise they will PXE boot to the default Cobbler boot menu, where
oVirt Node can be manually choosen

Signed-off-by: Alan Pevec <apevec redhat com>
---
 wui-appliance/Makefile     |    9 +++++-
 wui-appliance/gettree.sh   |   31 ++++++++++++++++++
 wui-appliance/wui-devel.ks |   75 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 114 insertions(+), 1 deletions(-)
 create mode 100755 wui-appliance/gettree.sh

diff --git a/wui-appliance/Makefile b/wui-appliance/Makefile
index ea0bb61..ace0b8c 100644
--- a/wui-appliance/Makefile
+++ b/wui-appliance/Makefile
@@ -1,11 +1,13 @@
 NAME=ovirt-appliance
 YUMCACHE=$$(pwd)/../tmp/cache
+F_REL := $(shell rpm -q --qf '%{VERSION}' fedora-release)
+ARCH  := $(shell uname -i)
 
 appliance: $(NAME)-sda.raw
 
 appliance-compressed: $(NAME)-sda.qcow
 
-$(NAME)-sda.raw: wui-devel.ks common-install.ks common-pkgs.ks common-post.ks repos.ks
+$(NAME)-sda.raw: *.ks tmp/tree/.treeinfo
 	mkdir -p tmp
 	appliance-creator --config wui-devel.ks --name $(NAME) \
 	  --tmpdir="$$(pwd)/tmp" --cache="$(YUMCACHE)"
@@ -17,6 +19,11 @@ $(NAME)-sda.qcow: $(NAME)-sda.raw
 repos.ks: ../common/repos.ks.in
 	cp ../common/repos.ks.in repos.ks
 
+tmp/tree/.treeinfo:
+	mkdir -p tmp/tree
+	cd tmp/tree; ../../gettree.sh \
+	  http://download.fedoraproject.org/pub/fedora/linux/releases/$(F_REL)/Fedora/$(ARCH)/os
+
 clean:
 	rm -f repos.ks
 
diff --git a/wui-appliance/gettree.sh b/wui-appliance/gettree.sh
new file mode 100755
index 0000000..f6b01a8
--- /dev/null
+++ b/wui-appliance/gettree.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+# gettree.sh <Fedora release URL>
+#   Fedora release URL - Fedora base URL
+#     e.g. http://download.fedoraproject.org/pub/fedora/linux/releases/9/Fedora/x86_64/os
+#   download minimal Fedora tree: .treeinfo stage2 initrd and kernel
+
+download() {
+    local f=$1
+    wget --progress=dot:mega --continue $1
+    printf "."
+}
+
+if [ -z "$1" ]; then
+    cat >&2 << EOF
+Usage: $(basename "$0") <Fedora release URL>
+EOF
+    exit 1
+fi
+
+url=$1
+printf "Downloading minimal Fedora install tree from $url"
+set -e
+download $url/.treeinfo
+mkdir -p images/pxeboot
+cd images
+download $url/images/stage2.img
+cd pxeboot
+download $url/images/pxeboot/initrd.img
+download $url/images/pxeboot/vmlinuz
+echo "done"
diff --git a/wui-appliance/wui-devel.ks b/wui-appliance/wui-devel.ks
index 66927be..cb49b6b 100644
--- a/wui-appliance/wui-devel.ks
+++ b/wui-appliance/wui-devel.ks
@@ -290,3 +290,78 @@ chmod +x /etc/init.d/ovirt-wui-dev
 chkconfig ovirt-wui-dev on
 
 %end
+
+%post --nochroot
+  # distribution tree is ready in tmp/tree
+  set -e
+  python -c '
+from iniparse.ini import INIConfig
+ini = INIConfig()
+fp = open("tmp/tree/.treeinfo")
+ini.readfp(fp)
+fp.close()
+family = ini.general.family
+version = ini.general.version
+arch = ini.general.arch
+print "%s %s %s" % (family, version, arch)' | ( read os ver arch
+      dest=$INSTALL_ROOT/var/www/cobbler/ks_mirror/$os-$ver-$arch
+      printf "Importing $os-$ver-$arch ..."
+      cp -a tmp/tree $dest
+      cat >> $INSTALL_ROOT/etc/rc.d/rc.cobbler-import << EOF
+#!/bin/sh
+# Import Cobbler profiles on first boot
+
+exec > /root/cobbler-import.log 2>&1
+
+# run only once
+chmod -x \$0
+set -x
+cobbler import --name=$os-$ver --arch=$arch \
+  --path=/var/www/cobbler/ks_mirror/$os-$ver-$arch
+cobbler repo add --name=f9-$arch --arch=$arch --mirror-locally=0 \
+  --mirror=http://download.fedoraproject.org/pub/fedora/linux/releases/9/Everything/$arch/os
+cobbler repo add --name=f9-$arch-updates --arch=$arch --mirror-locally=0 \
+  --mirror=http://download.fedoraproject.org/pub/fedora/linux/updates/9/$arch
+cobbler profile edit --name=$os-$ver-$arch --repos="f9-$arch f9-$arch-updates"
+
+# TODO extract Node boot params from /var/lib/tftboot/pxelinux.cfg/default
+# before Cobbler overwrites it
+cobbler distro add --name="oVirt-Node-$arch" --arch=$arch \
+  --initrd=/var/lib/tftpboot/initrd0.img --kernel=/var/lib/tftpboot/vmlinuz0 \
+  --kopts="rootflags=loop root=/ovirt.iso rootfstype=iso9660 ro console=tty0 console=ttyS0,115200n8"
+cobbler profile add --name=oVirt-Node-$arch --distro=oVirt-Node-$arch
+cobbler system add --netboot-enabled=1 --profile=oVirt-Node-$arch \
+  --name=node3 --mac=00:16:3e:12:34:57
+cobbler system add --netboot-enabled=1 --profile=oVirt-Node-$arch \
+  --name=node4 --mac=00:16:3e:12:34:58
+cobbler system add --netboot-enabled=1 --profile=oVirt-Node-$arch \
+  --name=node5 --mac=00:16:3e:12:34:59
+set +x
+echo "Add new oVirt Nodes as Cobbler systems to make them PXE boot oVirt Node image directly."
+echo "Alternatively, choose oVirt-Node-$arch in default Cobbler boot menu."
+EOF
+      chmod +x $INSTALL_ROOT/etc/rc.d/rc.cobbler-import
+      echo "[ -x /etc/rc.d/rc.cobbler-import ] && /etc/rc.d/rc.cobbler-import" \
+            >> $INSTALL_ROOT/etc/rc.d/rc.local
+  echo done
+  )
+%end
+
+# Cobbler configuration
+%post
+  exec >> /root/kickstart-post.log 2>&1
+  # ovirt/ovirt
+  echo ovirt:Cobbler:68db208a546dcedf34edf0b4fe0ab1f2 > /etc/cobbler/users.digest
+  # make cobbler check happier
+  mkdir -p /etc/vsftpd
+  touch /etc/vsftpd/vsftpd.conf
+  mkdir -p /usr/lib/syslinux
+  cp /var/lib/tftpboot/pxelinux.0 /usr/lib/syslinux/pxelinux.0
+  # TODO use Augeas 0.3.0 Inifile lens
+  sed -i -e "s/^module = authn_denyall.*/module = authn_configfile/" \
+      /etc/cobbler/modules.conf
+  sed -i -e "s/^server:.*/server: '192.168.50.2'/" \
+         -e "s/^next_server:.*/next_server: '192.168.50.2'/" \
+      /etc/cobbler/settings
+  sed -i -e '/kernel /a \\tIPAPPEND 2' /etc/cobbler/pxesystem.template
+%end
-- 
1.5.5.1


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