From 7aa825a8002cbc373f1f049488a394a3dbb5ec2a Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 2 Dec 2014 17:53:09 +0000 Subject: installer: read config in yaml now --- installer/installer.py | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/installer/installer.py b/installer/installer.py index af25876e..f9992b6e 100755 --- a/installer/installer.py +++ b/installer/installer.py @@ -20,16 +20,17 @@ import morphlib -import ConfigParser import os import re import sys import json +import yaml import subprocess import tempfile import errno import time import traceback +import stat class BaserockInstaller(): @@ -48,7 +49,8 @@ class BaserockInstaller(): rawdisk_path = morphlib.extensions._get_morph_extension_filename( 'rawdisk', '.write') - disk_dest, rootfs = self.check_and_read_config(self.config_file) + disk_dest, rootfs, postinstallcmd = self.check_and_read_config( + self.config_file) self.validate_install_values(disk_dest, rootfs) deployment_config=self.get_deployment_config(rootfs) @@ -57,7 +59,7 @@ class BaserockInstaller(): deployment_config, rootfs, disk_dest) self.do_unmounts(mounted) - self.finish_and_reboot() + self.finish_installation(postinstallcmd) except BaseException, e: print traceback.format_exc() print "Something failed, opening shell..." @@ -93,11 +95,11 @@ class BaserockInstaller(): self.install_system(script) os.remove(script) - def finish_and_reboot(self): + def finish_installation(self, postinstallcmd): os.system("sync") - print "Rebooting in 5 seconds..." + print "Executing `%s` in 5 seconds..." % postinstallcmd time.sleep(5) - os.system("reboot -f") + os.system(postinstallcmd) def do_mounts(self, to_mount): mounted = [] @@ -122,21 +124,29 @@ class BaserockInstaller(): def check_and_read_config(self, config_file): print "Reading configuration from %s..." % config_file - config = ConfigParser.RawConfigParser() - config.read(config_file) - keys = ('device', 'rootfs') - device, rootfs = (self.read_option(config, 'install', key) + keys = ('INSTALLER_TARGET_STORAGE_DEVICE', + 'INSTALLER_ROOTFS_TO_INSTALL') + with open(config_file) as f: + config = yaml.load(f) + + device, rootfs = (self.read_option(config, key) for key in keys) - return device, rootfs + postinstallcmd = self.read_option(config, + 'INSTALLER_POST_INSTALL_COMMAND', + 'reboot -f') + return device, rootfs, postinstallcmd - def read_option(self, config, section, option): + def read_option(self, config, option, default_value=None): try: - value = config.get(section, option) - except: - value = raw_input("Option '%s.%s' missing, please enter a value: " - % (section, option)) - print "Option '%s.%s' with value '%s" % (section, option, value) + value = config[option] + except KeyError, e: + if default_value: + value = default_value + else: + value = raw_input("Option '%s' missing, please enter a value: " + % option) + print "Option '%s' with value '%s" % (option, value) return value def get_deployment_config(self, rootfs): -- cgit v1.2.1