Fabian Deutsch has uploaded a new change for review. Change subject: [DRAFT] installer: Use transaction for auto-installation ......................................................................
[DRAFT] installer: Use transaction for auto-installation Change-Id: I26e93e6ec664a31810350dd8a25c86c6afe1e2eb Signed-off-by: Fabian Deutsch <[email protected]> --- M scripts/ovirt-auto-install.py M src/ovirtnode/network.py 2 files changed, 126 insertions(+), 79 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/90/15590/1 diff --git a/scripts/ovirt-auto-install.py b/scripts/ovirt-auto-install.py index cb2399f..f5523ef 100755 --- a/scripts/ovirt-auto-install.py +++ b/scripts/ovirt-auto-install.py @@ -18,7 +18,6 @@ # MA 02110-1301, USA. A copy of the GNU General Public License is # also available at http://www.gnu.org/copyleft/gpl.html. -import os import sys from ovirtnode.ovirtfunctions import * from ovirtnode.storage import * @@ -26,72 +25,119 @@ from ovirtnode.network import * from ovirtnode.log import * from ovirtnode.kdump import * -from ovirt.node.config import defaults -def config_networking(): - # network configuration - print "Configuring Network" - if OVIRT_VARS["OVIRT_BOOTIF"] != "": - network_auto() - if "OVIRT_HOSTNAME" in OVIRT_VARS: - cfg = defaults.Hostname() - tx = cfg.transaction() - tx() -# setup network before storage for iscsi installs -if is_iscsi_install(): - config_networking() +class AutomaticDiskPartitioning(Transaction.Element): + title = "Performing automatic disk partitioning" -if not is_stateless(): - print "Performing automatic disk partitioning" + def commit(self): + if storage_auto(): + # store /etc/shadow if adminpw/rootpw are set, + # handled already in ovirt-early + file = open("/proc/cmdline") + args = file.read() + if "adminpw" in args or "rootpw" in args: + print "Storing /etc/shadow" + ovirt_store_config("/etc/passwd") + ovirt_store_config("/etc/shadow") + file.close() + else: + raise RuntimeError("Automatic installation failed. " + + "Please review /var/log/ovirt.log") - if storage_auto(): - print "Completed automatic disk partitioning" - # store /etc/shadow if adminpw/rootpw are set, - # handled already in ovirt-early - file = open("/proc/cmdline") - args = file.read() - if "adminpw" in args or "rootpw" in args: - print "Storing /etc/shadow" - ovirt_store_config("/etc/passwd") - ovirt_store_config("/etc/shadow") - file.close() - else: - if not is_iscsi_install(): - config_networking() - print "Automatic installation failed. Please review /var/log/ovirt.log" + +class EnableSshPasswordAuthentication(Transaction.Element): + title = "Enabling SSH password authentication" + + def commit(self): + if OVIRT_VARS["OVIRT_SSH_PWAUTH"] == "yes": + augtool("set", + "/files/etc/ssh/sshd_config/PasswordAuthentication", + "yes") + elif OVIRT_VARS["OVIRT_SSH_PWAUTH"] == "no": + augtool("set", + "/files/etc/ssh/sshd_config/PasswordAuthentication", + "no") + ovirt_store_config("/etc/ssh/sshd_config") + system_closefds("service sshd restart &> /dev/null") + + +class ConfigureLogging(Transaction.Element): + title = "Configuring Logging" + + def commit(self): + logging_auto() + + +class ConfigureCollectd(Transaction.Element): + title = "Configuring Collectd" + + def commit(self): + try: + from ovirt_config_setup.collectd import * + collectd_auto() + except: + pass + + +class PerformInstallation(Transaction.Element): + title = "Transferring image" + + def commit(self): + Install() + + +class ConfigureKdump(Transaction.Element): + title = "Configuring KDump" + + def commit(self): + kdump_auto() + + +class InstallBootloader(Transaction.Element): + title = "Installing Bootloader" + + def commit(self): + install = Install() + if not install.ovirt_boot_setup(): + raise RuntimeError("Bootloader Installation Failed") + + +if __name__ == "__main__": + tx = Transaction("Automatic Installation") + + configure_network_tx = build_network_auto_transaction + + # setup network before storage for iscsi installs + if is_iscsi_install(): + tx.append(configure_network_tx) + + if not is_stateless(): + tx.append(AutomaticDiskPartitioning()) + + if not is_iscsi_install(): + tx.append(configure_network_tx) + + #set ssh_passwd_auth + if "OVIRT_SSH_PWAUTH" in OVIRT_VARS: + tx.append(EnableSshPasswordAuthentication()) + + tx.append(ConfigureLogging()) + + tx.append(ConfigureCollectd()) + + tx.append(PerformInstallation()) # FIXME needed?? + + tx.append(ConfigureKdump()) + + if not is_stateless(): + tx.append(InstallBootloader()) + + try: + TransactionProgress(txs, is_dry=False).run() + print "Installation and Configuration Completed" + except: + print "Installation and Configuration Failed" sys.exit(1) -if not is_iscsi_install(): - config_networking() -#set ssh_passwd_auth -if "OVIRT_SSH_PWAUTH" in OVIRT_VARS: - if OVIRT_VARS["OVIRT_SSH_PWAUTH"] == "yes": - augtool("set", "/files/etc/ssh/sshd_config/PasswordAuthentication", \ - "yes") - elif OVIRT_VARS["OVIRT_SSH_PWAUTH"] == "no": - augtool("set", "/files/etc/ssh/sshd_config/PasswordAuthentication", \ - "no") - ovirt_store_config("/etc/ssh/sshd_config") - system_closefds("service sshd restart &> /dev/null") - -# iscsi handled in install.py -print "Configuring Logging" -logging_auto() -try: - from ovirt_config_setup.collectd import * - print "Configuring Collectd" - collectd_auto() -except: - pass -install = Install() -print "Configuring KDump" -kdump_auto() -if not is_stateless(): - print "Installing Bootloader" - if install.ovirt_boot_setup(): - print "Bootloader Installation Completed" - else: - print "Bootloader Installation Failed" - sys.exit(1) - print "Installation and Configuration Completed" + sys.exit(0) diff --git a/src/ovirtnode/network.py b/src/ovirtnode/network.py index fe0e1fe..5b91590 100644 --- a/src/ovirtnode/network.py +++ b/src/ovirtnode/network.py @@ -56,6 +56,7 @@ from ovirt.node.config.defaults import Network return Network().commit() + def convert_to_biosdevname(): if not "BIOSDEVNAMES_CONVERSION" in OVIRT_VARS: # check for appropriate bios version @@ -111,21 +112,23 @@ return True -def network_auto(): - try: - from ovirt.node.config.defaults import Network, Nameservers, \ - Timeservers - from ovirt.node.utils.console import TransactionProgress +def build_network_auto_transaction(): + from ovirt.node.config.defaults import Network, Nameservers, \ + Timeservers, Hostname + from ovirt.node.utils.console import TransactionProgress - txs = Transaction("Automatic Installation") + txs = Transaction("Automatic Installation") - mnet = Network() - netmodel = mnet.retrieve() + mhostname = Hostname() + txs += mhostname.transaction() - logger.debug("Got netmodel: %s" % netmodel) - + mnet = Network() + netmodel = mnet.retrieve() + logger.debug("Got netmodel: %s" % netmodel) + if netmodel["iface"]: + # Only running net configuration if bootif is given # use dhcp if bootif is given - if netmodel["iface"] and not netmodel["ipaddr"]: + if not netmodel["ipaddr"]: netmodel.update(bootproto="dhcp") txs += mnet.transaction() @@ -136,7 +139,5 @@ mntp = Timeservers() txs += mntp.transaction() - TransactionProgress(txs, is_dry=False).run() - except: - logger.warn("Network Configuration Failed....") - return False + return txs + -- To view, visit http://gerrit.ovirt.org/15590 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I26e93e6ec664a31810350dd8a25c86c6afe1e2eb Gerrit-PatchSet: 1 Gerrit-Project: ovirt-node Gerrit-Branch: master Gerrit-Owner: Fabian Deutsch <[email protected]> _______________________________________________ node-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/node-patches
