Change in vdsm[master]: NetReload: Move removeBondings and editBondings implementati...
wudxw at linux.vnet.ibm.com
wudxw at linux.vnet.ibm.com
Wed Apr 24 08:20:40 UTC 2013
Mark Wu has uploaded a new change for review.
Change subject: NetReload: Move removeBondings and editBondings implementation to ifcfg.py
......................................................................
NetReload: Move removeBondings and editBondings implementation to ifcfg.py
Change-Id: I224512bd719f43f77389a503e81a36734670dbd9
Signed-off-by: Mark Wu <wudxw at linux.vnet.ibm.com>
---
M vdsm/configNetwork.py
M vdsm/netconf/ifcfg.py
2 files changed, 52 insertions(+), 42 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/98/14198/1
diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index e52700b..6f1e4a0 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -542,7 +542,7 @@
"Unknown nics in: %r" % list(nics))
-def _editBondings(bondings, configWriter):
+def _editBondings(bondings, configurator):
""" Add/Edit bond interface """
logger = logging.getLogger("_editBondings")
@@ -554,40 +554,16 @@
bridge = _netinfo.getBridgedNetworkForIface(bond)
- mtu = None
if bond in _netinfo.bondings:
- # 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)
- 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
-
- # First we need to prepare all conf files
- configWriter.addBonding(bond, bridge=bridge, mtu=mtu,
- bondingOptions=bondAttrs.get('options', None))
-
- for nic in bondAttrs['nics']:
- configWriter.addNic(nic, bonding=bond, mtu=mtu)
-
- # Now we can run ifup for all interfaces
- ifup(bond)
+ configurator.editBonding(bond, bondAttrs, bridge, _netinfo)
+ else:
+ configurator.configureBonding(bond, nics=bondAttrs['nics'],
+ bridge=bridge,
+ bondingOptions=
+ bondAttrs.get('options', None))
-def _removeBondings(bondings, configWriter):
+def _removeBondings(bondings, configurator):
""" Remove bond interface """
logger = logging.getLogger("_removeBondings")
@@ -597,14 +573,7 @@
if 'remove' in bondAttrs:
nics = _netinfo.getNicsForBonding(bond)
logger.debug("Removing bond %r with nics = %s", bond, nics)
- ifdown(bond)
- configWriter.removeBonding(bond)
-
- for nic in nics:
- ifdown(nic)
- configWriter.removeNic(nic)
- ifup(nic)
-
+ configurator.removeBonging(bond, nics)
del bondings[bond]
@@ -669,6 +638,7 @@
logger = logging.getLogger("setupNetworks")
_netinfo = netinfo.NetInfo()
configWriter = ConfigWriter()
+ configurator = Ifcfg(configWriter)
networksAdded = set()
logger.debug("Setting up network according to configuration: "
@@ -706,10 +676,10 @@
networksAdded.add(network)
# Remove bonds with 'remove' attribute
- _removeBondings(bondings, configWriter)
+ _removeBondings(bondings, configurator)
# Check whether bonds should be resized
- _editBondings(bondings, configWriter)
+ _editBondings(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 ee7c666..e25f536 100644
--- a/vdsm/netconf/ifcfg.py
+++ b/vdsm/netconf/ifcfg.py
@@ -150,6 +150,46 @@
self.configWriter.createLibvirtNetwork(network, False, nic)
return nic
+ 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)
+
class ConfigWriter(object):
CONFFILE_HEADER = '# automatically generated by vdsm'
--
To view, visit http://gerrit.ovirt.org/14198
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I224512bd719f43f77389a503e81a36734670dbd9
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