Yedidyah Bar David has uploaded a new change for review.

Change subject: packaging: setup: host rename
......................................................................

packaging: setup: host rename

Change-Id: I100a602a199bac576bd9fad9e180f0ddbfa0ea5b
Signed-off-by: Yedidyah Bar David <d...@redhat.com>
---
M ovirt-engine.spec.in
A packaging/setup/bin/ovirt-engine-rename
M packaging/setup/ovirt_engine_setup/constants.py
A packaging/setup/plugins/ovirt-engine-rename/core/__init__.py
A packaging/setup/plugins/ovirt-engine-rename/core/database.py
A packaging/setup/plugins/ovirt-engine-rename/core/hostname.py
A packaging/setup/plugins/ovirt-engine-rename/core/misc.py
A packaging/setup/plugins/ovirt-engine-rename/core/pki.py
A packaging/setup/plugins/ovirt-engine-rename/core/setup.py
A packaging/setup/plugins/ovirt-engine-rename/core/uninstall.py
10 files changed, 519 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/98/17098/1

diff --git a/ovirt-engine.spec.in b/ovirt-engine.spec.in
index a0cb07b..404384c 100644
--- a/ovirt-engine.spec.in
+++ b/ovirt-engine.spec.in
@@ -801,6 +801,7 @@
 # Setup
 %{engine_data}/setup/bin/ovirt-engine-setup
 %{engine_data}/setup/bin/ovirt-engine-remove
+%{engine_data}/setup/bin/ovirt-engine-rename
 %{engine_data}/setup/bin/ovirt-engine-setup.env
 %{engine_data}/setup/ovirt_engine_setup/*.py*
 %{engine_data}/setup/plugins/*/*/*.py*
diff --git a/packaging/setup/bin/ovirt-engine-rename 
b/packaging/setup/bin/ovirt-engine-rename
new file mode 100755
index 0000000..ba097c7
--- /dev/null
+++ b/packaging/setup/bin/ovirt-engine-rename
@@ -0,0 +1,79 @@
+#!/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.
+#
+
+die() {
+       local m="$1"
+       echo "FATAL: ${m}" >&2
+       exit 1
+}
+
+usage() {
+       cat << __EOF__
+Usage: $0
+    --log=file
+        write log to this file.
+    --config=file
+        Load configuration files.
+    --config-append=file
+        Load extra configuration files.
+    --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-setup:ovirt-engine-rename"
+otopienv=""
+environment=""
+
+environment="${environment} OVESETUP_CORE/offlinePackager=bool:True"
+
+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}"
+               ;;
+               --help)
+                       usage
+               ;;
+               *)
+                       die "Invalid option '${x}'"
+               ;;
+       esac
+done
+
+OTOPI_NONROOT=1 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 09ed76f..adaf305 100644
--- a/packaging/setup/ovirt_engine_setup/constants.py
+++ b/packaging/setup/ovirt_engine_setup/constants.py
@@ -85,6 +85,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_IPTABLES_EXAMPLE = os.path.join(
         OVIRT_ENGINE_SYSCONFDIR,
@@ -569,6 +570,7 @@
     ACTION_SETUP = 'setup'
     ACTION_REMOVE = 'cleanup'
     ACTION_UPGRADE = 'upgrade'
+    ACTION_RENAME = 'rename'
 
 
 @util.export
@@ -935,6 +937,19 @@
 @util.export
 @util.codegen
 @osetupattrsclass
+class RenameEnv(object):
+    @osetupattrs(
+        answerfile=True,
+        summary=True,
+        description=_('New FQDN'),
+    )
+    def FQDN(self):
+        return 'OSETUP_RENAME/fqdn'
+
+
+@util.export
+@util.codegen
+@osetupattrsclass
 class AIOEnv(object):
     ENABLE = 'OVESETUP_AIO/enable'
 
diff --git a/packaging/setup/plugins/ovirt-engine-rename/core/__init__.py 
b/packaging/setup/plugins/ovirt-engine-rename/core/__init__.py
new file mode 100644
index 0000000..6560f21
--- /dev/null
+++ b/packaging/setup/plugins/ovirt-engine-rename/core/__init__.py
@@ -0,0 +1,37 @@
+#
+# 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 release preview plugin."""
+
+
+from otopi import util
+
+
+from . import misc
+from . import pki
+from . import hostname
+
+
+@util.export
+def createPlugins(context):
+    misc.Plugin(context=context)
+    hostname.Plugin(context=context)
+    #pki.Plugin(context=context)
+
+
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git a/packaging/setup/plugins/ovirt-engine-rename/core/database.py 
b/packaging/setup/plugins/ovirt-engine-rename/core/database.py
new file mode 100644
index 0000000..54bc577
--- /dev/null
+++ b/packaging/setup/plugins/ovirt-engine-rename/core/database.py
@@ -0,0 +1,2 @@
+#update database vdc_options
+#dwh and report URLs?!?!
diff --git a/packaging/setup/plugins/ovirt-engine-rename/core/hostname.py 
b/packaging/setup/plugins/ovirt-engine-rename/core/hostname.py
new file mode 100644
index 0000000..9b987ca
--- /dev/null
+++ b/packaging/setup/plugins/ovirt-engine-rename/core/hostname.py
@@ -0,0 +1,42 @@
+#
+# 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.
+#
+
+
+"""Hostname plugin."""
+
+from otopi import util
+from otopi import plugin
+
+
+from ovirt_engine_setup import constants as osetupcons
+
+
+@util.export
+class Plugin(plugin.PluginBase):
+    """Hostname plugin."""
+    @plugin.event(
+        stage=plugin.Stages.STAGE_CUSTOMIZATION,
+        before=[
+            osetupcons.Stages.CONFIG_PROTOCOLS_CUSTOMIZATION,
+        ],
+    )
+    def _customization(self):
+        # This forces hostname.py from ovirt-engine-setup to run
+        self.environment[osetupcons.ConfigEnv.FQDN] = None
+
+
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git a/packaging/setup/plugins/ovirt-engine-rename/core/misc.py 
b/packaging/setup/plugins/ovirt-engine-rename/core/misc.py
new file mode 100644
index 0000000..9a30bc8
--- /dev/null
+++ b/packaging/setup/plugins/ovirt-engine-rename/core/misc.py
@@ -0,0 +1,100 @@
+#
+# 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.
+#
+
+
+"""Misc plugin."""
+
+
+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,
+        ],
+    )
+    def _preinit(self):
+        self.environment.setdefault(
+            otopicons.CoreEnv.LOG_FILE_NAME_PREFIX,
+            osetupcons.FileLocations.OVIRT_OVIRT_RENAME_LOG_PREFIX
+        )
+        self.environment[
+            osetupcons.CoreEnv.ACTION
+        ] = osetupcons.Const.ACTION_RENAME
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_INIT,
+    )
+    def _init(self):
+        self.environment.setdefault(
+            osetupcons.RenameEnv.FQDN,
+            None
+        )
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_VALIDATION,
+        condition=lambda self: False,
+    )
+    def _validation(self):
+        if self.environment[
+            osetupcons.RenameEnv.FQDN
+        ] is None:
+            self.environment[
+                osetupcons.RenameEnv.FQDN
+            ] = self.dialog.queryString(
+                name='OVESETUP_RENAME_FQDN',
+                note=_('New fully qualified server name: '),
+                prompt=True,
+            )
+            # TODO validate host name syntax
+            # TODO check resolve?
+
+    @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=_(
+                'Rename completed successfully'
+            ),
+        )
+
+
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git a/packaging/setup/plugins/ovirt-engine-rename/core/pki.py 
b/packaging/setup/plugins/ovirt-engine-rename/core/pki.py
new file mode 100644
index 0000000..2b30337
--- /dev/null
+++ b/packaging/setup/plugins/ovirt-engine-rename/core/pki.py
@@ -0,0 +1,236 @@
+#
+# 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.
+#
+
+
+"""CA plugin."""
+
+
+import os
+import gettext
+_ = lambda m: gettext.dgettext(message=m, domain='ovirt-engine-setup')
+
+
+from M2Crypto import X509
+XN_FLAG_SEP_MULTILINE = 4 << 16
+
+
+from otopi import constants as otopicons
+from otopi import util
+from otopi import plugin
+from otopi import filetransaction
+
+
+from ovirt_engine_setup import constants as osetupcons
+from ovirt_engine_setup import dialog
+
+
+@util.export
+class Plugin(plugin.PluginBase):
+    """CA plugin."""
+
+    def __init__(self, context):
+        super(Plugin, self).__init__(context=context)
+        self._enabled = False
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_INIT,
+    )
+    def _init(self):
+        self.environment.setdefault(
+            osetupcons.PKIEnv.STORE_PASS,
+            osetupcons.Defaults.DEFAULT_PKI_STORE_PASS
+        )
+
+        self.environment[otopicons.CoreEnv.LOG_FILTER].append(
+            self.environment[
+                osetupcons.PKIEnv.STORE_PASS
+            ]
+        )
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_SETUP,
+        condition=lambda self: os.path.exists(
+            osetupcons.FileLocations.OVIRT_ENGINE_PKI_ENGINE_CA_CERT
+        )
+    )
+    def _setup(self):
+        self.command.detect('openssl')
+        self._enabled = True
+
+        # TODO: add files that we are going to touch
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_VALIDATION,
+        condition=lambda self: self._enabled,
+    )
+    def _aia(self):
+        x509 = X509.load_cert(
+            file=osetupcons.FileLocations.OVIRT_ENGINE_PKI_ENGINE_CA_CERT,
+            format=X509.FORMAT_PEM,
+        )
+
+        try:
+            authorityInfoAccess = x509.get_ext(
+                'authorityInfoAccess'
+            ).get_value()
+
+            self.logger.warning(_('AIA extension found in CA certificate'))
+            self.dialog.note(
+                text=_(
+                    'Please note:\n'
+                    'The certificate for the CA contains the\n'
+                    '"Authority Information Access" extension pointing\n'
+                    'to the old hostname:\n'
+                    '{aia}'
+                    'Currently this is harmless, but it might affect future\n'
+                    'upgrades. In version 3.3 the default was changed to\n'
+                    'create new CA certificate without this extension. If\n'
+                    'possible, it might be better to not rely on this\n'
+                    'program, and instead backup, cleanup and setup again\n'
+                    'cleanly.\n'
+                ).format(
+                    aia=authorityInfoAccess,
+                ),
+            )
+            if not dialog.queryBoolean(
+                dialog=self.dialog,
+                name='OVESETUP_RENAME_AIA_BYPASS',
+                note=_('Do you want to continue? (@VALUES@) [@DEFAULT@]: '),
+                prompt=True,
+            ):
+                raise RuntimeError(_('Aborted by user'))
+        except LookupError:
+            pass
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_MISC,
+        condition=lambda self: self._enabled,
+    )
+    def _apache(self):
+        # TODO
+        # this implementaiton is not transactional
+        # too many issues with legacy ca implementation
+        # need to work this out to allow transactional
+
+        rc, stdout, stder = self.execute(
+            args=(
+                self.command.get('openssl'),
+                'pkcs12',
+                '-in', (
+                    osetupcons.FileLocations.OVIRT_ENGINE_PKI_APACHE_STORE
+                ),
+                '-passin', 'pass:%s' % self.environment[
+                    osetupcons.PKIEnv.STORE_PASS
+                ],
+                '-nodes',
+                '-nokeys',
+            ),
+        )
+
+        while 'BEGIN CERTIFICATE' not in stdout[0]:
+            stdout = stdout[1:]
+
+        x509 = X509.load_cert_string(
+            string='\n'.join(stdout).encode('utf8'),
+            format=X509.FORMAT_PEM,
+        )
+        subject = x509.get_subject()
+        subject.get_entries_by_nid(
+            X509.X509_Name.nid['CN']
+        )[0].set_data(
+            self.environment[
+                osetupcons.RenameEnv.FQDN
+            ]
+        )
+
+        self.execute(
+            (
+                osetupcons.FileLocations.OVIRT_ENGINE_PKI_CA_ENROLL,
+                '--name=%s' % 'apache',
+                '--password=%s' % (
+                    self.environment[osetupcons.PKIEnv.STORE_PASS],
+                ),
+                '--subject=%s' % '/'+'/'.join(subject.as_text(
+                    flags=XN_FLAG_SEP_MULTILINE,
+                ).splitlines()),
+            ),
+        )
+
+        self.execute(
+            args=(
+                self.command.get('openssl'),
+                'pkcs12',
+                '-in', (
+                    osetupcons.FileLocations.OVIRT_ENGINE_PKI_APACHE_STORE
+                ),
+                '-passin', 'pass:%s' % self.environment[
+                    osetupcons.PKIEnv.STORE_PASS
+                ],
+                '-nodes',
+                '-nocerts',
+                '-out', (
+                    osetupcons.FileLocations.OVIRT_ENGINE_PKI_APACHE_KEY
+                ),
+            ),
+            logStreams=False,
+        )
+
+        self.environment[
+            osetupcons.ApacheEnv.NEED_RESTART
+        ] = True
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_MISC,
+        condition=lambda self: self._enabled,
+    )
+    def _config(self):
+        for config in (
+            osetupcons.FileLocations.OVIRT_ENGINE_PKI_CERT_TEMPLATE,
+            osetupcons.FileLocations.OVIRT_ENGINE_PKI_CERT_TEMPLATE[
+                :-len('.in')
+            ],
+            os.path.join(
+                os.path.dirname(
+                    osetupcons.FileLocations.OVIRT_ENGINE_PKI_CERT_TEMPLATE
+                ),
+                'cert.conf',
+            ),
+        ):
+            with open(config, 'r') as f:
+                content = []
+                for line in f:
+                    if line.startswith('authorityInfoAccess'):
+                        line = (
+                            'authorityInfoAccess = '
+                            'caIssuers;URI:http://%s:%s/ca.crt'
+                        ) % (
+                            self.environment[
+                                osetupcons.RenameEnv.FQDN
+                            ],
+                            '80',  # TODO: get from config
+                        )
+                    content.append(line)
+
+            self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append(
+                filetransaction.FileTransaction(
+                    name=config,
+                    content=content,
+                )
+            )
+
+
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git a/packaging/setup/plugins/ovirt-engine-rename/core/setup.py 
b/packaging/setup/plugins/ovirt-engine-rename/core/setup.py
new file mode 100644
index 0000000..c25c7a3
--- /dev/null
+++ b/packaging/setup/plugins/ovirt-engine-rename/core/setup.py
@@ -0,0 +1,3 @@
+#read current config extract http port
+#it can be either http port or proxy port depend on what initialized
+#this should be added to environment to be used by pki module
diff --git a/packaging/setup/plugins/ovirt-engine-rename/core/uninstall.py 
b/packaging/setup/plugins/ovirt-engine-rename/core/uninstall.py
new file mode 100644
index 0000000..1176595
--- /dev/null
+++ b/packaging/setup/plugins/ovirt-engine-rename/core/uninstall.py
@@ -0,0 +1,4 @@
+#have env list holds all files that are about to be changed during the session
+#this will be extended in setup of every plugin
+#the plugin will take md5 snapshot of files before misc
+#then will create uninstall information for these who had md5 that matched the 
previous uninstall


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

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