Sandro Bonazzola has uploaded a new change for review. Change subject: packaging: allow interactive NFS exports cleanup with engine-cleanup-2 ......................................................................
packaging: allow interactive NFS exports cleanup with engine-cleanup-2 cleanup exportfs configuration only if requested. Change-Id: I16b5920f0cfc9f564aa92f7e0d5a6d33af5e0b44 Signed-off-by: Sandro Bonazzola <[email protected]> --- M packaging/setup/ovirt_engine_setup/constants.py A packaging/setup/plugins/ovirt-engine-remove/system/__init__.py A packaging/setup/plugins/ovirt-engine-remove/system/exportfs.py 3 files changed, 221 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/02/14702/1 diff --git a/packaging/setup/ovirt_engine_setup/constants.py b/packaging/setup/ovirt_engine_setup/constants.py index de05d4d..4726aa4 100644 --- a/packaging/setup/ovirt_engine_setup/constants.py +++ b/packaging/setup/ovirt_engine_setup/constants.py @@ -722,6 +722,12 @@ def FIREWALL_MANAGER(self): return 'OVESETUP_CONFIG/firewallManager' + @osetupattrs( + answerfile=True, + ) + def PRESERVE_EXPORTS(self): + return 'OVESETUP_CONFIG/preserveExports' + @util.export @util.codegen diff --git a/packaging/setup/plugins/ovirt-engine-remove/system/__init__.py b/packaging/setup/plugins/ovirt-engine-remove/system/__init__.py new file mode 100644 index 0000000..57cbcd7 --- /dev/null +++ b/packaging/setup/plugins/ovirt-engine-remove/system/__init__.py @@ -0,0 +1,33 @@ +# +# ovirt-engine-setup -- ovirt engine setup +# Copyright (C) 2013 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +"""ovirt-host-setup system plugin.""" + + +from otopi import util + + +from . import exportfs + + [email protected] +def createPlugins(context): + exportfs.Plugin(context=context) + + +# vim: expandtab tabstop=4 shiftwidth=4 diff --git a/packaging/setup/plugins/ovirt-engine-remove/system/exportfs.py b/packaging/setup/plugins/ovirt-engine-remove/system/exportfs.py new file mode 100644 index 0000000..12d4b31 --- /dev/null +++ b/packaging/setup/plugins/ovirt-engine-remove/system/exportfs.py @@ -0,0 +1,182 @@ +# +# ovirt-engine-setup -- ovirt engine setup +# Copyright (C) 2013 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +""" +ISO domain configuration plugin. +""" + +import configparser +import datetime +import gettext +import hashlib +import os +_ = lambda m: gettext.dgettext(message=m, domain='ovirt-engine-setup') + + +from otopi import util +from otopi import plugin + + +from ovirt_engine_setup import constants as osetupcons +from ovirt_engine_setup import dialog + + [email protected] +class Plugin(plugin.PluginBase): + """ + ISO domain removal plugin. + """ + def __init__(self, context): + super(Plugin, self).__init__(context=context) + self._enabled = False + self._uninstall_file = None + + def _digestFile(self, filename): + md5 = hashlib.new('md5') + with open(filename, 'rb') as f: + md5.update(f.read(1000)) + return md5.hexdigest() + + @plugin.event( + stage=plugin.Stages.STAGE_INIT, + ) + def _init(self): + self.environment.setdefault( + osetupcons.ConfigEnv.PRESERVE_EXPORTS, + None + ) + + @plugin.event( + stage=plugin.Stages.STAGE_SETUP, + ) + def _setup(self): + self._enabled = not self.environment[ + osetupcons.CoreEnv.DEVELOPER_MODE + ] + self.command.detect('exportfs') + + @plugin.event( + stage=plugin.Stages.STAGE_CUSTOMIZATION, + condition=lambda self: self._enabled + ) + def _customization(self): + if self.environment[osetupcons.ConfigEnv.PRESERVE_EXPORTS] is None: + self.environment[ + osetupcons.ConfigEnv.PRESERVE_EXPORTS + ] = dialog.queryBoolean( + dialog=self.dialog, + name='OVESETUP_UNEXPORT_ISO_DOMAIN', + note=_( + 'Do you want leave the ISO domain exported through NFS? ' + '(@VALUES@) [@DEFAULT@]: ' + ), + prompt=True, + true=_('Yes'), + false=_('No'), + default=False, + ) + + @plugin.event( + stage=plugin.Stages.STAGE_MISC, + condition=lambda self: self._enabled and self.environment[ + osetupcons.ConfigEnv.PRESERVE_EXPORTS + ], + priority=plugin.Stages.PRIORITY_HIGH, + ) + def _add_nfs_export_to_unremovable(self): + config = configparser.ConfigParser() + config.optionxform = str + unremovable = [ + osetupcons.FileLocations.NFS_EXPORT_FILE + ] + if os.path.exists(osetupcons.FileLocations.NFS_EXPORT_DIR): + unremovable.append(osetupcons.FileLocations.OVIRT_NFS_EXPORT_FILE) + + def _addFiles(section, files): + config.add_section(section) + for index, name in enumerate(sorted(set(files))): + if os.path.exists(name): + prefix = 'file.{index:03}'.format(index=index) + config.set( + section, + prefix + '.name', + name, + ) + config.set( + section, + prefix + '.md5', + self._digestFile(name), + ) + _addFiles( + 'files', + [] + ) + _addFiles( + 'unremovable', + unremovable, + ) + + self._uninstall_file = os.path.join( + osetupcons.FileLocations.OVIRT_ENGINE_UNINSTALL_DIR, + '%s-uninstall.conf' % ( + datetime.datetime.now().strftime('%Y%m%d%H%M%S'), + ), + ) + if not os.path.exists(os.path.dirname(self._uninstall_file)): + os.makedirs(os.path.dirname(self._uninstall_file)) + with open(self._uninstall_file, 'w') as confFile: + config.write(confFile) + + @plugin.event( + stage=plugin.Stages.STAGE_CLOSEUP, + condition=lambda self: self._enabled, + before=[ + osetupcons.Stages.DIALOG_TITLES_E_SUMMARY, + ], + after=[ + osetupcons.Stages.DIALOG_TITLES_S_SUMMARY, + ], + ) + def _closeup(self): + #avoid to protect exportfs next time if not requested again + if self._uninstall_file and os.path.exists(self._uninstall_file): + os.unlink(self._uninstall_file) + if self.environment[osetupcons.ConfigEnv.PRESERVE_EXPORTS]: + self.dialog.note( + text=_( + 'ISO NFS share are still available on this host.' + ), + ) + else: + rc, stdout, stderr = self.execute( + ( + self.command.get('exportfs'), + '-r', + '-a', + ), + raiseOnError=False, + ) + if rc != 0: + self.logger.error( + _('Could not refresh NFS exports ({code}: {error})').format( + code=rc, + error=stderr, + ) + ) + +# vim: expandtab tabstop=4 shiftwidth=4 -- To view, visit http://gerrit.ovirt.org/14702 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I16b5920f0cfc9f564aa92f7e0d5a6d33af5e0b44 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Sandro Bonazzola <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
