Sandro Bonazzola has uploaded a new change for review. Change subject: Update engine's mgmt net to have the correct vlan id ......................................................................
Update engine's mgmt net to have the correct vlan id Up until now, when setting the management network over a vlan, the logical network in the engine would not be automatically updated to match the real configuration. This addresses the issue. Change-Id: Ica4c5804395d364438f1e142387376cc7adc7172 Bug-Url: https://bugzilla.redhat.com/1124207 Signed-off-by: Antoni S. Puimedon <[email protected]> (cherry picked from commit a6bd8963d3d82af57224227e5f2af7aef6cd3492) --- M src/ovirt_hosted_engine_setup/Makefile.am A src/ovirt_hosted_engine_setup/vds_info.py M src/plugins/ovirt-hosted-engine-setup/engine/add_host.py M src/plugins/ovirt-hosted-engine-setup/network/bridge.py 4 files changed, 109 insertions(+), 42 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-setup refs/changes/74/32374/1 diff --git a/src/ovirt_hosted_engine_setup/Makefile.am b/src/ovirt_hosted_engine_setup/Makefile.am index 0a986b4..a00d7df 100644 --- a/src/ovirt_hosted_engine_setup/Makefile.am +++ b/src/ovirt_hosted_engine_setup/Makefile.am @@ -45,6 +45,7 @@ tasks.py \ vm_status.py \ mixins.py \ + vds_info.py \ $(NULL) nodist_ovirthostedenginelib_PYTHON = \ diff --git a/src/ovirt_hosted_engine_setup/vds_info.py b/src/ovirt_hosted_engine_setup/vds_info.py new file mode 100644 index 0000000..011dcb9 --- /dev/null +++ b/src/ovirt_hosted_engine_setup/vds_info.py @@ -0,0 +1,78 @@ +# +# 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 +# + + +""" +vds utilities +""" + + +from vdsm import netinfo + + +def capabilities(conn): + """Returns a dictionary with the host capabilities""" + result = conn.getVdsCapabilities() + code, message = result['status']['code'], result['status']['message'] + if code != 0 or 'info' not in result: + raise RuntimeError( + 'Failed to get vds capabilities. Error code: ' + '"%s" message: "%s"' % (code, message) + ) + return result['info'] + + +def network(caps, device): + """Returns a dictionary that describes the network of the device""" + info = netinfo.NetInfo(caps) + attrs = {} + if device in info.vlans: + port_info = info.vlans[device] + attrs['vlan'] = port_info['vlanid'] + iface = port_info['iface'] + if iface in info.bondings: + attrs['bonding'] = iface + else: + attrs['nic'] = iface + elif device in info.bondings: + attrs['bonding'] = device + port_info = info.bondings[device] + elif device in info.nics: + attrs['nic'] = device + port_info = info.nics[device] + else: + raise RuntimeError( + 'The selected device %s is not a supported bridge ' + 'port' % device + ) + + if 'BOOTPROTO' in port_info['cfg']: + attrs['bootproto'] = port_info['cfg']['BOOTPROTO'] + if attrs.get('bootproto') == 'dhcp': + attrs['blockingdhcp'] = True + else: + attrs['ipaddr'] = port_info['addr'] + attrs['netmask'] = port_info['netmask'] + gateway = port_info.get('gateway') + if gateway is not None: + attrs['gateway'] = gateway + return attrs + + +# 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 62a1786..c2e70b3 100644 --- a/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py +++ b/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py @@ -46,7 +46,12 @@ from otopi import filetransaction +from vdsm import netinfo +from vdsm import vdscli + + from ovirt_hosted_engine_setup import constants as ohostedcons +from ovirt_hosted_engine_setup import vds_info _ = lambda m: gettext.dgettext(message=m, domain='ovirt-hosted-engine-setup') @@ -420,6 +425,23 @@ ], ca_file=self.cert, ) + + conn = vdscli.connect() + net_info = netinfo.NetInfo(vds_info.capabilities(conn)) + bridge_port = self.environment[ohostedcons.NetworkEnv.BRIDGE_IF] + if bridge_port in net_info.vlans: + self.logger.debug( + 'Updating engine\'s management network to be vlanned' + ) + vlan_id = net_info.vlans[bridge_port]['vlanid'] + mgmt_network = engine_api.networks.get( + name=self.environment[ohostedcons.NetworkEnv.BRIDGE_NAME] + ) + mgmt_network.set_vlan( + self._ovirtsdk_xml.params.VLAN(id=vlan_id) + ) + mgmt_network.update() + self.logger.debug('Adding the host to the cluster') cluster_name = self.environment[ ohostedcons.EngineEnv.HOST_CLUSTER_NAME diff --git a/src/plugins/ovirt-hosted-engine-setup/network/bridge.py b/src/plugins/ovirt-hosted-engine-setup/network/bridge.py index 3c35401..b62d21f 100644 --- a/src/plugins/ovirt-hosted-engine-setup/network/bridge.py +++ b/src/plugins/ovirt-hosted-engine-setup/network/bridge.py @@ -38,6 +38,7 @@ from ovirt_hosted_engine_setup import constants as ohostedcons +from ovirt_hosted_engine_setup import vds_info _ = lambda m: gettext.dgettext(message=m, domain='ovirt-hosted-engine-setup') @@ -196,39 +197,13 @@ def _misc(self): self.logger.info(_('Configuring the management bridge')) conn = vdscli.connect() - net_info = netinfo.NetInfo(_getVdsCapabilities(conn)) - bridge_port = self.environment[ohostedcons.NetworkEnv.BRIDGE_IF] - bridge = self.environment[ohostedcons.NetworkEnv.BRIDGE_NAME] - networks = {bridge: {}} - if bridge_port in net_info.vlans: - port_info = net_info.vlans[bridge_port] - networks[bridge]['vlan'] = port_info['vlanid'] - iface = port_info['iface'] - if iface in net_info.bondings: - networks[bridge]['bonding'] = iface - else: - networks[bridge]['nic'] = iface - elif bridge_port in net_info.bondings: - networks[bridge]['bonding'] = bridge_port - port_info = net_info.bondings[bridge_port] - elif bridge_port in net_info.nics: - networks[bridge]['nic'] = bridge_port - port_info = net_info.nics[bridge_port] - else: - raise RuntimeError('The selected device %s is not a supported ' - 'bridge port' % bridge_port) - - if 'BOOTPROTO' in port_info['cfg']: - networks[bridge]['bootproto'] = port_info['cfg']['BOOTPROTO'] - if networks[bridge].get('bootproto') == 'dhcp': - networks[bridge]['blockingdhcp'] = True - else: - networks[bridge]['ipaddr'] = port_info['addr'] - networks[bridge]['netmask'] = port_info['netmask'] - gateway = port_info.get('gateway') - if gateway is not None: - networks[bridge]['gateway'] = gateway - + networks = { + self.environment[ohostedcons.NetworkEnv.BRIDGE_NAME]: + vds_info.network( + vds_info.capabilities(conn), + self.environment[ohostedcons.NetworkEnv.BRIDGE_IF] + ) + } _setupNetworks(conn, networks, {}, {'connectivityCheck': False}) _setSafeNetworkConfig(conn) @@ -248,15 +223,6 @@ if code != 0: raise RuntimeError('Failed to setup networks %r. Error code: "%s" ' 'message: "%s"' % (networks, code, message)) - - -def _getVdsCapabilities(conn): - result = conn.getVdsCapabilities() - code, message = result['status']['code'], result['status']['message'] - if code != 0 or 'info' not in result: - raise RuntimeError('Failed to get vds capabilities. Error code: ' - '"%s" message: "%s"' % (code, message)) - return result['info'] def _setSafeNetworkConfig(conn): -- To view, visit http://gerrit.ovirt.org/32374 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ica4c5804395d364438f1e142387376cc7adc7172 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-hosted-engine-setup Gerrit-Branch: ovirt-hosted-engine-setup-1.2 Gerrit-Owner: Sandro Bonazzola <[email protected]> Gerrit-Reviewer: Antoni Segura Puimedon <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
