Change in vdsm[master]: NetReload: netmodels for editBonding/removeBonding
wudxw at linux.vnet.ibm.com
wudxw at linux.vnet.ibm.com
Tue Jun 4 14:15:27 UTC 2013
Mark Wu has uploaded a new change for review.
Change subject: NetReload: netmodels for editBonding/removeBonding
......................................................................
NetReload: netmodels for editBonding/removeBonding
Re-implement the logic of editBonding and removeBonding using
netmodels.
Change-Id: I9ab6fabb01d38c0e23a950bc5b693fe597b7d21c
Signed-off-by: Mark Wu <wudxw at linux.vnet.ibm.com>
---
M vdsm/configNetwork.py
M vdsm/netconf/ifcfg.py
M vdsm/netmodels.py
3 files changed, 54 insertions(+), 86 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/56/15356/1
diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index 525996c..6f7ba9d 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -376,39 +376,32 @@
"Unknown nics in: %r" % list(nics))
-def _editBondings(bondings, configurator):
- """ Add/Edit bond interface """
- logger = logging.getLogger("_editBondings")
+def _handleBondings(bondings, configurator):
+ """ Add/Edit/Remove bond interface """
+ logger = logging.getLogger("_handleBondings")
_netinfo = netinfo.NetInfo()
- for bond, bondAttrs in bondings.iteritems():
- logger.debug("Creating/Editing bond %s with attributes %s",
- bond, bondAttrs)
-
- bridge = _netinfo.getBridgedNetworkForIface(bond)
-
- if bond in _netinfo.bondings:
- configurator.editBonding(bond, bondAttrs, bridge, _netinfo)
- else:
- configurator.configureBonding(bond, nics=bondAttrs['nics'],
- bridge=bridge,
- bondingOptions=bondAttrs.get(
- 'options', None))
-
-
-def _removeBondings(bondings, configurator):
- """ Remove bond interface """
- logger = logging.getLogger("_removeBondings")
-
- _netinfo = netinfo.NetInfo()
-
- for bond, bondAttrs in bondings.items():
+ for bondName, bondAttrs in bondings.iteritems():
+ bond = Bond.objectivize(bondName, configurator,
+ bondAttrs.get('options', None),
+ nics=None, mtu=None,
+ _netinfo=_netinfo,
+ destroy='remove' in bondAttrs)
if 'remove' in bondAttrs:
- nics = _netinfo.getNicsForBonding(bond)
- logger.debug("Removing bond %r with nics = %s", bond, nics)
- configurator.removeBonding(bond, nics)
- del bondings[bond]
+ logger.debug("Removing bond %s with attributes %s", bondName,
+ bondAttrs)
+ configurator.removeBond(bond)
+ del bondings[bondName]
+ del _netinfo.bondings[bondName]
+ elif bondName in _netinfo.bondings:
+ logger.debug("Editing bond %s with attributes %s", bondName,
+ bondAttrs)
+ configurator.editBonding(bond, bondAttrs, _netinfo)
+ else:
+ logger.debug("Creating bond %s with attributes %s", bondName,
+ bondAttrs)
+ configurator.configureBond(bond)
def _buildBondOptions(bondName, bondings, _netinfo):
@@ -509,11 +502,7 @@
else:
networksAdded.add(network)
- # Remove bonds with 'remove' attribute
- _removeBondings(bondings, configurator)
-
- # Check whether bonds should be resized
- _editBondings(bondings, configurator)
+ _handleBondings(bondings, configurator)
# We need to use the newest host info
_ni = netinfo.NetInfo()
diff --git a/vdsm/netconf/ifcfg.py b/vdsm/netconf/ifcfg.py
index 02ee20e..6070053 100644
--- a/vdsm/netconf/ifcfg.py
+++ b/vdsm/netconf/ifcfg.py
@@ -116,45 +116,14 @@
iface.name)
self._libvirtAdded.add(network)
- def configureBonding(self, bond, nics, bridge=None, mtu=None,
- bondingOptions=None):
- self.configWriter.addBonding(bond, bridge=bridge, mtu=mtu,
- bondingOptions=bondingOptions)
- for nic in nics:
- self.configWriter.addNic(nic, bonding=bond, mtu=mtu)
- ifup(bond)
-
- def editBonding(self, bond, bondAttrs, bridge, _netinfo):
- # Save MTU for future set on NICs
- confParams = netinfo.getIfaceCfg(bond)
- mtu = confParams.get('MTU', None)
- if mtu:
- mtu = int(mtu)
-
- ifdown(bond)
- # Take down all bond's NICs.
- for nic in _netinfo.getNicsForBonding(bond):
- ifdown(nic)
- self.configWriter.removeNic(nic)
- if nic not in bondAttrs['nics']:
- ifup(nic)
-
- # Note! In case we have bridge up and connected to the bond
- # we will get error in log:
- # (ifdown) bridge XXX is still up; can't delete it
- # But, we prefer this behaviour instead of taking bridge down
- # Anyway, we will not be able to take it down with connected VMs
- self.configureBonding(bond, bondAttrs['nics'], bridge, mtu,
- bondAttrs.get('options', None))
-
- def removeBonding(self, bond, nics):
- ifdown(bond)
- self.configWriter.removeBonding(bond)
-
- for nic in nics:
- ifdown(nic)
- self.configWriter.removeNic(nic)
- ifup(nic)
+ def editBonding(self, bond, newAttrs, _netinfo):
+ ifdown(bond.name)
+ for slave in bond.slaves:
+ slave.remove()
+ bond.updateSlaves(newAttrs['nics'], _netinfo)
+ bond.options = newAttrs.get('options', None)
+ bridge = _netinfo.getBridgedNetworkForIface(bond.name)
+ self.configureBond(bond, bridge)
def removeLibvirtNetwork(self, network):
self.configWriter.removeLibvirtNetwork(network)
diff --git a/vdsm/netmodels.py b/vdsm/netmodels.py
index 995878f..2bbb1f6 100644
--- a/vdsm/netmodels.py
+++ b/vdsm/netmodels.py
@@ -165,26 +165,36 @@
logging.debug('Removing bond %r', self)
self.configurator.removeBond(self)
+ def updateSlaves(self, nics, _netinfo):
+ self.slaves = self._objectivizeSlaves(self.name, self.configurator,
+ nics, self.mtu, _netinfo)
+
+ @staticmethod
+ def _objectivizeSlaves(name, configurator, nics, mtu, _netinfo):
+ slaves = []
+ for nic in nics:
+ nicVlans = tuple(_netinfo.getVlansForIface(nic))
+ nicNet = _netinfo.getNetworkForIface(nic)
+ nicBond = _netinfo.getBondingForNic(nic)
+ if nicVlans or nicNet or nicBond and nicBond != name:
+ raise ConfigNetworkError(
+ ne.ERR_USED_NIC, 'nic %s already used by %s' %
+ (nic, nicVlans or nicNet or nicBond))
+ slaves.append(Nic(nic, configurator, mtu=mtu,
+ _netinfo=_netinfo))
+ return slaves
+
@classmethod
def objectivize(cls, name, configurator, options, nics, mtu, _netinfo,
destroy=None):
- if name and nics:
- slaves = []
- for nic in nics:
- nicVlans = tuple(_netinfo.getVlansForIface(nic))
- nicNet = _netinfo.getNetworkForIface(nic)
- nicBond = _netinfo.getBondingForNic(nic)
- if nicVlans or nicNet or nicBond and nicBond != name:
- raise ConfigNetworkError(
- ne.ERR_USED_NIC, 'nic %s already used by %s' %
- (nic, nicVlans or nicNet or nicBond))
- slaves.append(Nic(nic, configurator, mtu=mtu,
- _netinfo=_netinfo))
- elif name in _netinfo.bondings: # Implicit bonding.
+ if name in _netinfo.bondings: # Implicit bonding or edit bonding
mtu = max(int(netinfo.getMtu(name)), mtu)
slaves = [Nic(nic, configurator, mtu=mtu, _netinfo=_netinfo)
for nic in _netinfo.getNicsForBonding(name)]
options = _netinfo.bondings[name]['cfg'].get('BONDING_OPTS')
+ elif name and nics:
+ slaves = cls._objectivizeSlaves(name, configurator, nics, mtu,
+ _netinfo)
else:
raise ConfigNetworkError(ne.ERR_BAD_BONDING,
'Bonding %s not specified and it is not '
--
To view, visit http://gerrit.ovirt.org/15356
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9ab6fabb01d38c0e23a950bc5b693fe597b7d21c
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Mark Wu <wudxw at linux.vnet.ibm.com>
More information about the vdsm-patches
mailing list