Simone Tiraboschi has uploaded a new change for review. Change subject: setup: adding broker.conf, answerfile and he conf as VdcOptions ......................................................................
setup: adding broker.conf, answerfile and he conf as VdcOptions adding broker.conf, answerfile and he conf as VdcOptions: - injecting files and auto-adding with engine-config via cloud-init for automated setup - asking to the user to copy to the engine VM and add via engine-config for manual setup Change-Id: If0cb56e316c1a621ac2934473fde23b636005cbc Signed-off-by: Simone Tiraboschi <stira...@redhat.com> --- M src/plugins/ovirt-hosted-engine-setup/core/answerfile.py M src/plugins/ovirt-hosted-engine-setup/core/conf.py M src/plugins/ovirt-hosted-engine-setup/core/misc.py M src/plugins/ovirt-hosted-engine-setup/ha/ha_notifications.py M src/plugins/ovirt-hosted-engine-setup/vm/cloud_init.py 5 files changed, 129 insertions(+), 18 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-setup refs/changes/08/41908/1 diff --git a/src/plugins/ovirt-hosted-engine-setup/core/answerfile.py b/src/plugins/ovirt-hosted-engine-setup/core/answerfile.py index c28fcbe..342db64 100644 --- a/src/plugins/ovirt-hosted-engine-setup/core/answerfile.py +++ b/src/plugins/ovirt-hosted-engine-setup/core/answerfile.py @@ -24,6 +24,7 @@ import datetime import gettext import os +import StringIO from otopi import common @@ -47,6 +48,24 @@ def __init__(self, context): super(Plugin, self).__init__(context=context) + def _generate_answers(self, f): + f.write('[environment:default]\n') + for c in ohostedcons.__dict__['__hosted_attrs__']: + for k in c.__dict__.values(): + if hasattr(k, '__hosted_attrs__'): + if k.__hosted_attrs__['answerfile']: + k = k.fget(None) + if k in self.environment: + v = self.environment[k] + f.write( + '%s=%s:%s\n' % ( + k, + common.typeName(v), + '\n'.join(v) if isinstance(v, list) + else v, + ) + ) + def _save_answers(self, name): self.logger.info( _("Generating answer file '{name}'").format( @@ -55,22 +74,7 @@ ) path = self.resolveFile(name) with open(path, 'w') as f: - f.write('[environment:default]\n') - for c in ohostedcons.__dict__['__hosted_attrs__']: - for k in c.__dict__.values(): - if hasattr(k, '__hosted_attrs__'): - if k.__hosted_attrs__['answerfile']: - k = k.fget(None) - if k in self.environment: - v = self.environment[k] - f.write( - '%s=%s:%s\n' % ( - k, - common.typeName(v), - '\n'.join(v) if isinstance(v, list) - else v, - ) - ) + self._generate_answers(f) if self.environment[ohostedcons.CoreEnv.NODE_SETUP]: try: ohostedutil.persist(path) @@ -98,6 +102,23 @@ self._answers = [] @plugin.event( + stage=plugin.Stages.STAGE_MISC, + after=ohostedcons.Stages.STORAGE_AVAILABLE, + name=ohostedcons.Stages.ANSWER_FILE_AVAIABLE, + ) + def _misc(self): + # TODO: ensure to generate after latest env value modification + # otherwise that value will not be in the file copied to the engine VM + f = StringIO.StringIO() + try: + self._generate_answers(f) + self.environment[ + ohostedcons.NotificationsEnv.ANSWERFILE_CONTENT + ] = f.getvalue() + finally: + f.close() + + @plugin.event( stage=plugin.Stages.STAGE_CLEANUP, priority=plugin.Stages.PRIORITY_LAST, ) diff --git a/src/plugins/ovirt-hosted-engine-setup/core/conf.py b/src/plugins/ovirt-hosted-engine-setup/core/conf.py index 1abd940..e66c817 100644 --- a/src/plugins/ovirt-hosted-engine-setup/core/conf.py +++ b/src/plugins/ovirt-hosted-engine-setup/core/conf.py @@ -140,6 +140,9 @@ template=ohostedcons.FileLocations.OVIRT_HOSTED_ENGINE_TEMPLATE, subst=subst ) + self.environment[ + ohostedcons.CloudInit.HECONF_CONTENT + ] = content with transaction.Transaction() as localtransaction: localtransaction.append( filetransaction.FileTransaction( diff --git a/src/plugins/ovirt-hosted-engine-setup/core/misc.py b/src/plugins/ovirt-hosted-engine-setup/core/misc.py index e504c99..545b7b2 100644 --- a/src/plugins/ovirt-hosted-engine-setup/core/misc.py +++ b/src/plugins/ovirt-hosted-engine-setup/core/misc.py @@ -168,6 +168,28 @@ ), ) def _closeup(self): + if not self.environment[ohostedcons.CloudInit.EXECUTE_ESETUP]: + self.dialog.note( + text=_( + 'Please copy:\n' + ' 1 - {bcfile}\n' + ' 2 - {fhansfile}\n' + ' 3 - {heconffile}\n' + 'to the engine VM and than execute there:\n' + ' # engine-config -s HostedEngineBrokerConf="$(<r1)"\n' + ' # engine-config -s HostedEngineFHAnswerFile="$(<r2)"\n' + ' # engine-config -s HostedEngineHEConf="$(<r3)"\n' + 'substituting r1, r2 and r3 with the path ' + 'used on the engine VM for 1, 2 and 3' + ).format( + bcfile=ohostedcons.FileLocations.NOTIFY_CONF_FILE, + fhansfile=ohostedcons. + FileLocations.OVIRT_HOSTED_ENGINE_ANSWERS, + heconffile=ohostedcons. + FileLocations.OVIRT_HOSTED_ENGINE_SETUP_CONF, + ), + ) + self.dialog.note( text=_( 'Hosted Engine successfully set up' diff --git a/src/plugins/ovirt-hosted-engine-setup/ha/ha_notifications.py b/src/plugins/ovirt-hosted-engine-setup/ha/ha_notifications.py index eaa89f7..7dc74dd 100644 --- a/src/plugins/ovirt-hosted-engine-setup/ha/ha_notifications.py +++ b/src/plugins/ovirt-hosted-engine-setup/ha/ha_notifications.py @@ -101,6 +101,10 @@ ohostedcons.NotificationsEnv.DEST_EMAIL, None ) + self.environment.setdefault( + ohostedcons.NotificationsEnv.BROKER_CONF_CONTENT, + None + ) @plugin.event( stage=plugin.Stages.STAGE_CUSTOMIZATION, @@ -216,15 +220,21 @@ @plugin.event( stage=plugin.Stages.STAGE_MISC, condition=lambda self: self._enabled, + name=ohostedcons.Stages.BROKER_CONF_AVAIABLE, ) def _misc(self): f = StringIO.StringIO() try: self._cfg.write(f) + self.environment[ + ohostedcons.NotificationsEnv.BROKER_CONF_CONTENT + ] = f.getvalue() self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( filetransaction.FileTransaction( name=self._conffile, - content=f.getvalue(), + content=self.environment[ + ohostedcons.NotificationsEnv.BROKER_CONF_CONTENT + ], modifiedList=self.environment[ otopicons.CoreEnv.MODIFIED_FILES ], diff --git a/src/plugins/ovirt-hosted-engine-setup/vm/cloud_init.py b/src/plugins/ovirt-hosted-engine-setup/vm/cloud_init.py index b22ba28..d9d84a6 100644 --- a/src/plugins/ovirt-hosted-engine-setup/vm/cloud_init.py +++ b/src/plugins/ovirt-hosted-engine-setup/vm/cloud_init.py @@ -413,6 +413,14 @@ ohostedcons.VMEnv.AUTOMATE_VM_SHUTDOWN, None ) + self.environment.setdefault( + ohostedcons.CloudInit.ANSWERFILE_CONTENT, + None + ) + self.environment.setdefault( + ohostedcons.CloudInit.HECONF_CONTENT, + None + ) @plugin.event( stage=plugin.Stages.STAGE_SETUP, @@ -669,6 +677,11 @@ @plugin.event( stage=plugin.Stages.STAGE_MISC, + after=( + ohostedcons.Stages.BROKER_CONF_AVAIABLE, + ohostedcons.Stages.ANSWER_FILE_AVAIABLE, + ohostedcons.Stages.SAVE_CONFIG, + ), condition=lambda self: self._enable, ) def _misc(self): @@ -773,17 +786,41 @@ ' path: {heanswers}\n' ' owner: root:root\n' ' permissions: \'0640\'\n' + ' - content: |\n' + '{bccontent}\n' + ' path: {bcfile}\n' + ' owner: root:root\n' + ' permissions: \'0640\'\n' + ' - content: |\n' + '{fhanscontent}\n' + ' path: {fhansfile}\n' + ' owner: root:root\n' + ' permissions: \'0640\'\n' + ' - content: |\n' + '{heconfcontent}\n' + ' path: {heconffile}\n' + ' owner: root:root\n' + ' permissions: \'0640\'\n' 'runcmd:\n' ' - /usr/bin/engine-setup --offline' ' --config-append={applianceanswers}' ' --config-append={heanswers}' ' 1>{port}' - ' 2>&1\n' + ' 2>&1 &&' + ' engine-config -s HostedEngineBrokerConf="$(<{bcfile})" ' + ' 1>{port} 2>&1 && ' + ' engine-config -s HostedEngineFHAnswerFile="$(<{fhansfile})" ' + ' 1>{port} 2>&1 && ' + ' engine-config -s HostedEngineHEConf="$(<{heconffile})" ' + ' 1>{port} 2>&1 \n' ' - if [ $? -eq 0 ];' ' then echo "{success_string}" >{port};' ' else echo "{fail_string}" >{port};' ' fi\n' ' - rm {heanswers}\n' + ' - rm {bcfile}\n' + ' - rm {fhansfile}\n' + ' - rm {heconffile}\n' ).format( fqdn=self.environment[ ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN @@ -800,6 +837,24 @@ ), success_string=ohostedcons.Const.E_SETUP_SUCCESS_STRING, fail_string=ohostedcons.Const.E_SETUP_FAIL_STRING, + bcfile=ohostedcons.Const.CLOUD_INIT_BCFILE, + fhansfile=ohostedcons.Const.CLOUD_INIT_FHANSFILE, + heconffile=ohostedcons.Const.CLOUD_INIT_HECONFFILE, + bccontent='\n'.join([ + ' ' + line for line in self.environment[ + ohostedcons.NotificationsEnv.BROKER_CONF_CONTENT + ].split('\n') + ]), + fhanscontent='\n'.join([ + ' ' + line for line in self.environment[ + ohostedcons.CloudInit.ANSWERFILE_CONTENT + ].split('\n') + ]), + heconfcontent='\n'.join([ + ' ' + line for line in self.environment[ + ohostedcons.CloudInit.HECONF_CONTENT + ].split('\n') + ]) ) f = open(f_user_data, 'w') -- To view, visit https://gerrit.ovirt.org/41908 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If0cb56e316c1a621ac2934473fde23b636005cbc Gerrit-PatchSet: 1 Gerrit-Project: ovirt-hosted-engine-setup Gerrit-Branch: master Gerrit-Owner: Simone Tiraboschi <stira...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches