Mark Wu has uploaded a new change for review. Change subject: Only assign layer 3 parameters to topmost interface ......................................................................
Only assign layer 3 parameters to topmost interface This patch changes to configure bare interfaces without any layer 3 parameters, and assign the l3 info to the topmost interface at last. Then we don't need to care about resetting the parameters. Change-Id: I3d430879cdfcc74ff133ac03ead74305fa3baf06 Signed-off-by: Mark Wu <[email protected]> --- M vdsm/configNetwork.py 1 file changed, 46 insertions(+), 44 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/55/11355/1 diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py index bfdd505..27d722a 100755 --- a/vdsm/configNetwork.py +++ b/vdsm/configNetwork.py @@ -446,16 +446,13 @@ self.writeConfFile(netinfo.NET_CONF_PREF + name, cfg) - def addBridge(self, name, ipaddr=None, netmask=None, mtu=None, - gateway=None, bootproto=None, delay='0', onboot='yes', + def addBridge(self, name, mtu=None, delay='0', onboot='yes', **kwargs): """ Create ifcfg-* file with proper fields for bridge """ conf = 'TYPE=Bridge\nDELAY=%s\n' % pipes.quote(delay) - self._createConfFile(conf, name, ipaddr, netmask, gateway, - bootproto, mtu, onboot, **kwargs) + self._createConfFile(conf, name, mtu, onboot, **kwargs) def addVlan(self, vlanId, iface, network, mtu=None, bridged=True, - ipaddr=None, netmask=None, gateway=None, bootproto=None, onboot='yes', **kwargs): """ Create ifcfg-* file with proper fields for VLAN """ name = '%s.%s' % (pipes.quote(iface), vlanId) @@ -463,11 +460,9 @@ if bridged: conf += 'BRIDGE=%s\n' % pipes.quote(network) - self._createConfFile(conf, name, ipaddr, netmask, gateway, - bootproto, mtu, onboot, **kwargs) + self._createConfFile(conf, name, mtu, onboot, **kwargs) def addBonding(self, bonding, bridge=None, bondingOptions=None, mtu=None, - ipaddr=None, netmask=None, gateway=None, bootproto=None, onboot='yes', **kwargs): """ Create ifcfg-* file with proper fields for bond """ if not bondingOptions: @@ -479,14 +474,15 @@ if ifaceUsers(bonding): confParams = netinfo.getIfaceCfg(bonding) - if not ipaddr: - ipaddr = confParams.get('IPADDR', None) - netmask = confParams.get('NETMASK', None) - gateway = confParams.get('GATEWAY', None) + ipaddr = confParams.get('IPADDR', None) + netmask = confParams.get('NETMASK', None) + gateway = confParams.get('GATEWAY', None) if not mtu: mtu = confParams.get('MTU', None) if mtu: mtu = int(mtu) + else: + ipaddr = netmask = gateway = bootproto = None self._createConfFile(conf, bonding, ipaddr, netmask, gateway, bootproto, mtu, onboot, **kwargs) @@ -497,7 +493,6 @@ open(bondMastersPath, 'w').write('+%s\n' % bonding) def addNic(self, nic, bonding=None, bridge=None, mtu=None, - ipaddr=None, netmask=None, gateway=None, bootproto=None, onboot='yes', **kwargs): """ Create ifcfg-* file with proper fields for NIC """ _netinfo = netinfo.NetInfo() @@ -512,17 +507,28 @@ if ifaceUsers(nic): confParams = netinfo.getIfaceCfg(nic) - if not ipaddr: - ipaddr = confParams.get('IPADDR', None) - netmask = confParams.get('NETMASK', None) - gateway = confParams.get('GATEWAY', None) + ipaddr = confParams.get('IPADDR', None) + netmask = confParams.get('NETMASK', None) + gateway = confParams.get('GATEWAY', None) if not mtu: mtu = confParams.get('MTU', None) if mtu: mtu = int(mtu) + else: + ipaddr = netmask = gateway = bootproto = None self._createConfFile(conf, nic, ipaddr, netmask, gateway, bootproto, mtu, onboot, **kwargs) + + def updateTopIface(self, topIface, ipaddr=None, netmask=None, gateway=None, + bootproto=None): + cf = netinfo.NET_CONF_PREF + topIface + l3Info = {'IPADDR': ipaddr, 'NETMASK': netmask, 'GATEWAY': gateway, + 'BOOTPROTO': bootproto or 'none'} + for entry, value in l3Info.iteritems(): + if not value: + delete = True + self._updateConfigValue(cf, entry, value, delete) def removeNic(self, nic): cf = netinfo.NET_CONF_PREF + nic @@ -924,6 +930,14 @@ nic = nics[0] if nics else None iface = bonding or nic + if bridged: + topIface = network + elif vlan: + topIface = iface + '.' + vlan + else: + topIface = iface + + bootproto = options.get('bootproto') blockingDhcp = utils.tobool(options.get('blockingdhcp')) # take down nics that need to be changed @@ -934,16 +948,8 @@ ifdown(nic) if bridged: - configWriter.addBridge(network, ipaddr=ipaddr, netmask=netmask, - mtu=mtu, gateway=gateway, **options) + configWriter.addBridge(network, mtu=mtu, **options) ifdown(network) - # We need to define (if requested) ip, mask & gateway on ifcfg-* - # only on most top device according to following order: - # bridge -> vlan -> bond -> nic - # For lower level devices we should ignore it. - # reset ip, netmask, gateway and bootproto for lower level devices - bridgeBootproto = options.get('bootproto') - ipaddr = netmask = gateway = options['bootproto'] = None # For VLAN we should attach bridge only to the VLAN device # rather than to underlying NICs or bond @@ -957,44 +963,40 @@ # don't ifup VLAN interface here, it should be done last, # after the bond and nic up configWriter.addVlan(vlan, iface, network=brName, - mtu=mtu, bridged=bridged, - ipaddr=ipaddr, netmask=netmask, - gateway=gateway, **options) + mtu=mtu, bridged=bridged, **options) iface += '.' + vlan - vlanBootproto = options.get('bootproto') - # reset ip, netmask, gateway and bootproto for lower level devices - ipaddr = netmask = gateway = options['bootproto'] = None # First we need to prepare all conf files if bonding: configWriter.addBonding(bonding, bridge=bridgeForNic, bondingOptions=bondingOptions, - mtu=max(prevmtu, mtu), - ipaddr=ipaddr, netmask=netmask, - gateway=gateway, **options) - bondBootproto = options.get('bootproto') - # reset ip, netmask, gateway and bootproto for lower level devices - ipaddr = netmask = gateway = options['bootproto'] = None + mtu=max(prevmtu, mtu), **options) for nic in nics: configWriter.addNic(nic, bonding=bonding, bridge=bridgeForNic if not bonding else None, - mtu=max(prevmtu, mtu), ipaddr=ipaddr, - netmask=netmask, gateway=gateway, **options) + mtu=max(prevmtu, mtu), **options) + + if ipaddr or bootproto: + configWriter.updateTopIface(topIface, ipaddr=ipaddr, netmask=netmask, + gateway=gateway, bootproto=bootproto) + + def _isAsync(iface): + return iface == topIface and bootproto == 'dhcp' and not blockingDhcp # Now we can run ifup for all interfaces if bonding: - ifup(bonding, bondBootproto == 'dhcp' and not blockingDhcp) + ifup(bonding, _isAsync(bonding)) else: for nic in nics: - ifup(nic, options.get('bootproto') == 'dhcp' and not blockingDhcp) + ifup(nic, _isAsync(nic)) # Now we can ifup VLAN interface, because bond and nic already up if vlan: - ifup(iface, vlanBootproto == 'dhcp' and not blockingDhcp) + ifup(iface, _isAsync(iface)) if bridged: - ifup(network, bridgeBootproto == 'dhcp' and not blockingDhcp) + ifup(network, _isAsync(network)) # add libvirt network configWriter.createLibvirtNetwork(network, bridged, iface) -- To view, visit http://gerrit.ovirt.org/11355 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3d430879cdfcc74ff133ac03ead74305fa3baf06 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Mark Wu <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
