Yedidyah Bar David has uploaded a new change for review.

Change subject: packaging: Otopi-based engine-backup
......................................................................

packaging: Otopi-based engine-backup

Change-Id: I8f85a6228febc31297f57efdaee7fad76037f3cb
Bug-Url: https://bugzilla.redhat.com/1064503
Signed-off-by: Yedidyah Bar David <d...@redhat.com>
---
M ovirt-engine.spec.in
A packaging/setup/bin/ovirt-engine-backup
M packaging/setup/ovirt_engine_setup/constants.py
A packaging/setup/plugins/ovirt-engine-backup/base/__init__.py
A packaging/setup/plugins/ovirt-engine-backup/base/misc.py
A packaging/setup/plugins/ovirt-engine-backup/ovirt-engine/__init__.py
A packaging/setup/plugins/ovirt-engine-backup/ovirt-engine/backup_paths.py
7 files changed, 357 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/77/36377/1

diff --git a/ovirt-engine.spec.in b/ovirt-engine.spec.in
index c39e652..93cbdb1 100644
--- a/ovirt-engine.spec.in
+++ b/ovirt-engine.spec.in
@@ -999,6 +999,7 @@
 %{engine_data}/setup/bin/ovirt-engine-rename
 %{engine_data}/setup/bin/ovirt-engine-setup
 %{engine_data}/setup/bin/ovirt-engine-setup.env
+%{engine_data}/setup/bin/ovirt-engine-backup
 %{engine_data}/setup/ovirt_engine_setup/*.py*
 %{engine_data}/setup/plugins/*/base/
 %{engine_state}/backups/
diff --git a/packaging/setup/bin/ovirt-engine-backup 
b/packaging/setup/bin/ovirt-engine-backup
new file mode 100755
index 0000000..f83a00f
--- /dev/null
+++ b/packaging/setup/bin/ovirt-engine-backup
@@ -0,0 +1,78 @@
+#!/bin/sh
+#
+# 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.
+#
+
+usage() {
+       cat << __EOF__
+Usage: $0
+    --log=file
+        write log to this file.
+    --mode=mode
+        backup or restore
+    --config=file
+        Load configuration files.
+    --config-append=file
+        Load extra configuration files or answer file.
+    --generate-answer=file
+        Generate answer file.
+
+__EOF__
+       exit 1
+}
+
+script="$(readlink -f "$0")"
+scriptdir="$(dirname "${script}")"
+. "${scriptdir}/ovirt-engine-setup.env"
+baseenv="APPEND:BASE/pluginPath=str:${scriptdir}/../plugins 
APPEND:BASE/pluginGroups=str:ovirt-engine-common:ovirt-engine-backup"
+otopienv=""
+environment=""
+
+environment="${environment} OVESETUP_CORE/offlinePackager=bool:True 
PACKAGER/yumpackagerEnabled=bool:False"
+
+while [ -n "$1" ]; do
+       x="$1"
+       v="${x#*=}"
+       shift
+       case "${x}" in
+               --otopi-environment=*)
+                       otopienv="${v}"
+               ;;
+               --log=*)
+                       environment="${environment} CORE/logFileName=str:${v}"
+               ;;
+               --config=*)
+                       environment="${environment} 
APPEND:CORE/configFileName=str:${v}"
+               ;;
+               --config-append=*)
+                       environment="${environment} 
APPEND:CORE/configFileAppend=str:${v}"
+               ;;
+               --generate-answer=*)
+                       environment="${environment} 
OVESETUP_CORE/answerFile=str:${v}"
+               ;;
+               --mode=*)
+                       environment="${environment} OSETUP_BACKUP/mode=str:${v}"
+               ;;
+               --help)
+                       usage
+               ;;
+               *)
+                       die "Invalid option '${x}'"
+               ;;
+       esac
+done
+
+exec "${otopidir}/otopi" "${baseenv} ${environment} ${otopienv}"
diff --git a/packaging/setup/ovirt_engine_setup/constants.py 
b/packaging/setup/ovirt_engine_setup/constants.py
index 61f2fed..4a2c3be 100644
--- a/packaging/setup/ovirt_engine_setup/constants.py
+++ b/packaging/setup/ovirt_engine_setup/constants.py
@@ -89,6 +89,7 @@
     OVIRT_OVIRT_SETUP_LOG_PREFIX = 'ovirt-engine-setup'
     OVIRT_OVIRT_REMOVE_LOG_PREFIX = 'ovirt-engine-remove'
     OVIRT_OVIRT_RENAME_LOG_PREFIX = 'ovirt-engine-rename'
+    OVIRT_OVIRT_BACKUP_LOG_PREFIX = 'ovirt-engine-backup'
 
     OVIRT_OVIRT_SETUP_CONFIG_FILE = config.ENGINE_SETUP_CONFIG
     OVIRT_SETUP_OSINFO_REPOSITORY_DIR = os.path.join(
@@ -251,6 +252,7 @@
     ACTION_SETUP = 'setup'
     ACTION_REMOVE = 'cleanup'
     ACTION_RENAME = 'rename'
+    ACTION_BACKUP = 'backup'
     FIREWALL_MANAGER_HUMAN = 'skip'
     FIREWALL_MANAGER_IPTABLES = 'iptables'
     FIREWALL_MANAGER_FIREWALLD = 'firewalld'
@@ -480,6 +482,31 @@
 @util.export
 @util.codegen
 @osetupattrsclass
+class BackupEnv(object):
+    @osetupattrs(
+        answerfile=True,
+        summary=True,
+        description=_('Mode'),
+    )
+    def MODE(self):
+        return 'OSETUP_BACKUP/mode'
+
+    BACKUP_PATHS = 'OSETUP_BACKUP/backupPaths'
+    TEMP_FOLDER = 'OSETUP_BACKUP/tempFolder'
+    FILE = 'OSETUP_BACKUP/file'
+    FILES = 'files'
+
+
+@util.export
+@util.codegen
+@osetupattrsclass
+class RestoreEnv(object):
+    CHANGE_DB_CREDENTIALS = 'OSETUP_BACKUP/changeDBCredentials'
+
+
+@util.export
+@util.codegen
+@osetupattrsclass
 class RemoveEnv(object):
     @osetupattrs(
         answerfile=True,
diff --git a/packaging/setup/plugins/ovirt-engine-backup/base/__init__.py 
b/packaging/setup/plugins/ovirt-engine-backup/base/__init__.py
new file mode 100644
index 0000000..9bdee0c
--- /dev/null
+++ b/packaging/setup/plugins/ovirt-engine-backup/base/__init__.py
@@ -0,0 +1,33 @@
+#
+# ovirt-engine-setup -- ovirt engine setup
+# Copyright (C) 2014 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-engine-backup core plugin."""
+
+
+from otopi import util
+
+
+from . import misc
+
+
+@util.export
+def createPlugins(context):
+    misc.Plugin(context=context)
+
+
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git a/packaging/setup/plugins/ovirt-engine-backup/base/misc.py 
b/packaging/setup/plugins/ovirt-engine-backup/base/misc.py
new file mode 100644
index 0000000..fb5f7c3
--- /dev/null
+++ b/packaging/setup/plugins/ovirt-engine-backup/base/misc.py
@@ -0,0 +1,126 @@
+#
+# ovirt-engine-setup -- ovirt engine setup
+# Copyright (C) 2014 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.
+#
+
+
+"""Misc plugin."""
+
+
+import os
+import shutil
+import tempfile
+import gettext
+_ = lambda m: gettext.dgettext(message=m, domain='ovirt-engine-setup')
+
+
+from otopi import constants as otopicons
+from otopi import util
+from otopi import plugin
+
+
+from ovirt_engine_setup import constants as osetupcons
+
+
+@util.export
+class Plugin(plugin.PluginBase):
+    """Misc plugin."""
+
+    def __init__(self, context):
+        super(Plugin, self).__init__(context=context)
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_BOOT,
+        before=(
+            otopicons.Stages.CORE_LOG_INIT,
+        ),
+        priority=plugin.Stages.PRIORITY_HIGH - 10,
+    )
+    def _preinit(self):
+        self.environment.setdefault(
+            otopicons.CoreEnv.LOG_DIR,
+            osetupcons.FileLocations.OVIRT_SETUP_LOGDIR
+        )
+        self.environment.setdefault(
+            otopicons.CoreEnv.LOG_FILE_NAME_PREFIX,
+            osetupcons.FileLocations.OVIRT_OVIRT_BACKUP_LOG_PREFIX
+        )
+        self.environment[
+            osetupcons.CoreEnv.ACTION
+        ] = osetupcons.Const.ACTION_BACKUP
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_INIT,
+    )
+    def _init(self):
+        self.environment.setdefault(
+            osetupcons.BackupEnv.TEMP_FOLDER,
+            None
+        )
+        self._tempdir_created = True
+        self.environment.setdefault(
+            osetupcons.BackupEnv.BACKUP_PATHS,
+            []
+        )
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_MISC,
+    )
+    def _misc(self):
+        if self.environment[osetupcons.BackupEnv.TEMP_FOLDER] is None:
+            self.environment[
+                osetupcons.BackupEnv.TEMP_FOLDER
+            ] = tempfile.mkdtemp(prefix='engine-backup')  # prefix from env?
+        else:
+            tmp = self.environment[osetupcons.BackupEnv.TEMP_FOLDER]
+            if not os.path.exists(tmp):
+                os.makedirs(tmp, 0x700)
+            else:
+                if not os.listdir(tmp):
+                    self._tempdir_created = False
+                else:
+                    raise RuntimeError(
+                        _(
+                            "Temporary folder {tmp} is not empty"
+                        ).format(
+                            tmp=tmp,
+                        )
+                    )
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_CLOSEUP,
+        before=(
+            osetupcons.Stages.DIALOG_TITLES_E_SUMMARY,
+        ),
+        after=(
+            osetupcons.Stages.DIALOG_TITLES_S_SUMMARY,
+        ),
+    )
+    def _closeup(self):
+        self.dialog.note(
+            text=_(
+                'Backup completed successfully'
+            ),
+        )
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_CLEANUP,
+        condition=lambda self: self._tempdir_created,
+    )
+    def _cleanup(self):
+        shutil.rmtree(self.environment[osetupcons.BackupEnv.TEMP_FOLDER])
+
+
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git 
a/packaging/setup/plugins/ovirt-engine-backup/ovirt-engine/__init__.py 
b/packaging/setup/plugins/ovirt-engine-backup/ovirt-engine/__init__.py
new file mode 100644
index 0000000..ff66281
--- /dev/null
+++ b/packaging/setup/plugins/ovirt-engine-backup/ovirt-engine/__init__.py
@@ -0,0 +1,33 @@
+#
+# ovirt-engine-setup -- ovirt engine setup
+# Copyright (C) 2014 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-engine-backup ovirt-engine plugin."""
+
+
+from otopi import util
+
+
+from . import backup_paths
+
+
+@util.export
+def createPlugins(context):
+    backup_paths.Plugin(context=context)
+
+
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git 
a/packaging/setup/plugins/ovirt-engine-backup/ovirt-engine/backup_paths.py 
b/packaging/setup/plugins/ovirt-engine-backup/ovirt-engine/backup_paths.py
new file mode 100644
index 0000000..ad22b25
--- /dev/null
+++ b/packaging/setup/plugins/ovirt-engine-backup/ovirt-engine/backup_paths.py
@@ -0,0 +1,59 @@
+#
+# ovirt-engine-setup -- ovirt engine setup
+# Copyright (C) 2014 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.
+#
+
+
+"""Backup/Restore files/folders plugin."""
+
+
+import gettext
+_ = 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
+
+
+@util.export
+class Plugin(plugin.PluginBase):
+    """Misc plugin."""
+
+    def __init__(self, context):
+        super(Plugin, self).__init__(context=context)
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_SETUP,
+    )
+    def _setup(self):
+        self.environment[osetupcons.BackupEnv.BACKUP_PATHS].extend((
+            # TODO Use constants? path.join?
+            '/etc/ovirt-engine',
+            '/etc/pki/ovirt-engine',
+            '/etc/ovirt-engine-setup.conf.d',
+            '/var/lib/ovirt-engine',
+            '/etc/httpd/conf.d/ovirt-engine-root-redirect.conf',
+            '/etc/httpd/conf.d/ssl.conf',
+            '/etc/httpd/conf.d/z-ovirt-engine-proxy.conf',
+            '/etc/yum/pluginconf.d/versionlock.list',
+            '/etc/firewalld/services/ovirt-https.xml',
+            '/etc/firewalld/services/ovirt-http.xml',
+            '/etc/firewalld/services/ovirt-postgres.xml',
+        ))
+
+# vim: expandtab tabstop=4 shiftwidth=4


-- 
To view, visit http://gerrit.ovirt.org/36377
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8f85a6228febc31297f57efdaee7fad76037f3cb
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

Reply via email to