[Ovirt-devel] [PATCH node] add install.py
Joey Boggs
jboggs at redhat.com
Tue Oct 26 17:32:33 UTC 2010
---
scripts/install.py | 247 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 247 insertions(+), 0 deletions(-)
create mode 100755 scripts/install.py
diff --git a/scripts/install.py b/scripts/install.py
new file mode 100755
index 0000000..ddffb53
--- /dev/null
+++ b/scripts/install.py
@@ -0,0 +1,247 @@
+#!/usr/bin/python
+#
+# install.py - configure local boot/root disk partitions
+
+# SYNOPSIS
+# ovirt-config-boot livecd_path bootparams reboot
+#
+# livecd_path - where livecd media is mounted,
+# parent of LiveOS and isolinux folders
+# default is /live
+#
+# bootparams - extra boot parameters like console=...
+# default is $OVIRT_BOOTPARAMS
+#
+# reboot - reboot after install
+# default is yes
+
+from ovirtfunctions import *
+import shutil
+import sys
+
+def ovirt_boot_setup():
+
+ log("installing the image.")
+
+ if OVIRT_VARS["OVIRT_ROOT_INSTALL"] == "n":
+ log("done.")
+ return
+
+ found_boot=False
+ rc = os.system("findfs LABEL=Boot 2>&1 >/dev/null")
+ if rc == 0:
+ found_boot = True
+ grub_dev_label = "Boot"
+ rc = os.system("findfs LABEL=Root 2>&1 >/dev/null")
+ if rc == 0:
+ found_boot = False
+ grub_dev_label = "Root"
+ if found_boot:
+ mount_boot()
+ if not os.path.ismount("/boot"):
+ log("Boot partition not available")
+ sys.exit(1)
+ # Grab OVIRT_ISCSI VARIABLES from boot partition for upgrading
+ # file created only if OVIRT_ISCSI_ENABLED=y
+ if os.path.exists("/boot/ovirt"):
+ try:
+ f = open("/boot/ovirt", 'r')
+ for line in f:
+ try:
+ line = line.strip()
+ key, value = line.split("\"", 1)
+ key = key.strip("=")
+ key = key.strip()
+ value = value.strip("\"")
+ OVIRT_VARS[key] = value
+ except:
+ pass
+ f.close()
+ iscsiadm_cmd = "iscsiadm -p %s:%s -m discovery -t sendtargets" % (OVIRT_VARS["OVIRT_ISCSI_TARGET_IP"], OVIRT_VARS["OVIRT_ISCSI_TARGET_PORT"])
+ os.system("iscsiadm_cmd")
+ log("Restarting iscsi service")
+ os.system("service iscsi restart")
+ except:
+ pass
+ else:
+ grub_dev_label="RootBackup"
+
+ # check that /boot mounted ok and find partition number for GRUB, $4 is to allow 0 as a partition number for grub
+ grub_part_info_cmd = "findfs LABEL=%s 2>/dev/null" % grub_dev_label
+ grub_part_info = subprocess.Popen(grub_part_info_cmd, shell=True, stdout=PIPE, stderr=STDOUT)
+ disk = grub_part_info.stdout.read()
+ disk = disk.rstrip(disk[-1:])
+ length = len(disk) - 1
+ partN = disk[length:]
+ partN = int(partN) - 1
+ disk = disk.rstrip(disk[-1:])
+
+ if disk is None and partN < 0:
+ log("unable to determine Root partition")
+ sys.exit(1)
+ if OVIRT_VARS.has_key("OVIRT_ISCSI_ENABLED") and OVIRT_VARS["OVIRT_ISCSI_ENABLED"] != "y":
+ mount_liveos()
+ if not os.path.ismount("/liveos"):
+ log("Root partition not available")
+ sys.exit(1)
+
+ # prepare Root partition update
+ candidate=""
+ if os.system("findfs LABEL=RootBackup 2>&1 >/dev/null"):
+ candidate = "RootBackup"
+ elif os.system("findfs LABEL=RootUpdate 2>&1 >/dev/null"):
+ candidate = "RootUpdate"
+ elif os.system("findfs LABEL=RootNew 2>&1 >/dev/null"):
+ candidate = "RootNew"
+ if candidate == "":
+ rc=1
+ elif candidate == "RootNew":
+ os.system("umount /liveos")
+ rc=0
+ else:
+ candidate_dev_cmd = "findfs LABEL=%s 2>/dev/null" % candidate
+ candidate_dev = subprocess.Popen(grub_part_info_cmd, shell=True, stdout=PIPE, stderr=STDOUT, stdin=PIPE)
+ candidate_dev = candidate_dev.stdout.read()
+ e2label_cmd = "e2label %s RootNew" % candidate_dev
+ rc = os.system(e2label_cmd)
+ if rc != 0:
+ log("root partition not available.")
+ label_debug = os.listdir("ls -al /dev/disk/by-label")
+ log(label_debug)
+ return rc
+ mount_cmd = "mount %s /liveos" % candidate_dev
+ os.system(mount_cmd)
+ os.system("rm -rf /liveos/LiveOS")
+ os.system("mkdir -p /liveos/LiveOS")
+
+ # install oVirt Node image for local boot
+ if os.path.exists("/live/syslinux"):
+ syslinux = "syslinux"
+ if os.path.exists("/live/isolinux"):
+ syslinux = "isolinux"
+ else:
+ syslinux=""
+
+ if OVIRT_VARS.has_key("OVIRT_ISCSI_ENABLED") and OVIRT_VARS["OVIRT_ISCSI_ENABLED"] == "y":
+ initrd_dest = "/boot"
+ grub_dir = "/boot/grub"
+ grub_prefix = "/grub"
+ else:
+ initrd_dest = "/liveos"
+ grub_dir = "/liveos/boot/grub"
+ grub_prefix = "/boot/grub"
+ if os.path.isdir(grub_dir):
+ shutil.rmtree(grub_dir)
+ if not os.path.exists(grub_dir):
+ os.makedirs(grub_dir)
+ os.system("cp -p /live/" + syslinux + "/vmlinuz0 " + initrd_dest)
+ rc = os.system("cp -p /live/" + syslinux + "/initrd0.img " + initrd_dest)
+ if rc != 0:
+ log("kernel image copy failed.")
+ return rc
+
+ if not OVIRT_VARS.has_key("OVIRT_ISCSI_ENABLED"):
+ rc = os.system("cp -p /live/LiveOS/squashfs.img /liveos/LiveOS")
+ if rc > 0:
+ log("squashfs image copy failed.")
+ return rc
+ version_cmd = "rpm -q --qf '%{version}' ovirt-node"
+ version = subprocess.Popen(version_cmd, shell=True, stdout=PIPE, stderr=STDOUT)
+ version = version.stdout.read()
+ release_cmd = "rpm -q --qf '%{version}' ovirt-node"
+ release = subprocess.Popen(release_cmd, shell=True, stdout=PIPE, stderr=STDOUT)
+ release = release.stdout.read()
+ # reorder tty0 to allow both serial and phys console after installation
+ if OVIRT_VARS.has_key("OVIRT_ISCSI_ENABLED") and OVIRT_VARS["OVIRT_ISCSI_ENABLED"] == "y":
+ bootparams="ro root=LABEL=ovirt-node-root roottypefs=ext3 console=tty0 \
+ netroot=iscsi:$OVIRT_ISCSI_TARGET_IP::$OVIRT_ISCSI_TARGET_PORT::$OVIRT_ISCSI_NODE_NAME ip=eth0:dhcp"
+ else:
+ bootparams="ro root=live:LABEL=Root roottypefs=ext3 console=tty0 \
+ $(echo $bootparams | sed s/console=tty0//g)"
+ grub_config_file = "%s/grub.conf" % grub_dir
+ GRUB_CONFIG_TEMPLATE = """
+default=0
+timeout=5
+hiddenmenu
+title oVirt Node (%(version)s-%(release)s)
+ root (hd0,%(partN)s)
+ kernel /vmlinuz0 %(bootparams)s
+ initrd /initrd0.img
+ """
+ device_map_conf = open(grub_dir + "/device.map\n", "w")
+ device_map_conf.write("(hd0) " + disk)
+ device_map_conf.close()
+ grub_files = ["stage1", "stage2", "e2fs_stage1_5"]
+ for file in grub_files:
+ os.system("cp /usr/share/grub/x86_64-redhat/" + file + " " + grub_dir)
+
+ GRUB_SETUP_TEMPLATE = """
+ grub --device-map=%(grub_dir)s/device.map
+root (hd0,%(partN)s)
+setup --prefix=%(grub_prefix)s (hd0)
+ """
+
+ grub_dict = {
+ "version" : version,
+ "release" : release,
+ "partN" : partN,
+ "bootparams" : bootparams,
+ "disk" : disk,
+ "grub_dir" : grub_dir,
+ "grub_prefix" : grub_prefix
+ }
+ grub_config_out = GRUB_CONFIG_TEMPLATE % grub_dict
+ grub_setup_out = GRUB_SETUP_TEMPLATE % grub_dict
+ grub_conf = open(grub_config_file, "w")
+ subprocess.Popen(grub_setup_out, shell=True, stdout=PIPE, stderr=STDOUT)
+ grub_conf.write(grub_config_out)
+ grub_conf.close()
+
+ if OVIRT_VARS.has_key("OVIRT_ISCSI_ENABLED") and OVIRT_VARS["OVIRT_ISCSI_ENABLED"] != "y":
+ os.system("umount /liveos")
+ # mark new Root ready to go, reboot() in ovirt-function switches it to active
+ e2label_cmd = "e2label %s RootUpdate" % candidate_dev
+ os.system(e2label_cmd)
+ os.system("rm -rf %s") % tmpdir
+ if OVIRT_VARS.has_key("OVIRT_ISCSI_ENABLED") and OVIRT_VARS["OVIRT_ISCSI_ENABLED"] == "y":
+ # copy default for when Root/HostVG is inaccessible(iscsi upgrade)
+ shutil.copy(OVIRT_DEFAULTS, "/boot")
+ log("done.")
+
+def Usage():
+
+ print "Usage: %s [livecd_path] [bootparams] [reboot(yes/no)]" % sys.argv[0]
+ print " livecd_path - where livecd media is mounted parent of LiveOS"
+ print " and isolinux folders default is /live"
+ print ""
+ print " bootparams - extra boot parameters like console=..."
+ print " default is \"$OVIRT_BOOTPARAMS\""
+ print ""
+ print " reboot - reboot after install, default is yes"
+ sys.exit(1)
+
+if len(sys.argv) < 3:
+ Usage()
+
+live = sys.argv[1]
+bootparams = sys.argv[2]
+try:
+ doreboot=sys.argv[3]
+ doreboot="no"
+except:
+ doreboot = "yes"
+
+if bootparams is None:
+ bootparams=OVIRT_VARS["OVIRT_BOOTPARAMS"]
+if doreboot == "":
+ doreboot="yes"
+
+if OVIRT_VARS["OVIRT_ROOT_INSTALL"] == "n":
+ log("done.")
+else:
+ rc = ovirt_boot_setup() #(live, bootparams)
+if rc == 0 and doreboot == "yes":
+ disable_firstboot()
+ if OVIRT_VARS["OVIRT_ISCSI_ENABLED"] != "y":
+ ovirt_store_firstboot_config()
+ reboot()
--
1.7.2.3
More information about the ovirt-devel
mailing list