Skip to content

Commit

Permalink
network: fixing hostname - interface enforcing for DHCP setups
Browse files Browse the repository at this point in the history
https://gerrit.ovirt.org/#/c/53142/ is enforcing that the hostname
resolves on the interface where we are going to create the bridge
on. Vds_info.network on the other side wasn't returning an ip
addr if the interface was configured for DHCP so this
enforcing was always failing if the user rely on DHCP.
Fixing it.
Simply using socket.getfqdn() on additional hosts.

Change-Id: Ie09301e6142c8bc6b009b02ae252bcac78b2f063
Bug-Url: https://bugzilla.redhat.com/1308333
Signed-off-by: Simone Tiraboschi <stirabos@redhat.com>
  • Loading branch information
tiraboschi committed Feb 15, 2016
1 parent 9edcb21 commit 4e2180b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 27 deletions.
52 changes: 35 additions & 17 deletions src/ovirt_hosted_engine_setup/vds_info.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# ovirt-hosted-engine-setup -- ovirt hosted engine setup
# Copyright (C) 2014 Red Hat, Inc.
# Copyright (C) 2014-2016 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
Expand Down Expand Up @@ -57,22 +57,31 @@ def _evaluateDefaultRoute(attrs, cfg):


def network(caps, device):
"""Returns a dictionary that describes the network of the device"""
"""
Returns a dictionary that describes the network of the device.
:param caps: the output of vds_info.capabilities
:param device: the name of the network device
:return (configuration, status): configuration is the whole dict to be
passed to setupNetwork to configure the bridge as needed.
Status is the current network status (for instance it includes
the IP address also if the interfaces got its address by DHCP)
"""
info = netinfo.CachingNetInfo(caps)
attrs = {}
configuration = {}
status = {}
if device in info.vlans:
port_info = info.vlans[device]
attrs['vlan'] = port_info['vlanid']
configuration['vlan'] = port_info['vlanid']
iface = port_info['iface']
if iface in info.bondings:
attrs['bonding'] = iface
configuration['bonding'] = iface
else:
attrs['nic'] = iface
configuration['nic'] = iface
elif device in info.bondings:
attrs['bonding'] = device
configuration['bonding'] = device
port_info = info.bondings[device]
elif device in info.nics:
attrs['nic'] = device
configuration['nic'] = device
port_info = info.nics[device]
else:
raise RuntimeError(
Expand All @@ -81,19 +90,28 @@ def network(caps, device):
)

if 'BOOTPROTO' in port_info['cfg']:
attrs['bootproto'] = port_info['cfg']['BOOTPROTO']
if attrs.get('bootproto') == 'dhcp':
attrs['blockingdhcp'] = True
configuration['bootproto'] = port_info['cfg']['BOOTPROTO']
if configuration.get('bootproto') == 'dhcp':
configuration['blockingdhcp'] = True
else:
attrs['ipaddr'] = port_info['addr']
attrs['netmask'] = port_info['netmask']
configuration['ipaddr'] = port_info['addr']
configuration['netmask'] = port_info['netmask']
gateway = port_info.get('gateway')
if gateway is not None:
attrs['gateway'] = gateway
configuration['gateway'] = gateway
elif 'GATEWAY' in port_info['cfg']:
attrs['gateway'] = port_info['cfg']['GATEWAY']
attrs['defaultRoute'] = _evaluateDefaultRoute(attrs, port_info['cfg'])
return attrs
configuration['gateway'] = port_info['cfg']['GATEWAY']
configuration['defaultRoute'] = _evaluateDefaultRoute(
configuration,
port_info['cfg']
)
if 'addr' in port_info:
status['ipaddr'] = port_info['addr']
if 'netmask' in port_info:
status['netmask'] = port_info['netmask']
if 'gateway' in port_info:
status['gateway'] = port_info['gateway']
return configuration, status


# vim: expandtab tabstop=4 shiftwidth=4
35 changes: 25 additions & 10 deletions src/plugins/ovirt-hosted-engine-setup/network/bridge.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# ovirt-hosted-engine-setup -- ovirt hosted engine setup
# Copyright (C) 2013-2015 Red Hat, Inc.
# Copyright (C) 2013-2016 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
Expand Down Expand Up @@ -245,21 +245,24 @@ def _get_existing_bridge_interface(self):
] = bridge_ifs[0]

@plugin.event(
stage=plugin.Stages.STAGE_VALIDATION
stage=plugin.Stages.STAGE_VALIDATION,
condition=lambda self: not self.environment[
ohostedcons.CoreEnv.IS_ADDITIONAL_HOST
],
)
def _get_hostname_from_bridge_if(self):
info = vds_info.network(
configuration, status = vds_info.network(
vds_info.capabilities(
self.environment[ohostedcons.VDSMEnv.VDS_CLI]
),
self.environment[
ohostedcons.NetworkEnv.BRIDGE_IF
],
)
self.logger.debug('Network info: {info}'.format(info=info))
if 'ipaddr' not in info:
self.logger.debug('Network info: {info}'.format(info=status))
if 'ipaddr' not in status:
raise RuntimeError(_('Cannot acquire nic/bond/vlan address'))
ipaddr = info['ipaddr']
ipaddr = status['ipaddr']
hostname, aliaslist, ipaddrlist = socket.gethostbyaddr(ipaddr)
self.logger.debug(
"hostname: '{h}', aliaslist: '{a}', ipaddrlist: '{i}'".format(
Expand Down Expand Up @@ -288,6 +291,17 @@ def _get_hostname_from_bridge_if(self):
ohostedcons.NetworkEnv.HOST_NAME
] = hostname

@plugin.event(
stage=plugin.Stages.STAGE_VALIDATION,
condition=lambda self: self.environment[
ohostedcons.CoreEnv.IS_ADDITIONAL_HOST
],
)
def _get_hostname_additional_hosts(self):
self.environment[
ohostedcons.NetworkEnv.HOST_NAME
] = socket.getfqdn()

@plugin.event(
stage=plugin.Stages.STAGE_MISC,
name=ohostedcons.Stages.BRIDGE_AVAILABLE,
Expand All @@ -302,12 +316,13 @@ def _get_hostname_from_bridge_if(self):
def _misc(self):
self.logger.info(_('Configuring the management bridge'))
conn = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
nconf, nstatus = vds_info.network(
vds_info.capabilities(conn),
self.environment[ohostedcons.NetworkEnv.BRIDGE_IF]
)
networks = {
self.environment[ohostedcons.NetworkEnv.BRIDGE_NAME]:
vds_info.network(
vds_info.capabilities(conn),
self.environment[ohostedcons.NetworkEnv.BRIDGE_IF]
)
nconf
}
bonds = {}
options = {'connectivityCheck': False}
Expand Down

0 comments on commit 4e2180b

Please sign in to comment.