Sandro Bonazzola has uploaded a new change for review. Change subject: iscsi: add HE disk to the engine as direct lun ......................................................................
iscsi: add HE disk to the engine as direct lun Add Hosted Engine disk to the engine as direct lun. Change-Id: I9c5640bde713fc4d09cf74a7037c62e833495934 Bug-Url: https://bugzilla.redhat.com/1157243 Bug-Url: https://bugzilla.redhat.com/1157239 Bug-Url: https://bugzilla.redhat.com/1157238 Signed-off-by: Sandro Bonazzola <[email protected]> --- M src/ovirt_hosted_engine_setup/constants.py M src/plugins/ovirt-hosted-engine-setup/engine/Makefile.am M src/plugins/ovirt-hosted-engine-setup/engine/__init__.py A src/plugins/ovirt-hosted-engine-setup/engine/add_disk.py M src/plugins/ovirt-hosted-engine-setup/engine/add_host.py M src/plugins/ovirt-hosted-engine-setup/storage/iscsi.py 6 files changed, 146 insertions(+), 7 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-setup refs/changes/83/34783/1 diff --git a/src/ovirt_hosted_engine_setup/constants.py b/src/ovirt_hosted_engine_setup/constants.py index 5ddd7cf..7c413b3 100644 --- a/src/ovirt_hosted_engine_setup/constants.py +++ b/src/ovirt_hosted_engine_setup/constants.py @@ -374,6 +374,8 @@ def HOST_CLUSTER_NAME(self): return 'OVEHOSTED_ENGINE/clusterName' + TEMPORARY_CERT_FILE = 'OVEHOSTED_ENGINE/temporaryCertificate' + @util.export @util.codegen @@ -450,6 +452,8 @@ def VG_UUID(self): return 'OVEHOSTED_STORAGE/vgUUID' + GUID = 'OVEHOSTED_STORAGE/GUID' + @ohostedattrs( answerfile=True, summary=True, diff --git a/src/plugins/ovirt-hosted-engine-setup/engine/Makefile.am b/src/plugins/ovirt-hosted-engine-setup/engine/Makefile.am index 6e70058..0bb69ef 100644 --- a/src/plugins/ovirt-hosted-engine-setup/engine/Makefile.am +++ b/src/plugins/ovirt-hosted-engine-setup/engine/Makefile.am @@ -1,6 +1,6 @@ # # ovirt-hosted-engine-setup -- ovirt with a manager in a VM -# Copyright (C) 2013 Red Hat, Inc. +# Copyright (C) 2013-2014 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -28,6 +28,7 @@ __init__.py \ fqdn.py \ health.py \ + add_disk.py \ add_host.py \ os_install.py \ $(NULL) diff --git a/src/plugins/ovirt-hosted-engine-setup/engine/__init__.py b/src/plugins/ovirt-hosted-engine-setup/engine/__init__.py index 190d9f5..3aa9ee6 100644 --- a/src/plugins/ovirt-hosted-engine-setup/engine/__init__.py +++ b/src/plugins/ovirt-hosted-engine-setup/engine/__init__.py @@ -1,6 +1,6 @@ # # ovirt-hosted-engine-setup -- ovirt hosted engine setup -# Copyright (C) 2013 Red Hat, Inc. +# Copyright (C) 2013-2014 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -27,6 +27,7 @@ from . import os_install from . import fqdn from . import health +from . import add_disk from . import add_host @@ -35,6 +36,7 @@ os_install.Plugin(context=context) fqdn.Plugin(context=context) health.Plugin(context=context) + add_disk.Plugin(context=context) add_host.Plugin(context=context) diff --git a/src/plugins/ovirt-hosted-engine-setup/engine/add_disk.py b/src/plugins/ovirt-hosted-engine-setup/engine/add_disk.py new file mode 100644 index 0000000..72ad4f0 --- /dev/null +++ b/src/plugins/ovirt-hosted-engine-setup/engine/add_disk.py @@ -0,0 +1,118 @@ +# +# ovirt-hosted-engine-setup -- ovirt hosted engine setup +# Copyright (C) 2014 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# + + +""" +Hosted Engine Disk adder plugin. +""" + + +import gettext + + +import ovirtsdk.api +import ovirtsdk.xml +import ovirtsdk.infrastructure.errors + + +from otopi import util +from otopi import plugin + + +from ovirt_hosted_engine_setup import constants as ohostedcons + + +_ = lambda m: gettext.dgettext(message=m, domain='ovirt-hosted-engine-setup') + + [email protected] +class Plugin(plugin.PluginBase): + """ + Hosted Engine Disk adder plugin. + """ + + def __init__(self, context): + super(Plugin, self).__init__(context=context) + + @plugin.event( + stage=plugin.Stages.STAGE_CLOSEUP, + after=( + ohostedcons.Stages.HOST_ADDED, + ), + condition=( + lambda self: self.environment[ + ohostedcons.StorageEnv.DOMAIN_TYPE + ] == ohostedcons.DomainTypes.ISCSI and + not self.environment[ohostedcons.CoreEnv.IS_ADDITIONAL_HOST] + ), + ) + def _closeup(self): + lun = ovirtsdk.xml.params.LogicalUnit( + id=self.environment[ohostedcons.StorageEnv.GUID], + address=self.environment[ohostedcons.StorageEnv.ISCSI_IP_ADDR], + port=self.environment[ohostedcons.StorageEnv.ISCSI_PORT], + target=self.environment[ohostedcons.StorageEnv.ISCSI_TARGET], + username=self.environment[ohostedcons.StorageEnv.ISCSI_USER], + password=self.environment[ohostedcons.StorageEnv.ISCSI_PASSWORD], + ) + disk = ovirtsdk.xml.params.Disk( + alias='direct_lun', + description=self.environment[ohostedcons.StorageEnv.IMAGE_DESC], + interface='virtio_scsi', + sgio='unfiltered', + format='raw', + lun_storage=ovirtsdk.xml.params.Storage( + type_='iscsi', + logical_unit=[ + lun, + ], + ), + ) + try: + self.logger.debug('Connecting to the Engine') + engine_api = ovirtsdk.api.API( + url='https://{fqdn}/ovirt-engine/api'.format( + fqdn=self.environment[ + ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN + ], + ), + username='admin@internal', + password=self.environment[ + ohostedcons.EngineEnv.ADMIN_PASSWORD + ], + ca_file=self.environment[ + ohostedcons.EngineEnv.TEMPORARY_CERT_FILE + ], + ) + engine_api.disks.add(disk) + except ovirtsdk.infrastructure.errors.RequestError: + self.logger.debug( + 'Cannot add the Hosted Engine VM Disk to the engine', + exc_info=True, + ) + self.logger.error( + _('Cannot add the Hosted Engine VM Disk to the engine') + ) + raise RuntimeError( + _('Cannot add the Hosted Engine VM Disk to the engine') + ) + engine_api.disconnect() + + +# vim: expandtab tabstop=4 shiftwidth=4 diff --git a/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py b/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py index c2e70b3..12a8eb0 100644 --- a/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py +++ b/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py @@ -83,7 +83,6 @@ super(Plugin, self).__init__(context=context) self._ovirtsdk_api = ovirtsdk.api self._ovirtsdk_xml = ovirtsdk.xml - self.cert = None def _getPKICert(self): self.logger.debug('Acquiring ca.crt from the engine') @@ -99,10 +98,13 @@ content = urlObj.read() if content: self.logger.debug(content) - fd, self.cert = tempfile.mkstemp( + fd, cert = tempfile.mkstemp( prefix='engine-ca', suffix='.crt', ) + self.environment[ + ohostedcons.EngineEnv.TEMPORARY_CERT_FILE + ] = cert os.fchmod(fd, 0o600) with os.fdopen(fd, 'w') as fileobj: fileobj.write(content) @@ -296,6 +298,10 @@ ohostedcons.EngineEnv.HOST_CLUSTER_NAME, None ) + self.environment.setdefault( + ohostedcons.EngineEnv.TEMPORARY_CERT_FILE, + None + ) self._selinux_enabled = False @plugin.event( @@ -423,7 +429,9 @@ password=self.environment[ ohostedcons.EngineEnv.ADMIN_PASSWORD ], - ca_file=self.cert, + ca_file=self.environment[ + ohostedcons.EngineEnv.TEMPORARY_CERT_FILE + ], ) conn = vdscli.connect() @@ -565,8 +573,9 @@ stage=plugin.Stages.STAGE_CLEANUP, ) def _cleanup(self): - if self.cert is not None and os.path.exists(self.cert): - os.unlink(self.cert) + cert = self.environment[ohostedcons.EngineEnv.TEMPORARY_CERT_FILE] + if cert is not None and os.path.exists(cert): + os.unlink(cert) # vim: expandtab tabstop=4 shiftwidth=4 diff --git a/src/plugins/ovirt-hosted-engine-setup/storage/iscsi.py b/src/plugins/ovirt-hosted-engine-setup/storage/iscsi.py index 8903a56..5b8ddf6 100644 --- a/src/plugins/ovirt-hosted-engine-setup/storage/iscsi.py +++ b/src/plugins/ovirt-hosted-engine-setup/storage/iscsi.py @@ -350,6 +350,7 @@ self.environment[ ohostedcons.StorageEnv.VG_UUID ] = device['vgUUID'] + self.environment[ohostedcons.StorageEnv.GUID] = device['GUID'] @plugin.event( stage=plugin.Stages.STAGE_SETUP, @@ -393,6 +394,10 @@ ohostedcons.StorageEnv.VG_UUID, None ) + self.environment.setdefault( + ohostedcons.StorageEnv.GUID, + None + ) @plugin.event( stage=plugin.Stages.STAGE_CUSTOMIZATION, -- To view, visit http://gerrit.ovirt.org/34783 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9c5640bde713fc4d09cf74a7037c62e833495934 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-hosted-engine-setup Gerrit-Branch: master Gerrit-Owner: Sandro Bonazzola <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
