Douglas Schilling Landgraf has uploaded a new change for review.

Change subject: autoinstall: handle autoinstall params
......................................................................

autoinstall: handle autoinstall params

Currently the autoinstall registration flags belongs to vdsm-reg
which should be deprecated. This patch adds autoinstall script
to manage the below kernel args:

- management_server
- management_server_port
- rhevm_admin_password
- ovirt_vdsm_disable

Change-Id: Ibf664eb61344067427e4d88617dbbb7e8dd1d517
Signed-off-by: Douglas Schilling Landgraf <dougsl...@redhat.com>
---
M Makefile.am
A autoinstall/Makefile.am
A autoinstall/autoreg-args
A autoinstall/autoreg.py
M configure.ac
M ovirt-node-plugin-vdsm.spec.in
6 files changed, 138 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node-plugin-vdsm 
refs/changes/61/38161/1

diff --git a/Makefile.am b/Makefile.am
index 78ec56e..dfe9b01 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,7 +24,8 @@
 
 
 SUBDIRS = \
-  conf \
+       conf \
+       autoinstall \
        hooks \
        src \
        recipe
diff --git a/autoinstall/Makefile.am b/autoinstall/Makefile.am
new file mode 100644
index 0000000..4769ebb
--- /dev/null
+++ b/autoinstall/Makefile.am
@@ -0,0 +1,27 @@
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA  02110-1301, USA.  A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+pluginsargsdir = $(sysconfdir)/ovirt-commandline.d
+pyovirtconfigsetupdir =$(pythondir)/ovirt_config_setup
+
+dist_pyovirtconfigsetup_PYTHON = \
+       autoreg.py \
+       $(NULL)
+
+dist_pluginsargs_DATA = \
+       autoreg-args \
+       $(NULL)
diff --git a/autoinstall/autoreg-args b/autoinstall/autoreg-args
new file mode 100644
index 0000000..8568cc7
--- /dev/null
+++ b/autoinstall/autoreg-args
@@ -0,0 +1,5 @@
+management_server
+management_server_port
+management_server_fingerprint
+rhevm_admin_password
+ovirt_vdsm_disable
diff --git a/autoinstall/autoreg.py b/autoinstall/autoreg.py
new file mode 100644
index 0000000..6af3e6d
--- /dev/null
+++ b/autoinstall/autoreg.py
@@ -0,0 +1,101 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA  02110-1301, USA.  A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+import ovirtnode.ovirtfunctions as _functions
+
+from ovirt.node import log, utils
+from ovirt.node.config.defaults import SSH
+from ovirt.node.setup.vdsm import engine_page
+from ovirt.node.utils import system
+
+LOGGER = log.getLogger(__name__)
+ARGS = system.kernel_cmdline_arguments()
+
+
+def is_karg_set(key):
+    """ Check if the key was used as kernel argument """
+    if key in ARGS and len(ARGS[key]) > 0:
+        return ARGS[key]
+
+    return False
+
+
+if __name__ == "__main__":
+    LOGGER.info("== autoinstall: starting validation for kernel arguments ==")
+
+    kargs_opt = ["management_server",
+                 "management_server_port",
+                 "rhevm_admin_password"]
+
+    if "ovirt_vdsm_disable" in ARGS:
+        LOGGER.info("autoinstall: ovirt_vdsm_disabled is set, nothing to do!")
+        kargs_opt = []
+
+    for key in kargs_opt:
+        key_found = False
+        LOGGER.info("autoinstall: checking if kernel argument [%s] is set" % \
+                    key)
+        if "management_server" == key and is_karg_set("management_server"):
+            key_found = "management_server"
+            # Updating OVIRT_MANAGEMENT_SERVER in /etc/default/ovirt
+            engine_page.VDSM().update(server=ARGS["management_server"],
+                                      port=None,
+                                      cert_path=None)
+
+        elif "management_server_port" == key and \
+                is_karg_set("management_server_port"):
+            key_found = "management_server_port"
+
+            if not is_karg_set("management_server"):
+                LOGGER.error("To use management_server_port karg is required"
+                             " to set management_server key too!")
+            else:
+                # Updating OVIRT_MANAGEMENT_PORT in /etc/default/ovirt
+                engine_page.VDSM().update(server=ARGS["management_server"],
+                    port=ARGS["management_server_port"], cert_path=None)
+
+        # For rhevm_admin_password use:
+        # openssl passwd -1 to genereate the password
+        elif "rhevm_admin_password" == key and \
+                is_karg_set("rhevm_admin_password"):
+            key_found = "rhevm_admin_password"
+            try:
+                _functions.unmount_config("/etc/shadow")
+                _functions.unmount_config("/etc/passwd")
+                engine_page.execute_cmd("/usr/sbin/usermod -p %s root" % \
+                    ARGS["rhevm_admin_password"])
+
+                engine_page.execute_cmd("chage -E -1 root")
+                utils.fs.Config().persist("/etc/shadow")
+                utils.fs.Config().persist("/etc/passwd")
+                LOGGER.info("autoinstall: Password updated for user root!")
+            except:
+                LOGGER.error("autoinstall: Unable to update root password!")
+                raise
+
+            # Enable SSHD
+            SSH().update(pwauth=True)
+            SSH().commit()
+
+        if key_found:
+            LOGGER.info("autoinstall: kernel argument %s is set" % key_found)
+        else:
+            LOGGER.info("autoinstall: [%s] is not set" % key)
+
+    LOGGER.info("== autoinstall: finished ==")
diff --git a/configure.ac b/configure.ac
index 3f20b78..cd71f0a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -17,6 +17,7 @@
 AC_CONFIG_FILES([Makefile
                 src/Makefile
                 src/config.py
+                autoinstall/Makefile
                 conf/Makefile
                 hooks/Makefile
                 recipe/Makefile
diff --git a/ovirt-node-plugin-vdsm.spec.in b/ovirt-node-plugin-vdsm.spec.in
index 64d16a5..f87596d 100644
--- a/ovirt-node-plugin-vdsm.spec.in
+++ b/ovirt-node-plugin-vdsm.spec.in
@@ -92,6 +92,8 @@
 %{_libexecdir}/ovirt-node/hooks/on-boot/01-vdsm-configure
 %{_libexecdir}/ovirt-node/hooks/on-boot/02-vdsm-sebool-config
 %{_libexecdir}/ovirt-node/hooks/on-boot/90-start-vdsm
+%{_sysconfdir}/ovirt-commandline.d/autoreg-args
+%{python_sitelib}/ovirt_config_setup/autoreg.py*
 %{_sysconfdir}/ovirt-plugins.d
 %{_sysconfdir}/default/version.ovirt-node-plugin-vdsm
 


-- 
To view, visit https://gerrit.ovirt.org/38161
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibf664eb61344067427e4d88617dbbb7e8dd1d517
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node-plugin-vdsm
Gerrit-Branch: master
Gerrit-Owner: Douglas Schilling Landgraf <dougsl...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to