Sandro Bonazzola has uploaded a new change for review. Change subject: packaging: setup: allow automation for cluster ......................................................................
packaging: setup: allow automation for cluster Allow automation for cluster selection. Introduce a second answer file saving as last step of closeup stage, storing the cluster name selected for reusing it on additional hosts. Change-Id: I699dda9d1286b8d6f2e251a5f0ffcaa43725da21 Related-To: http://bugzilla.redhat.com/1059950 Related-To: http://bugzilla.redhat.com/1043906 Signed-off-by: Sandro Bonazzola <sbona...@redhat.com> --- M src/ovirt_hosted_engine_setup/constants.py M src/plugins/ovirt-hosted-engine-setup/core/answerfile.py M src/plugins/ovirt-hosted-engine-setup/engine/add_host.py 3 files changed, 71 insertions(+), 30 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-setup refs/changes/55/26355/1 diff --git a/src/ovirt_hosted_engine_setup/constants.py b/src/ovirt_hosted_engine_setup/constants.py index d189eaa..fcaf500 100644 --- a/src/ovirt_hosted_engine_setup/constants.py +++ b/src/ovirt_hosted_engine_setup/constants.py @@ -1,6 +1,6 @@ # # ovirt-hosted-engine-setup -- ovirt hosted engine setup -# Copyright (C) 2013 Red Hat, Inc. +# Copyright (C) 2013-2014 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -322,6 +322,12 @@ def APP_HOST_NAME(self): return 'OVEHOSTED_ENGINE/appHostName' + @ohostedattrs( + answerfile=True, + ) + def HOST_CLUSTER_NAME(self): + return 'OVEHOSTED_ENGINE/clusterName' + @util.export @util.codegen diff --git a/src/plugins/ovirt-hosted-engine-setup/core/answerfile.py b/src/plugins/ovirt-hosted-engine-setup/core/answerfile.py index 96cd94d..9fff9ee 100644 --- a/src/plugins/ovirt-hosted-engine-setup/core/answerfile.py +++ b/src/plugins/ovirt-hosted-engine-setup/core/answerfile.py @@ -42,22 +42,6 @@ def __init__(self, context): super(Plugin, self).__init__(context=context) - @plugin.event( - stage=plugin.Stages.STAGE_INIT, - ) - def _init(self): - self.environment.setdefault( - ohostedcons.CoreEnv.ANSWER_FILE, - ohostedcons.FileLocations.OVIRT_HOSTED_ENGINE_ANSWERS - ) - - @plugin.event( - stage=plugin.Stages.STAGE_VALIDATION, - priority=plugin.Stages.PRIORITY_LAST, - condition=lambda self: self.environment[ - ohostedcons.CoreEnv.ANSWER_FILE - ] is not None - ) def _save_answers(self): self.logger.info( _("Generating answer file '{name}'").format( @@ -87,5 +71,34 @@ ) ) + @plugin.event( + stage=plugin.Stages.STAGE_INIT, + ) + def _init(self): + self.environment.setdefault( + ohostedcons.CoreEnv.ANSWER_FILE, + ohostedcons.FileLocations.OVIRT_HOSTED_ENGINE_ANSWERS + ) + + @plugin.event( + stage=plugin.Stages.STAGE_VALIDATION, + priority=plugin.Stages.PRIORITY_LAST, + condition=lambda self: self.environment[ + ohostedcons.CoreEnv.ANSWER_FILE + ] is not None + ) + def _save_answers_at_validation(self): + self._save_answers() + + @plugin.event( + stage=plugin.Stages.STAGE_CLOSEUP, + priority=plugin.Stages.PRIORITY_LAST, + condition=lambda self: self.environment[ + ohostedcons.CoreEnv.ANSWER_FILE + ] is not None + ) + def _save_answers_at_closeup(self): + self._save_answers() + # vim: expandtab tabstop=4 shiftwidth=4 diff --git a/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py b/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py index 8f11a9f..36f8895 100644 --- a/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py +++ b/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py @@ -283,6 +283,10 @@ ohostedcons.EngineEnv.APP_HOST_NAME, None ) + self.environment.setdefault( + ohostedcons.EngineEnv.HOST_CLUSTER_NAME, + None + ) self._selinux_enabled = False @plugin.event( @@ -416,19 +420,37 @@ ca_file=self.cert, ) self.logger.debug('Adding the host to the cluster') - cluster_l = [c.get_name() for c in engine_api.clusters.list()] - cluster_name = default_cluster_name if default_cluster_name in \ - cluster_l else cluster_l[0] - cluster_name = self.dialog.queryString( - name='cluster_name', - note=_( - 'Enter the name of the cluster to which you want to add ' - 'the host (@VALUES@) [@DEFAULT@]: ' - ), - prompt=True, - default=cluster_name, - validValues=cluster_l, - ) + cluster_name = self.environment[ + ohostedcons.EngineEnv.HOST_CLUSTER_NAME + ] + if cluster_name is not None: + if cluster_name not in [ + c.get_name() + for c in engine_api.clusters.list() + ]: + raise RuntimeError( + _( + 'Specified cluster does not exist: {cluster}' + ).format( + cluster=cluster_name, + ) + ) + else: + cluster_l = [c.get_name() for c in engine_api.clusters.list()] + cluster_name = ( + default_cluster_name if default_cluster_name in + cluster_l else cluster_l[0] + ) + cluster_name = self.dialog.queryString( + name='cluster_name', + note=_( + 'Enter the name of the cluster to which you want to ' + 'add the host (@VALUES@) [@DEFAULT@]: ' + ), + prompt=True, + default=cluster_name, + validValues=cluster_l, + ) engine_api.hosts.add( self._ovirtsdk_xml.params.Host( name=self.environment[ -- To view, visit http://gerrit.ovirt.org/26355 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I699dda9d1286b8d6f2e251a5f0ffcaa43725da21 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-hosted-engine-setup Gerrit-Branch: master Gerrit-Owner: Sandro Bonazzola <sbona...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches