Yedidyah Bar David has uploaded a new change for review. Change subject: packaging: add provisiondb ......................................................................
packaging: add provisiondb Change-Id: I02a141f2933b208375127cad156547350c41dd2b Signed-off-by: Yedidyah Bar David <d...@redhat.com> --- M packaging/bin/engine-backup.sh A packaging/setup/plugins/ovirt-engine-provisiondb/ovirt-engine-common/provisioning/__init__.py A packaging/setup/plugins/ovirt-engine-provisiondb/ovirt-engine-common/provisioning/postgres.py 3 files changed, 181 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/51/40451/1 diff --git a/packaging/bin/engine-backup.sh b/packaging/bin/engine-backup.sh index 0c9b6ba..28aeedb 100755 --- a/packaging/bin/engine-backup.sh +++ b/packaging/bin/engine-backup.sh @@ -174,6 +174,7 @@ --db-restore-jobs=JOBS Number of restore jobs for the Engine DB, when using custom dump format and compressor None. Passed to pg_restore -j. Defaults to 2. + --provision-db Create a postgresql database for the engine --change-db-credentials activate the following options, to restore the Engine database to a different location etc. If used, existing credentials are ignored. @@ -189,6 +190,7 @@ --dwh-db-compressor=COMPRESSOR for DWH, same options as --archive-compressor --dwh-db-dump-format=FORMAT for DWH, same options as --db-dump-format --dwh-db-restore-jobs=JOBS for DWH, same as --db-restore-jobs + --provision-dwb-db Create a postgresql database for DWH --change-dwh-db-credentials activate the following options, to restore the DWH database to a different location etc. If used, existing credentials are ignored. @@ -204,6 +206,7 @@ --reports-db-compressor=COMPRESSOR for Reports, same options as --archive-compressor --reports-db-dump-format=FORMAT for Reports, same options as --db-dump-format --reports-db-restore-jobs=JOBS for Reports, same as --db-restore-jobs + --provision-reports-db Create a postgresql database for Reports --change-reports-db-credentials activate the following options, to restore the Reports database to a different location etc. If used, existing credentials are ignored. @@ -270,6 +273,7 @@ DB_DUMP_COMPRESSOR= DB_DUMP_FORMAT=custom DB_RESTORE_JOBS=2 +PROVISION_DB= CHANGE_DB_CREDENTIALS= MY_DB_HOST= MY_DB_PORT=5432 @@ -283,6 +287,7 @@ DWH_DB_DUMP_COMPRESSOR= DWH_DB_DUMP_FORMAT=custom DWH_DB_RESTORE_JOBS=2 +PROVISION_DWH_DB= CHANGE_DWH_DB_CREDENTIALS= MY_DWH_DB_HOST= MY_DWH_DB_PORT=5432 @@ -296,6 +301,7 @@ REPORTS_DB_DUMP_COMPRESSOR= REPORTS_DB_DUMP_FORMAT=custom REPORTS_DB_RESTORE_JOBS=2 +PROVISION_REPORTS_DB= CHANGE_REPORTS_DB_CREDENTIALS= MY_REPORTS_DB_HOST= MY_REPORTS_DB_PORT=5432 @@ -425,6 +431,9 @@ DB_RESTORE_JOBS=$(parse_jobs "${v}") [ $? != 0 ] && logdie "failed parsing jobs" ;; + --provision-db) + PROVISION_DB=1 + ;; --change-db-credentials) CHANGE_DB_CREDENTIALS=1 ;; @@ -471,6 +480,9 @@ DWH_DB_RESTORE_JOBS=$(parse_jobs "${v}") [ $? != 0 ] && logdie "failed parsing jobs" ;; + --provision-dwh-db) + PROVISION_DWH_DB=1 + ;; --change-dwh-db-credentials) CHANGE_DWH_DB_CREDENTIALS=1 ;; @@ -516,6 +528,9 @@ --reports-db-restore-jobs=*) REPORTS_DB_RESTORE_JOBS=$(parse_jobs "${v}") [ $? != 0 ] && logdie "failed parsing jobs" + ;; + --provision-reports-db) + PROVISION_REPORTS_DB=1 ;; --change-reports-db-credentials) CHANGE_REPORTS_DB_CREDENTIALS=1 @@ -575,6 +590,7 @@ [ -e "${FILE}" ] || die "${FILE} does not exist" fi if [ -n "${CHANGE_DB_CREDENTIALS}" ]; then + [ -n "${PRIVION_DB}" ] && die "Cannot change credentials if provisioning a database" [ -n "${MY_DB_HOST}" ] || die "--db-host is missing" [ -n "${MY_DB_USER}" ] || die "--db-user is missing" [ -n "${MY_DB_PASSWORD}" ] || \ @@ -582,6 +598,7 @@ [ -n "${MY_DB_DATABASE}" ] || die "--db-name is missing" fi if [ -n "${CHANGE_DWH_DB_CREDENTIALS}" ]; then + [ -n "${PRIVION_DWH_DB}" ] && die "Cannot change credentials if provisioning a database" [ -n "${MY_DWH_DB_HOST}" ] || die "--dwh-db-host is missing" [ -n "${MY_DWH_DB_USER}" ] || die "--dwh-db-user is missing" [ -n "${MY_DWH_DB_PASSWORD}" ] || \ @@ -589,6 +606,7 @@ [ -n "${MY_DWH_DB_DATABASE}" ] || die "--dwh-db-name is missing" fi if [ -n "${CHANGE_REPORTS_DB_CREDENTIALS}" ]; then + [ -n "${PRIVION_REPORTS_DB}" ] && die "Cannot change credentials if provisioning a database" [ -n "${MY_REPORTS_DB_HOST}" ] || die "--reports-db-host is missing" [ -n "${MY_REPORTS_DB_USER}" ] || die "--reports-db-user is missing" [ -n "${MY_REPORTS_DB_PASSWORD}" ] || \ @@ -767,6 +785,23 @@ log "Reloading configuration" my_load_config + + if [ -n "${PRIVION_DB}" ]; then + TODO sysctl + write answer file to temp file + run provision-db with it, logdie if failed + fi + if [ -n "${PRIVION_DWH_DB}" ]; then + TODO sysctl + write answer file to temp file + run provision-db with it, logdie if failed + fi + if [ -n "${PRIVION_REPORTS_DB}" ]; then + TODO sysctl + write answer file to temp file + run provision-db with it, logdie if failed + fi + [ -n "${CHANGE_DB_CREDENTIALS}" ] && setMyEngineDBCredentials [ -n "${CHANGE_DWH_DB_CREDENTIALS}" ] && setMyDwhDBCredentials [ -n "${CHANGE_REPORTS_DB_CREDENTIALS}" ] && setMyReportsDBCredentials diff --git a/packaging/setup/plugins/ovirt-engine-provisiondb/ovirt-engine-common/provisioning/__init__.py b/packaging/setup/plugins/ovirt-engine-provisiondb/ovirt-engine-common/provisioning/__init__.py new file mode 100644 index 0000000..5204f84 --- /dev/null +++ b/packaging/setup/plugins/ovirt-engine-provisiondb/ovirt-engine-common/provisioning/__init__.py @@ -0,0 +1,33 @@ +# +# ovirt-engine-setup -- ovirt engine setup +# Copyright (C) 2015 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 pki plugin.""" + + +from otopi import util + + +from . import postgres + + +@util.export +def createPlugins(context): + postgres.Plugin(context=context) + + +# vim: expandtab tabstop=4 shiftwidth=4 diff --git a/packaging/setup/plugins/ovirt-engine-provisiondb/ovirt-engine-common/provisioning/postgres.py b/packaging/setup/plugins/ovirt-engine-provisiondb/ovirt-engine-common/provisioning/postgres.py new file mode 100644 index 0000000..484196b --- /dev/null +++ b/packaging/setup/plugins/ovirt-engine-provisiondb/ovirt-engine-common/provisioning/postgres.py @@ -0,0 +1,113 @@ +# +# ovirt-engine-setup -- ovirt engine setup +# Copyright (C) 2013-2015 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. +# + + +"""Local Postgres plugin.""" + + +import gettext + +from otopi import plugin, util + +from ovirt_engine_setup import constants as osetupcons +from ovirt_engine_setup import dialog +from ovirt_engine_setup.provisiondb import constants as oprovisioncons +from ovirt_engine_setup.engine_common import constants as oengcommcons +from ovirt_engine_setup.engine_common import postgres + + +def _(m): + return gettext.dgettext(message=m, domain='ovirt-engine-setup') + + +@util.export +class Plugin(plugin.PluginBase): + """Local Postgres plugin.""" + + def __init__(self, context): + super(Plugin, self).__init__(context=context) + self._renamedDBResources = False + self._provisioning = postgres.Provisioning( + plugin=self, + dbenvkeys=oprovisioncons.Const.PROVISION_DB_ENV_KEYS, + defaults=oprovisioncons.Const.DEFAULT_PROVISION_DB_ENV_KEYS, + ) + + @plugin.event( + stage=plugin.Stages.STAGE_SETUP, + ) + def _setup(self): + self._provisioning.detectCommands() + if not self._provisioning.supported(): + self.environment[EXIT_CODE] = prov_not_supported + raise RuntimeError('Provisioning not supported') + + @plugin.event( + stage=plugin.Stages.STAGE_CUSTOMIZATION, + ) + def _customization(self): + self.environment[oprovisioncons.EngineDBEnv.HOST] = 'localhost' + self.environment[ + oprovisioncons.EngineDBEnv.PORT + ] = oprovisioncons.Defaults.DEFAULT_DB_PORT + self._provisioning.applyEnvironment() + + @plugin.event( + stage=plugin.Stages.STAGE_VALIDATION, + ) + def _validation(self): + self._provisioning.validate() + + @plugin.event( + stage=plugin.Stages.STAGE_MISC, + after=( + # TODO take care of sysctl - move to common somehow or something like that + osetupcons.Stages.SYSTEM_SYSCTL_CONFIG_AVAILABLE, + ), + condition=lambda self: self._enabled, + ) + def _misc(self): + self._provisioning.provision() + + @plugin.event( + stage=plugin.Stages.STAGE_CLOSEUP, + before=( + osetupcons.Stages.DIALOG_TITLES_E_SUMMARY, + ), + after=( + osetupcons.Stages.DIALOG_TITLES_S_SUMMARY, + ), + condition=lambda self: self._provisioning.databaseRenamed, + ) + def _closeup(self): + self.dialog.note( + text=_( + 'Engine database resources:\n' + ' Database name: {database}\n' + ' Database user name: {user}\n' + ).format( + database=self.environment[ + oenginecons.EngineDBEnv.DATABASE + ], + user=self.environment[ + oenginecons.EngineDBEnv.USER + ], + ) + ) + + +# vim: expandtab tabstop=4 shiftwidth=4 -- To view, visit https://gerrit.ovirt.org/40451 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I02a141f2933b208375127cad156547350c41dd2b Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Yedidyah Bar David <d...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches