Adam Litke has uploaded a new change for review. Change subject: Allow editing the VM mac address ......................................................................
Allow editing the VM mac address In order to give the user control of IP address assignment in DHCP environments it is important to allow the MAC address to be specified explicitly. Make MAC address a customizable parameter while still suggesting a default value for users who may not care. Change-Id: Ie75af322fc403809e0b044eb13561e6d16e1c4d4 Signed-off-by: Adam Litke <ali...@redhat.com> Bug-url: https://bugzilla.redhat.com/show_bug.cgi?id=1034706 --- M src/ovirt_hosted_engine_setup/constants.py M src/ovirt_hosted_engine_setup/util.py M src/plugins/ovirt-hosted-engine-setup/vm/Makefile.am M src/plugins/ovirt-hosted-engine-setup/vm/__init__.py M src/plugins/ovirt-hosted-engine-setup/vm/configurevm.py A src/plugins/ovirt-hosted-engine-setup/vm/mac.py 6 files changed, 131 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-setup refs/changes/25/22125/1 diff --git a/src/ovirt_hosted_engine_setup/constants.py b/src/ovirt_hosted_engine_setup/constants.py index b8f9549..bae66f5 100644 --- a/src/ovirt_hosted_engine_setup/constants.py +++ b/src/ovirt_hosted_engine_setup/constants.py @@ -395,6 +395,8 @@ @ohostedattrs( answerfile=True, + summary=True, + description=_('MAC address'), ) def MAC_ADDR(self): return 'OVEHOSTED_VM/vmMACAddr' diff --git a/src/ovirt_hosted_engine_setup/util.py b/src/ovirt_hosted_engine_setup/util.py index 8b8be3e..84230e6 100644 --- a/src/ovirt_hosted_engine_setup/util.py +++ b/src/ovirt_hosted_engine_setup/util.py @@ -53,6 +53,22 @@ return ':'.join(mac) +def validMAC(mac): + fields = mac.split(':') + if len(fields) != 6: + return False + for field in fields: + if len(field) != 2: + return False + try: + val = int(field, 16) + except ValueError: + return False + if val < 0 or val > 255: + return False + return True + + class VirtUserContext(object): """ Switch to vdsm:kvm user with provided umask diff --git a/src/plugins/ovirt-hosted-engine-setup/vm/Makefile.am b/src/plugins/ovirt-hosted-engine-setup/vm/Makefile.am index 3a075ff..563ba06 100644 --- a/src/plugins/ovirt-hosted-engine-setup/vm/Makefile.am +++ b/src/plugins/ovirt-hosted-engine-setup/vm/Makefile.am @@ -31,6 +31,7 @@ cpu.py \ configurevm.py \ image.py \ + mac.py \ machine.py \ memory.py \ runvm.py \ diff --git a/src/plugins/ovirt-hosted-engine-setup/vm/__init__.py b/src/plugins/ovirt-hosted-engine-setup/vm/__init__.py index 42e893a..04d3e57 100644 --- a/src/plugins/ovirt-hosted-engine-setup/vm/__init__.py +++ b/src/plugins/ovirt-hosted-engine-setup/vm/__init__.py @@ -29,6 +29,7 @@ from . import configurevm from . import cpu from . import image +from . import mac from . import machine from . import memory from . import runvm @@ -41,6 +42,7 @@ configurevm.Plugin(context=context) cpu.Plugin(context=context) image.Plugin(context=context) + mac.Plugin(context=context) machine.Plugin(context=context) memory.Plugin(context=context) runvm.Plugin(context=context) diff --git a/src/plugins/ovirt-hosted-engine-setup/vm/configurevm.py b/src/plugins/ovirt-hosted-engine-setup/vm/configurevm.py index 255eee4..54adeef 100644 --- a/src/plugins/ovirt-hosted-engine-setup/vm/configurevm.py +++ b/src/plugins/ovirt-hosted-engine-setup/vm/configurevm.py @@ -69,10 +69,6 @@ str(uuid.uuid4()) ) self.environment.setdefault( - ohostedcons.VMEnv.MAC_ADDR, - ohostedutil.randomMAC() - ) - self.environment.setdefault( ohostedcons.VMEnv.BOOT, None, ) diff --git a/src/plugins/ovirt-hosted-engine-setup/vm/mac.py b/src/plugins/ovirt-hosted-engine-setup/vm/mac.py new file mode 100644 index 0000000..396723b --- /dev/null +++ b/src/plugins/ovirt-hosted-engine-setup/vm/mac.py @@ -0,0 +1,110 @@ +# +# ovirt-hosted-engine-setup -- ovirt hosted engine setup +# Copyright (C) 2013 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 +# + + +""" +VM mac address configuration plugin. +""" + + +import gettext + + +from otopi import util +from otopi import plugin + + +from ovirt_hosted_engine_setup import constants as ohostedcons +from ovirt_hosted_engine_setup import util as ohostedutil + + +_ = lambda m: gettext.dgettext(message=m, domain='ovirt-hosted-engine-setup') + + +@util.export +class Plugin(plugin.PluginBase): + """ + VM mac address configuration plugin. + """ + + def __init__(self, context): + super(Plugin, self).__init__(context=context) + + @plugin.event( + stage=plugin.Stages.STAGE_INIT, + ) + def _init(self): + self.environment.setdefault( + ohostedcons.VMEnv.MAC_ADDR, + None + ) + + @plugin.event( + stage=plugin.Stages.STAGE_CUSTOMIZATION, + condition=lambda self: not self.environment[ + ohostedcons.CoreEnv.IS_ADDITIONAL_HOST + ], + after=( + ohostedcons.Stages.CONFIG_OVF_IMPORT, + ohostedcons.Stages.DIALOG_TITLES_S_VM, + ), + before=( + ohostedcons.Stages.DIALOG_TITLES_E_VM, + ), + ) + def _customization(self): + interactive = self.environment[ + ohostedcons.VMEnv.MAC_ADDR + ] is None + default_mac = ohostedutil.randomMAC() + valid = False + while not valid: + if interactive: + self.environment[ + ohostedcons.VMEnv.MAC_ADDR + ] = self.dialog.queryString( + name='ovehosted_vmenv_mac', + note=_( + 'You may specify a MAC address for the VM or ' + 'accept a randomly generated default [@DEFAULT@]: ' + ), + prompt=True, + default=default_mac, + ) + valid = ohostedutil.validMAC( + self.environment[ohostedcons.VMEnv.MAC_ADDR]) + if not valid and not interactive: + raise RuntimeError( + _('Invalid mac address specified: {mac}').format( + mac=self.environment[ + ohostedcons.VMEnv.MAC_ADDR + ], + ) + ) + if not valid and interactive: + self.logger.error( + _('Invalid mac address specified: {mac}').format( + mac=self.environment[ + ohostedcons.VMEnv.MAC_ADDR + ], + ) + ) + + +# vim: expandtab tabstop=4 shiftwidth=4 -- To view, visit http://gerrit.ovirt.org/22125 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie75af322fc403809e0b044eb13561e6d16e1c4d4 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-hosted-engine-setup Gerrit-Branch: ovirt-hosted-engine-setup-1.0 Gerrit-Owner: Adam Litke <ali...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches