Change in vdsm[master]: Remove '/var/log/core' for fedora
by Xu He Jie
Xu He Jie has uploaded a new change for review.
Change subject: Remove '/var/log/core' for fedora
......................................................................
Remove '/var/log/core' for fedora
Remove '/var/log/core' for fedora, this directory only be created
for RHEL
Change-Id: I594b5aa2ecaad1b1a268fa231a5769ef437ec75e
Signed-off-by: Xu He Jie <xuhj(a)linux.vnet.ibm.com>
---
M build-aux/Makefile.subs
M configure.ac
M vdsm/Makefile.am
M vdsm/constants.py.in
M vdsm/sos/vdsm.py.in
M vdsm/utils.py
M vdsm/vdsm-logrotate.conf.in
A vdsm/vdsm-logrotate.conf.rhel.in
M vdsm/vdsmd.init.in
9 files changed, 56 insertions(+), 27 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/48/4348/1
--
To view, visit http://gerrit.ovirt.org/4348
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I594b5aa2ecaad1b1a268fa231a5769ef437ec75e
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Xu He Jie <xuhj(a)linux.vnet.ibm.com>
11 years, 4 months
Change in vdsm[master]: Refactor configNetwork.py: add a new class NativeConfigurato...
by wudxw@linux.vnet.ibm.com
Mark Wu has uploaded a new change for review.
Change subject: Refactor configNetwork.py: add a new class NativeConfigurator
......................................................................
Refactor configNetwork.py: add a new class NativeConfigurator
Basically, this patch just adds a new class NativeConfigurator and moves
the functions of add, delete, edit and setup network into that class.
The purpose of this patch is to make it easy to integrate netcf support
by adding a wrapper to the actual network configurator.
Change-Id: I052955a8e2b7b92b123a5179afd15b79798e6c50
Signed-off-by: Mark Wu <wudxw(a)linux.vnet.ibm.com>
---
M vdsm/configNetwork.py
1 file changed, 440 insertions(+), 414 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/15/7915/1
diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index 12e5e5b..803ba3c 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -855,293 +855,6 @@
_validateInterNetworkCompatibility(_netinfo, vlan, nic, bridged)
-def addNetwork(network, vlan=None, bonding=None, nics=None, ipaddr=None,
- netmask=None, mtu=None, gateway=None, force=False,
- configWriter=None, bondingOptions=None, bridged=True,
- **options):
- nics = nics or ()
- _netinfo = netinfo.NetInfo()
- bridged = utils.tobool(bridged)
-
- if mtu:
- mtu = int(mtu)
-
- # Validation
- if not utils.tobool(force):
- logging.debug('validating network...')
- _addNetworkValidation(_netinfo, network=network,
- vlan=vlan, bonding=bonding, nics=nics, ipaddr=ipaddr,
- netmask=netmask, gateway=gateway, bondingOptions=bondingOptions,
- bridged=bridged, **options)
-
- logging.info("Adding network %s with vlan=%s, bonding=%s, nics=%s,"
- " bondingOptions=%s, mtu=%s, bridged=%s, options=%s",
- network, vlan, bonding, nics, bondingOptions,
- mtu, bridged, options)
-
- if configWriter is None:
- configWriter = ConfigWriter()
-
- prevmtu = None
- if mtu:
- prevmtu = configWriter.getMaxMtu(nics, mtu)
-
- nic = nics[0] if nics else None
- iface = bonding or nic
-
- # take down nics that need to be changed
- vlanedIfaces = [v['iface'] for v in _netinfo.vlans.values()]
- if bonding not in vlanedIfaces:
- for nic in nics:
- if nic not in vlanedIfaces:
- ifdown(nic)
-
- if bridged:
- configWriter.addBridge(network, ipaddr=ipaddr, netmask=netmask,
- mtu=mtu, gateway=gateway, **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 for lower level devices
- ipaddr = netmask = gateway = None
-
- # For VLAN we should attach bridge only to the VLAN device
- # rather than to underlying NICs or bond
- brName = network if bridged else None
- bridgeForNic = None if vlan else brName
-
- # We want to create config files (ifcfg-*) in top-down order
- # (bridge->vlan->bond->nic) to be able to handle IP/NETMASK
- # correctly for bridgeless networks
- if vlan:
- # 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)
- iface += '.' + vlan
- # reset ip, netmask, gateway for lower level devices
- ipaddr = netmask = gateway = 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)
- # reset ip, netmask, gateway for lower level devices
- ipaddr = netmask = gateway = None
-
- 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)
-
- # Now we can run ifup for all interfaces
- if bonding:
- ifup(bonding)
-
- # NICs must be activated in the same order of boot time
- # to expose the correct MAC address.
- for nic in nicSort(nics):
- ifup(nic)
-
- # Now we can ifup VLAN interface, because bond and nic already up
- if vlan:
- ifup(iface)
-
- if bridged:
- if options.get('bootproto') == 'dhcp' and \
- not utils.tobool(options.get('blockingdhcp')):
- # wait for dhcp in another thread,
- # so vdsm won't get stuck (BZ#498940)
- t = threading.Thread(target=ifup, name='ifup-waiting-on-dhcp',
- args=(network,))
- t.daemon = True
- t.start()
- else:
- ifup(network)
-
- # add libvirt network
- configWriter.createLibvirtNetwork(network, bridged, iface)
-
-
-def assertBridgeClean(bridge, vlan, bonding, nics):
- brifs = os.listdir('/sys/class/net/%s/brif/' % bridge)
- for nic in nics:
- try:
- brifs.remove(nic)
- except:
- pass
- if vlan:
- brif = (bonding or nics[0]) + '.' + vlan
- else:
- brif = bonding
- try:
- brifs.remove(brif)
- except:
- pass
-
- if brifs:
- raise ConfigNetworkError(ne.ERR_USED_BRIDGE,
- 'bridge %s has interfaces %s connected' % (bridge, brifs))
-
-
-def showNetwork(network):
- _netinfo = netinfo.NetInfo()
- if network not in _netinfo.networks:
- print "Network %r doesn't exist" % network
- return
-
- bridged = _netinfo.networks[network]['bridged']
- print "Network %s(Bridged: %s):" % (network, bridged)
-
- nics, vlan, bonding = _netinfo.getNicsVlanAndBondingForNetwork(network)
-
- if bridged:
- ipaddr = _netinfo.networks[network]['addr']
- netmask = _netinfo.networks[network]['netmask']
- gateway = _netinfo.networks[network]['gateway']
- print "ipaddr=%s, netmask=%s, gateway=%s" % (ipaddr, netmask, gateway)
- else:
- iface = _netinfo.networks[network]['iface']
- ipaddr = _netinfo.nics[iface]['addr']
- netmask = _netinfo.nics[iface]['netmask']
- print "ipaddr=%s, netmask=%s" % (ipaddr, netmask)
-
- print "vlan=%s, bonding=%s, nics=%s" % (vlan, bonding, nics)
-
-
-def listNetworks():
- _netinfo = netinfo.NetInfo()
- print "Networks:", _netinfo.networks.keys()
- print "Vlans:", _netinfo.vlans.keys()
- print "Nics:", _netinfo.nics.keys()
- print "Bondings:", _netinfo.bondings.keys()
-
-
-def delNetwork(network, vlan=None, bonding=None, nics=None, force=False,
- configWriter=None, implicitBonding=True, **options):
- _netinfo = netinfo.NetInfo()
-
- if configWriter is None:
- configWriter = ConfigWriter()
-
- if network not in _netinfo.networks:
- logging.info("Network %r: doesn't exist in libvirt database", network)
- if network in netinfo.bridges():
- configWriter.removeBridge(network)
- else:
- raise ConfigNetworkError(ne.ERR_BAD_BRIDGE,
- "Cannot delete network %r: It doesn't exist "
- "in the system" % network)
-
- if vlan:
- configWriter.removeVlan(vlan, bonding or nics[0])
-
- return
-
- nics, vlan, bonding = _netinfo.getNicsVlanAndBondingForNetwork(network)
- bridged = _netinfo.networks[network]['bridged']
-
- logging.info("Removing network %s with vlan=%s, bonding=%s, nics=%s,"
- "options=%s" % (network, vlan, bonding, nics, options))
-
- if not utils.tobool(force):
- if bonding:
- validateBondingName(bonding)
- if set(nics) != set(_netinfo.bondings[bonding]["slaves"]):
- raise ConfigNetworkError(ne.ERR_BAD_NIC,
- "delNetwork: %s are not all nics enslaved to %s" %
- (nics, bonding))
- if vlan:
- validateVlanId(vlan)
- if bridged:
- assertBridgeClean(network, vlan, bonding, nics)
-
- configWriter.setNewMtu(network=network, bridged=bridged)
- configWriter.removeLibvirtNetwork(network)
-
- # We need to gather NetInfo again to refresh networks info from libvirt.
- # The deleted bridge should never be up at this stage.
- if network in netinfo.NetInfo().networks:
- raise ConfigNetworkError(ne.ERR_USED_BRIDGE,
- "delNetwork: bridge %s still exists" % network)
-
- if network and bridged:
- configWriter.removeBridge(network)
-
- nic = nics[0] if nics else None
- iface = bonding if bonding else nic
- if iface:
- if vlan:
- configWriter.removeVlan(vlan, iface)
- else:
- cf = configWriter.NET_CONF_PREF + iface
- if not bridged:
- # When removing bridgeless non-VLANed network
- # we need to remove IP/NETMASK from the cfg file
- for key in ('IPADDR', 'NETMASK', 'GATEWAY', 'BOOTPROTO'):
- configWriter._updateConfigValue(cf, key, '', True)
- else:
- # When removing bridged non-VLANed network
- # we need to remove BRIDGE from the cfg file
- configWriter._updateConfigValue(cf, 'BRIDGE', '', True)
-
- # The (relatively) new setupNetwork verb allows to remove a network
- # defined on top of an bonding device without break the bond itself.
- if implicitBonding:
- if bonding and not bondingOtherUsers(network, vlan, bonding):
- ifdown(bonding)
- configWriter.removeBonding(bonding)
- iface = None if bonding == iface else iface
-
- for nic in nics:
- if not nicOtherUsers(network, vlan, bonding, nic):
- ifdown(nic)
- configWriter.removeNic(nic)
- iface = None if nic == iface else iface
-
- # Now we can restart changed interface
- if iface:
- ifdown(iface)
- ifup(iface)
-
-
-def clientSeen(timeout):
- start = time.time()
- while timeout >= 0:
- if os.stat(constants.P_VDSM_CLIENT_LOG).st_mtime > start:
- return True
- time.sleep(1)
- timeout -= 1
- return False
-
-
-def editNetwork(oldBridge, newBridge, vlan=None, bonding=None, nics=None,
- **options):
- configWriter = ConfigWriter()
- try:
- delNetwork(oldBridge, configWriter=configWriter, **options)
- addNetwork(newBridge, vlan=vlan, bonding=bonding, nics=nics,
- configWriter=configWriter, **options)
- except:
- configWriter.restoreBackups()
- raise
- if utils.tobool(options.get('connectivityCheck', False)):
- if not clientSeen(int(options.get('connectivityTimeout',
- CONNECTIVITY_TIMEOUT_DEFAULT))):
- delNetwork(newBridge, force=True)
- configWriter.restoreBackups()
- return define.errCode['noConPeer']['status']['code']
-
-
def _validateNetworkSetup(networks={}, bondings={}):
_netinfo = netinfo.NetInfo()
@@ -1171,73 +884,441 @@
"Unknown nics in: %r" % list(nics))
-def _editBondings(bondings, configWriter):
- """ Add/Edit bond interface """
- logger = logging.getLogger("_editBondings")
+def assertBridgeClean(bridge, vlan, bonding, nics):
+ brifs = os.listdir('/sys/class/net/%s/brif/' % bridge)
+ for nic in nics:
+ try:
+ brifs.remove(nic)
+ except:
+ pass
+ if vlan:
+ brif = (bonding or nics[0]) + '.' + vlan
+ else:
+ brif = bonding
+ try:
+ brifs.remove(brif)
+ except:
+ pass
- _netinfo = netinfo.NetInfo()
+ if brifs:
+ raise ConfigNetworkError(ne.ERR_USED_BRIDGE,
+ 'bridge %s has interfaces %s connected' % (bridge, brifs))
- for bond, bondAttrs in bondings.iteritems():
- logger.debug("Creating/Editing bond %s with attributes %s",
- bond, bondAttrs)
- brNets = list(_netinfo.getBridgedNetworksForIface(bond))
- # Only one bridged-non-VLANed network allowed on same nic/bond
- bridge = brNets[0] if brNets else None
+def clientSeen(timeout):
+ start = time.time()
+ while timeout >= 0:
+ if os.stat(constants.P_VDSM_CLIENT_LOG).st_mtime > start:
+ return True
+ time.sleep(1)
+ timeout -= 1
+ return False
- 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)
+class NativeConfigurator():
- # 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
+ def addNetwork(self, network, vlan=None, bonding=None, nics=None,
+ ipaddr=None, netmask=None, mtu=None, gateway=None,
+ force=False, configWriter=None, bondingOptions=None,
+ bridged=True, **options):
+ nics = nics or ()
+ _netinfo = netinfo.NetInfo()
+ bridged = utils.tobool(bridged)
+
+ if mtu:
+ mtu = int(mtu)
+
+ # Validation
+ if not utils.tobool(force):
+ logging.debug('validating network...')
+ _addNetworkValidation(_netinfo, network=network,
+ vlan=vlan, bonding=bonding, nics=nics, ipaddr=ipaddr,
+ netmask=netmask, gateway=gateway,
+ bondingOptions=bondingOptions, bridged=bridged, **options)
+
+ logging.info("Adding network %s with vlan=%s, bonding=%s, nics=%s,"
+ " bondingOptions=%s, mtu=%s, bridged=%s, options=%s",
+ network, vlan, bonding, nics, bondingOptions,
+ mtu, bridged, options)
+
+ if configWriter is None:
+ configWriter = ConfigWriter()
+
+ prevmtu = None
+ if mtu:
+ prevmtu = configWriter.getMaxMtu(nics, mtu)
+
+ nic = nics[0] if nics else None
+ iface = bonding or nic
+
+ # take down nics that need to be changed
+ vlanedIfaces = [v['iface'] for v in _netinfo.vlans.values()]
+ if bonding not in vlanedIfaces:
+ for nic in nics:
+ if nic not in vlanedIfaces:
+ ifdown(nic)
+
+ if bridged:
+ configWriter.addBridge(network, ipaddr=ipaddr, netmask=netmask,
+ mtu=mtu, gateway=gateway, **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 for lower level devices
+ ipaddr = netmask = gateway = None
+
+ # For VLAN we should attach bridge only to the VLAN device
+ # rather than to underlying NICs or bond
+ brName = network if bridged else None
+ bridgeForNic = None if vlan else brName
+
+ # We want to create config files (ifcfg-*) in top-down order
+ # (bridge->vlan->bond->nic) to be able to handle IP/NETMASK
+ # correctly for bridgeless networks
+ if vlan:
+ # 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)
+ iface += '.' + vlan
+ # reset ip, netmask, gateway for lower level devices
+ ipaddr = netmask = gateway = None
# First we need to prepare all conf files
- configWriter.addBonding(bond, bridge=bridge, mtu=mtu,
- bondingOptions=bondAttrs.get('options', None))
+ if bonding:
+ configWriter.addBonding(bonding, bridge=bridgeForNic,
+ bondingOptions=bondingOptions,
+ mtu=max(prevmtu, mtu),
+ ipaddr=ipaddr, netmask=netmask,
+ gateway=gateway, **options)
+ # reset ip, netmask, gateway for lower level devices
+ ipaddr = netmask = gateway = None
- for nic in bondAttrs['nics']:
- configWriter.addNic(nic, bonding=bond, mtu=mtu)
+ 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)
# Now we can run ifup for all interfaces
- ifup(bond)
+ if bonding:
+ ifup(bonding)
+
# NICs must be activated in the same order of boot time
# to expose the correct MAC address.
- for nic in nicSort(bondAttrs['nics']):
+ for nic in nicSort(nics):
ifup(nic)
+ # Now we can ifup VLAN interface, because bond and nic already up
+ if vlan:
+ ifup(iface)
-def _removeBondings(bondings, configWriter):
- """ Remove bond interface """
- logger = logging.getLogger("_removeBondings")
+ if bridged:
+ if options.get('bootproto') == 'dhcp' and \
+ not utils.tobool(options.get('blockingdhcp')):
+ # wait for dhcp in another thread,
+ # so vdsm won't get stuck (BZ#498940)
+ t = threading.Thread(target=ifup, name='ifup-waiting-on-dhcp',
+ args=(network,))
+ t.daemon = True
+ t.start()
+ else:
+ ifup(network)
- _netinfo = netinfo.NetInfo()
+ # add libvirt network
+ configWriter.createLibvirtNetwork(network, bridged, iface)
- for bond, bondAttrs in bondings.items():
- if 'remove' in bondAttrs:
- nics = _netinfo.getNicsForBonding(bond)
- logger.debug("Removing bond %r with nics = %s", bond, nics)
- ifdown(bond)
- configWriter.removeBonding(bond)
+ def delNetwork(self, network, vlan=None, bonding=None, nics=None,
+ force=False, configWriter=None, implicitBonding=True,
+ **options):
+ _netinfo = netinfo.NetInfo()
+
+ if configWriter is None:
+ configWriter = ConfigWriter()
+
+ if network not in _netinfo.networks:
+ logging.info("Network %r: doesn't exist in libvirt database",
+ network)
+ if network in netinfo.bridges():
+ configWriter.removeBridge(network)
+ else:
+ raise ConfigNetworkError(ne.ERR_BAD_BRIDGE,
+ "Cannot delete network %r: It doesn't exist "
+ "in the system" % network)
+
+ if vlan:
+ configWriter.removeVlan(vlan, bonding or nics[0])
+
+ return
+
+ nics, vlan, bonding = _netinfo.getNicsVlanAndBondingForNetwork(network)
+ bridged = _netinfo.networks[network]['bridged']
+
+ logging.info("Removing network %s with vlan=%s, bonding=%s, nics=%s,"
+ "options=%s" % (network, vlan, bonding, nics, options))
+
+ if not utils.tobool(force):
+ if bonding:
+ validateBondingName(bonding)
+ if set(nics) != set(_netinfo.bondings[bonding]["slaves"]):
+ raise ConfigNetworkError(ne.ERR_BAD_NIC,
+ "delNetwork: %s are not all nics enslaved to %s" %
+ (nics, bonding))
+ if vlan:
+ validateVlanId(vlan)
+ if bridged:
+ assertBridgeClean(network, vlan, bonding, nics)
+
+ configWriter.setNewMtu(network=network, bridged=bridged)
+ configWriter.removeLibvirtNetwork(network)
+
+ # We need to gather NetInfo again to refresh networks info from
+ # libvirt. The deleted bridge should never be up at this stage.
+ if network in netinfo.NetInfo().networks:
+ raise ConfigNetworkError(ne.ERR_USED_BRIDGE,
+ "delNetwork: bridge %s still exists" % network)
+
+ if network and bridged:
+ configWriter.removeBridge(network)
+
+ nic = nics[0] if nics else None
+ iface = bonding if bonding else nic
+ if iface:
+ if vlan:
+ configWriter.removeVlan(vlan, iface)
+ else:
+ cf = configWriter.NET_CONF_PREF + iface
+ if not bridged:
+ # When removing bridgeless non-VLANed network
+ # we need to remove IP/NETMASK from the cfg file
+ for key in ('IPADDR', 'NETMASK', 'GATEWAY', 'BOOTPROTO'):
+ configWriter._updateConfigValue(cf, key, '', True)
+ else:
+ # When removing bridged non-VLANed network
+ # we need to remove BRIDGE from the cfg file
+ configWriter._updateConfigValue(cf, 'BRIDGE', '', True)
+
+ # The (relatively) new setupNetwork verb allows to remove a network
+ # defined on top of an bonding device without break the bond itself.
+ if implicitBonding:
+ if bonding and not bondingOtherUsers(network, vlan, bonding):
+ ifdown(bonding)
+ configWriter.removeBonding(bonding)
+ iface = None if bonding == iface else iface
for nic in nics:
- ifdown(nic)
- configWriter.removeNic(nic)
+ if not nicOtherUsers(network, vlan, bonding, nic):
+ ifdown(nic)
+ configWriter.removeNic(nic)
+ iface = None if nic == iface else iface
- del bondings[bond]
+ # Now we can restart changed interface
+ if iface:
+ ifdown(iface)
+ ifup(iface)
+
+ def editNetwork(self, oldBridge, newBridge, vlan=None, bonding=None,
+ nics=None, **options):
+ configWriter = ConfigWriter()
+ try:
+ self.delNetwork(oldBridge, configWriter=configWriter, **options)
+ self.addNetwork(newBridge, vlan=vlan, bonding=bonding, nics=nics,
+ configWriter=configWriter, **options)
+ except:
+ configWriter.restoreBackups()
+ raise
+ if utils.tobool(options.get('connectivityCheck', False)):
+ if not clientSeen(int(options.get('connectivityTimeout',
+ CONNECTIVITY_TIMEOUT_DEFAULT))):
+ delNetwork(newBridge, force=True)
+ configWriter.restoreBackups()
+ return define.errCode['noConPeer']['status']['code']
+
+ def _editBondings(self, bondings, configWriter):
+ """ Add/Edit bond interface """
+ logger = logging.getLogger("_editBondings")
+
+ _netinfo = netinfo.NetInfo()
+
+ for bond, bondAttrs in bondings.iteritems():
+ logger.debug("Creating/Editing bond %s with attributes %s",
+ bond, bondAttrs)
+
+ brNets = list(_netinfo.getBridgedNetworksForIface(bond))
+ # Only one bridged-non-VLANed network allowed on same nic/bond
+ bridge = brNets[0] if brNets else None
+
+ 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)
+
+ # 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)
+ # NICs must be activated in the same order of boot time
+ # to expose the correct MAC address.
+ for nic in nicSort(bondAttrs['nics']):
+ ifup(nic)
+
+ def _removeBondings(self, bondings, configWriter):
+ """ Remove bond interface """
+ logger = logging.getLogger("_removeBondings")
+
+ _netinfo = netinfo.NetInfo()
+
+ for bond, bondAttrs in bondings.items():
+ 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)
+
+ del bondings[bond]
+
+ def setupNetworks(self, networks={}, bondings={}, **options):
+
+ logger = logging.getLogger("setupNetworks")
+
+ try:
+ _netinfo = netinfo.NetInfo()
+ configWriter = ConfigWriter()
+ networksAdded = set()
+ # keep set netsWithNewBonds to be able remove
+ # a new added network if connectivity check fail.
+ # If a new network needs to be created on top of existing bond,
+ # we will need to keep the bond on rollback flow,
+ # else we will break the new created bond.
+ netsWithNewBonds = set()
+
+ logger.debug("Setting up network according to configuration: "
+ "networks:%r, bondings:%r, options:%r" % (networks,
+ bondings, options))
+
+ force = options.get('force', False)
+ if not utils.tobool(force):
+ logging.debug("Validating configuration")
+ _validateNetworkSetup(dict(networks), dict(bondings))
+
+ logger.debug("Applying...")
+ try:
+ # Remove edited networks and networks with 'remove' attribute
+ for network, networkAttrs in networks.items():
+ if network in _netinfo.networks:
+ logger.debug("Removing network %r" % network)
+ self.delNetwork(network, configWriter=configWriter,
+ force=force, implicitBonding=False)
+ if 'remove' in networkAttrs:
+ del networks[network]
+ else:
+ networksAdded.add(network)
+
+ # Remove bonds with 'remove' attribute
+ self._removeBondings(bondings, configWriter)
+
+ # Check whether bonds should be resized
+ self._editBondings(bondings, configWriter)
+
+ # We need to use the newest host info
+ _ni = netinfo.NetInfo()
+ for network, networkAttrs in networks.iteritems():
+ d = dict(networkAttrs)
+ if 'bonding' in d:
+ # we may not receive any information
+ # about the bonding device if it is unchanged
+ # In this case check whether this bond exists
+ # on host and take its parameters
+ if bondings.get(d['bonding']):
+ d['nics'] = bondings[d['bonding']]['nics']
+ d['bondingOptions'] = \
+ bondings[d['bonding']].get('options', None)
+ # we create a new bond
+ if network in networksAdded:
+ netsWithNewBonds.add(network)
+ elif d['bonding'] in _ni.bondings:
+ logger.debug("Updating bond %r info", d['bonding'])
+ d['nics'] = _ni.bondings[d['bonding']]['slaves']
+ d['bondingOptions'] = \
+ _ni.bondings[d['bonding']]['cfg'].get(
+ 'BONDING_OPTS', None)
+ else:
+ d['nics'] = [d.pop('nic')]
+ d['force'] = force
+
+ logger.debug("Adding network %r" % network)
+ self.addNetwork(network, configWriter=configWriter,
+ implicitBonding=True, **d)
+
+ if utils.tobool(options.get('connectivityCheck', True)):
+ logger.debug('Checking connectivity...')
+ if not clientSeen(int(options.get('connectivityTimeout',
+ CONNECTIVITY_TIMEOUT_DEFAULT))):
+ logger.info('Connectivity check failed, rolling back')
+ for network in networksAdded:
+ self.delNetwork(network, force=True,
+ implicitBonding=network in netsWithNewBonds)
+ raise ConfigNetworkError(ne.ERR_LOST_CONNECTION,
+ 'connectivity check failed')
+ except:
+ configWriter.restoreBackups()
+ raise
+
+ except Exception, e:
+ # SuperVdsm eats the error, so let's print it ourselves
+ logger.error(e, exc_info=True)
+ raise
+
+
+configurator = NativeConfigurator()
+
+
+def addNetwork(network, vlan=None, bonding=None, nics=None, ipaddr=None,
+ netmask=None, mtu=None, gateway=None, force=False,
+ bondingOptions=None, bridged=True, **options):
+ configurator.addNetwork(network, vlan, bonding, nics, ipaddr, netmask, mtu,
+ gateway, force, bondingOptions, bridged, **options)
+
+
+def delNetwork(network, vlan=None, bonding=None, nics=None, force=False,
+ implicitBonding=True, **options):
+ configurator.delNetwork(network, vlan, bonding, nics, force,
+ implicitBonding, **options)
+
+
+def editNetwork(oldBridge, newBridge, vlan=None, bonding=None, nics=None,
+ **options):
+ configurator.editNetwork(oldBridge, newBridge, vlan, bonding, nics,
+ **options)
def setupNetworks(networks={}, bondings={}, **options):
@@ -1277,95 +1358,40 @@
the attachment in the network's attributes). Similarly, if you edit
a bonding, it's not necessary to specify its networks.
"""
- logger = logging.getLogger("setupNetworks")
+ configurator.setupNetworks(networks, bondings, **options)
- try:
- _netinfo = netinfo.NetInfo()
- configWriter = ConfigWriter()
- networksAdded = set()
- # keep set netsWithNewBonds to be able remove
- # a new added network if connectivity check fail.
- # If a new network needs to be created on top of existing bond,
- # we will need to keep the bond on rollback flow,
- # else we will break the new created bond.
- netsWithNewBonds = set()
- logger.debug("Setting up network according to configuration: "
- "networks:%r, bondings:%r, options:%r" % (networks,
- bondings, options))
+def showNetwork(network):
+ _netinfo = netinfo.NetInfo()
+ if network not in _netinfo.networks:
+ print "Network %r doesn't exist" % network
+ return
- force = options.get('force', False)
- if not utils.tobool(force):
- logging.debug("Validating configuration")
- _validateNetworkSetup(dict(networks), dict(bondings))
+ bridged = _netinfo.networks[network]['bridged']
+ print "Network %s(Bridged: %s):" % (network, bridged)
- logger.debug("Applying...")
- try:
- # Remove edited networks and networks with 'remove' attribute
- for network, networkAttrs in networks.items():
- if network in _netinfo.networks:
- logger.debug("Removing network %r" % network)
- delNetwork(network, configWriter=configWriter, force=force,
- implicitBonding=False)
- if 'remove' in networkAttrs:
- del networks[network]
- else:
- networksAdded.add(network)
+ nics, vlan, bonding = _netinfo.getNicsVlanAndBondingForNetwork(network)
- # Remove bonds with 'remove' attribute
- _removeBondings(bondings, configWriter)
+ if bridged:
+ ipaddr = _netinfo.networks[network]['addr']
+ netmask = _netinfo.networks[network]['netmask']
+ gateway = _netinfo.networks[network]['gateway']
+ print "ipaddr=%s, netmask=%s, gateway=%s" % (ipaddr, netmask, gateway)
+ else:
+ iface = _netinfo.networks[network]['iface']
+ ipaddr = _netinfo.nics[iface]['addr']
+ netmask = _netinfo.nics[iface]['netmask']
+ print "ipaddr=%s, netmask=%s" % (ipaddr, netmask)
- # Check whether bonds should be resized
- _editBondings(bondings, configWriter)
+ print "vlan=%s, bonding=%s, nics=%s" % (vlan, bonding, nics)
- # We need to use the newest host info
- _ni = netinfo.NetInfo()
- for network, networkAttrs in networks.iteritems():
- d = dict(networkAttrs)
- if 'bonding' in d:
- # we may not receive any information
- # about the bonding device if it is unchanged
- # In this case check whether this bond exists
- # on host and take its parameters
- if bondings.get(d['bonding']):
- d['nics'] = bondings[d['bonding']]['nics']
- d['bondingOptions'] = \
- bondings[d['bonding']].get('options', None)
- # we create a new bond
- if network in networksAdded:
- netsWithNewBonds.add(network)
- elif d['bonding'] in _ni.bondings:
- logger.debug("Updating bond %r info", d['bonding'])
- d['nics'] = _ni.bondings[d['bonding']]['slaves']
- d['bondingOptions'] = \
- _ni.bondings[d['bonding']]['cfg'].get(
- 'BONDING_OPTS', None)
- else:
- d['nics'] = [d.pop('nic')]
- d['force'] = force
- logger.debug("Adding network %r" % network)
- addNetwork(network, configWriter=configWriter,
- implicitBonding=True, **d)
-
- if utils.tobool(options.get('connectivityCheck', True)):
- logger.debug('Checking connectivity...')
- if not clientSeen(int(options.get('connectivityTimeout',
- CONNECTIVITY_TIMEOUT_DEFAULT))):
- logger.info('Connectivity check failed, rolling back')
- for network in networksAdded:
- delNetwork(network, force=True,
- implicitBonding=network in netsWithNewBonds)
- raise ConfigNetworkError(ne.ERR_LOST_CONNECTION,
- 'connectivity check failed')
- except:
- configWriter.restoreBackups()
- raise
-
- except Exception, e:
- # SuperVdsm eats the error, so let's print it ourselves
- logger.error(e, exc_info=True)
- raise
+def listNetworks():
+ _netinfo = netinfo.NetInfo()
+ print "Networks:", _netinfo.networks.keys()
+ print "Vlans:", _netinfo.vlans.keys()
+ print "Nics:", _netinfo.nics.keys()
+ print "Bondings:", _netinfo.bondings.keys()
def setSafeNetworkConfig():
--
To view, visit http://gerrit.ovirt.org/7915
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I052955a8e2b7b92b123a5179afd15b79798e6c50
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Mark Wu <wudxw(a)linux.vnet.ibm.com>
11 years, 4 months
Change in vdsm[master]: WIP: Add netcf support
by wudxw@linux.vnet.ibm.com
Mark Wu has uploaded a new change for review.
Change subject: WIP: Add netcf support
......................................................................
WIP: Add netcf support
Change-Id: I0070ea45de9d75570168410913a0aef62bcd940a
Signed-off-by: Mark Wu <wudxw(a)linux.vnet.ibm.com>
---
M vdsm/configNetwork.py
1 file changed, 314 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/18/8618/1
diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index 0f6de37..abf4e1f 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -26,6 +26,7 @@
import time
import logging
import threading
+import xml.dom.minidom
from xml.sax.saxutils import escape
import glob
import shutil
@@ -1299,6 +1300,319 @@
raise
+class Netcf(object):
+
+ def __init__(self):
+ self.doc = xml.dom.minidom.Document()
+ self.conn = libvirtconnection.get()
+
+ def addIfaceType(self, ifaceType, name):
+ interface = self.doc.createElement('interface')
+ interface.setAttribute('type', ifaceType)
+ interface.setAttribute('name', name)
+ return interface
+
+ def addTopIfaceAttrs(self, topIface, ipaddr=None, netmask=None,
+ gateway=None, mtu=None, dhcp=False, onboot=True):
+
+ def toNetmaskBits(netmask):
+ num = int(''.join('%02x' % int(i) for i in netmask.split('.')), 16)
+ bits = 32
+ while num / 2 != 0:
+ if num % 2 == 0:
+ bits -= 1
+ num /= 2
+ return bits
+
+ firstChild = topIface.firstChild
+
+ if onboot:
+ start = self.doc.createElement('start')
+ start.setAttribute('mode', 'onboot')
+ topIface.insertBefore(start, firstChild)
+
+ if mtu != None:
+ mtuChild = self.doc.createElement('mtu')
+ mtuChild.setAttribute('size', str(mtu))
+ topIface.insertBefore(mtuChild, firstChild)
+
+ protocol = self.doc.createElement('protocol')
+ protocol.setAttribute('family', "ipv4")
+ if ipaddr:
+ ip = self.doc.createElement('ip')
+ ip.setAttribute('address', (pipes.quote(ipaddr)))
+ prefix = str(toNetmaskBits(pipes.quote(netmask)))
+ ip.setAttribute('prefix', prefix)
+ protocol.appendChild(ip)
+ if gateway:
+ route = self.doc.createElement('route')
+ route.setAttribute('gateway', (pipes.quote(gateway)))
+ protocol.appendChild(ip)
+ elif dhcp:
+ dhcp = self.doc.createElement('dhcp')
+ protocol.appendChild(dhcp)
+ topIface.insertBefore(protocol, firstChild)
+ return topIface
+
+ def addBridge(self, name, port, ipaddr=None, netmask=None, mtu=None,
+ gateway=None, bootproto=None, delay='0', onboot='yes', **kwargs):
+ """
+ <interface type="bridge" name="br0">
+ <start mode="onboot"/>
+ <mtu size="1500"/>
+ <protocol family="ipv4">
+ <ip address="192.168.0.5" prefix="24"/>
+ <route gateway="192.168.0.1"/>
+ </protocol>
+ <bridge stp="off" delay="0.01">
+ <interface type="ethernet" name="eth0">
+ <mac address="ab:bb:cc:dd:ee:ff"/>
+ </interface>
+ <interface type="ethernet" name="eth1"/>
+ </bridge>
+ </interface>
+ """
+
+ brIface = self.addIfaceType('bridge', pipes.quote(name))
+ self.addTopIfaceAttrs(brIface, ipaddr, netmask, mtu, gateway)
+ bridge = self.doc.createElement('bridge')
+ bridge.setAttribute('delay', pipes.quote(delay))
+ # fix me need send a patch to allow set 'NM_CONTROLLED=no\n'
+ bridge.appendChild(port)
+ brIface.appendChild(bridge)
+ return brIface
+
+ """
+ <start mode="onboot"/>
+ <protocol family="ipv4">
+ <dhcp peerdns="no"/>
+ </protocol>
+ """
+ def addBareVlan(self, vlanId, iface):
+ """
+ <interface type="vlan" name="eth0.42">
+ <vlan tag="42">
+ <interface name="eth0"/>
+ </vlan>
+ </interface>
+ """
+ ifaceName = iface.getAttribute('name')
+ vlanIface = self.addIfaceType("vlan", ifaceName + '.' + vlanId)
+ vlanDev = self.doc.createElement("vlan")
+ vlanDev.setAttribute("tag", vlanId)
+ nicIface = self.doc.createElement("interface")
+ nicIface.setAttribute("name", ifaceName)
+ vlanDev.appendChild(nicIface)
+ vlanIface.appendChild(vlanDev)
+ return vlanIface
+
+ def addBareBonding(self, bonding, slaves, bondingOptions=None):
+ """
+ <interface type="bond" name="bond0">
+ <bond mode="active-backup">
+ <arpmon interval="10" target="192.168.122.1"/>
+ <interface type="ethernet" name="eth0">
+ <mac address="ab:bb:cc:dd:ee:ff"/>
+ </interface>
+ <interface type="ethernet" name="eth1"/>
+ </bond>
+ </interface>
+ """
+ bondIface = self.addIfaceType("bond", bonding)
+ bond = self.doc.createElement('bond')
+ # Todo: parse bonding options
+ # the default options is bondingOptions = 'mode=802.3ad miimon=150'
+ bond.setAttribute('mode', "802.3ad")
+ for slave in slaves:
+ bond.appendChild(slave)
+ bondIface.appendChild(bond)
+ return bondIface
+
+ def addBareNic(self, nic):
+ """
+ <interface type="ethernet" name="eth0">
+ <mac address="ab:bb:cc:dd:ee:ff"/>
+ </interface>
+ """
+ _netinfo = netinfo.NetInfo()
+ hwaddr = _netinfo.nics[nic].get('permhwaddr') or \
+ _netinfo.nics[nic]['hwaddr']
+
+ nicIface = self.addIfaceType('ethernet', nic)
+ mac = self.doc.createElement('mac')
+ mac.setAttribute('address', hwaddr)
+ nicIface.appendChild(mac)
+ return nicIface
+
+ def netcfDefineIface(self, xmlstr):
+ try:
+ self.conn.interfaceDefineXML(xmlstr, 0)
+ except:
+ logging.error('Failed to define interface', exc_info=True)
+
+ def netcfCreateIface(self, ifaceName):
+ iface = self.conn.interfaceLookupByName(ifaceName)
+ iface.create(0)
+
+ def netcfUndefineIface(self, ifaceName):
+ iface = self.conn.interfaceLookupByName(ifaceName)
+ if iface.isActive():
+ iface.destroy(0)
+ #Todo implement configuration rollback
+ #self.conn.changeBegin(0)
+ iface.undefine()
+
+ #self.conn.changeCommit(0)
+ #self.conn.changeRollback(0)
+
+ def _createNetwork(self, netXml):
+ conn = libvirtconnection.get()
+ net = conn.networkDefineXML(netXml)
+ net.create()
+ net.setAutostart(1)
+
+ def createLibvirtNetwork(self, network, bridged=True, iface=None,
+ skipBackup=False):
+ netName = netinfo.LIBVIRT_NET_PREFIX + network
+ if bridged:
+ netXml = '''<network><name>%s</name><forward mode='bridge'/>
+ <bridge name='%s'/></network>''' % (escape(netName),
+ escape(network))
+ else:
+ netXml = '''<network><name>%s</name><forward mode='passthrough'>
+ <interface dev='%s'/></forward></network>''' % \
+ (escape(netName), escape(iface))
+ if not skipBackup:
+ self._networkBackup(network)
+ self._createNetwork(netXml)
+
+ def _removeNetwork(self, network):
+ netName = netinfo.LIBVIRT_NET_PREFIX + network
+ conn = libvirtconnection.get()
+
+ net = conn.networkLookupByName(netName)
+ if net.isActive():
+ net.destroy()
+ if net.isPersistent():
+ net.undefine()
+
+ def removeLibvirtNetwork(self, network, skipBackup=False):
+ if not skipBackup:
+ self._networkBackup(network)
+ self._removeNetwork(network)
+
+ def _networkBackup(self, network):
+ """Not impolemented now"""
+
+ pass
+
+
+class NetcfConfigurator():
+
+ def __init__(self):
+ self.configWriter = Netcf()
+
+ def addNetwork(self, network, vlan=None, bonding=None, nics=None,
+ ipaddr=None, netmask=None, mtu=None, gateway=None,
+ force=False, configWriter=None, bondingOptions=None,
+ bridged=True, **options):
+ nics = nics or ()
+ _netinfo = netinfo.NetInfo()
+ bridged = utils.tobool(bridged)
+
+ if mtu:
+ mtu = int(mtu)
+
+ # Validation
+ if not utils.tobool(force):
+ logging.debug('validating network...')
+ _addNetworkValidation(_netinfo, network=network,
+ vlan=vlan, bonding=bonding, nics=nics, ipaddr=ipaddr,
+ netmask=netmask, gateway=gateway,
+ bondingOptions=bondingOptions, bridged=bridged, **options)
+
+ logging.info("Adding network %s with vlan=%s, bonding=%s, nics=%s,"
+ " bondingOptions=%s, mtu=%s, bridged=%s, options=%s",
+ network, vlan, bonding, nics, bondingOptions,
+ mtu, bridged, options)
+
+ # Todo, consider mtu support for multiple vlans
+
+ nic = nics[0] if nics else None
+ iface = bonding or nic
+
+ # take down nics that need to be changed
+ vlanedIfaces = [v['iface'] for v in _netinfo.vlans.values()]
+ if bonding not in vlanedIfaces:
+ for nic in nics:
+ if nic not in vlanedIfaces:
+ ifdown(nic)
+
+ if bridged:
+ ifdown(network)
+
+ slaves = []
+ for nic in nics:
+ topIface = self.configWriter.addBareNic(nic)
+ slaves.append(topIface)
+ if bonding:
+ topIface = self.configWriter.addBareBonding(bonding, slaves,
+ bondingOptions)
+ if vlan:
+ # netcf doesn't allow create the underlying device together with
+ # vlan. So create the underlying device before vlan.
+ topIface = self.configWriter.addTopIfaceAttrs(topIface)
+ topIfaceXml = topIface.toprettyxml(encoding='utf-8')
+ self.configWriter.netcfDefineIface(topIfaceXml)
+ topIface = self.configWriter.addBareVlan(vlan, topIface)
+ if bridged:
+ topIface = self.configWriter.addBridge(
+ network, port=topIface, ipaddr=ipaddr, netmask=netmask,
+ mtu=mtu, gateway=gateway, **options)
+ else:
+ topIface = self.configWriter.addTopIfaceAttrs(
+ topIface, ipaddr=ipaddr, netmask=netmask, mtu=mtu,
+ gateway=gateway)
+
+ self.configWriter.netcfDefineIface(
+ topIface.toprettyxml(encoding='utf-8'))
+
+ # Todo consider dhcp block issue
+ ifaceName = topIface.getAttribute('name')
+ self.configWriter.netcfCreateIface(ifaceName)
+ # add libvirt network
+ self.configWriter.createLibvirtNetwork(network, bridged, iface)
+
+ def delNetworkNetcf(self, network, vlan=None, bonding=None, nics=None,
+ force=False, configWriter=None, implicitBonding=True,
+ **options):
+ _netinfo = netinfo.NetInfo()
+
+ if network not in _netinfo.networks:
+ logging.info("Network %r: doesn't exist in libvirt database",
+ network)
+ if network in netinfo.bridges():
+ self.configWriter.removeBridge(network)
+ else:
+ raise ConfigNetworkError(ne.ERR_BAD_BRIDGE,
+ "Cannot delete network %r: It doesn't exist "
+ "in the system" % network)
+
+ if vlan:
+ self.configWriter.removeVlan(vlan, bonding or nics[0])
+
+ return
+
+ self.configWriter.removeLibvirtNetwork(network, log=False)
+ # We need to gather NetInfo again to refresh networks info from
+ # libvirt. The deleted bridge should never be up at this stage.
+ if network in netinfo.NetInfo().networks:
+ raise ConfigNetworkError(ne.ERR_USED_BRIDGE,
+ "delNetwork: bridge %s still exists" % network)
+
+ self.configWriter.netcfUndefineIface(network)
+
+
configurator = NativeConfigurator()
--
To view, visit http://gerrit.ovirt.org/8618
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0070ea45de9d75570168410913a0aef62bcd940a
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Mark Wu <wudxw(a)linux.vnet.ibm.com>
11 years, 4 months
Change in vdsm[master]: Remove unused qemuImg.py.
by ewarszaw@redhat.com
Eduardo has uploaded a new change for review.
Change subject: Remove unused qemuImg.py.
......................................................................
Remove unused qemuImg.py.
Change-Id: Ib3ff2fe876a838306a15b6773aa810c8102e30fa
Signed-off-by: Eduardo <ewarszaw(a)redhat.com>
---
M vdsm.spec.in
M vdsm/Makefile.am
D vdsm/qemuImg.py
3 files changed, 0 insertions(+), 97 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/82/5582/1
--
To view, visit http://gerrit.ovirt.org/5582
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib3ff2fe876a838306a15b6773aa810c8102e30fa
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Eduardo <ewarszaw(a)redhat.com>
11 years, 4 months
Change in vdsm[master]: Adding threads limitation to misc.tmap
by ybronhei@redhat.com
Yaniv Bronhaim has uploaded a new change for review.
Change subject: Adding threads limitation to misc.tmap
......................................................................
Adding threads limitation to misc.tmap
Using threads queue to keep the threads order and limit threads count
I moved the function code next to itmap for readability.
Currently noone calls to tmap function, so I don't care to change and
fix it now to avoid future bugs.
Exceptions that related to the queue usage will be raised as part of
the function's exceptions.
Signed-off-by: Yaniv Bronhaim <ybronhei(a)redhat.com>
Change-Id: I07845bfd78b9215e8994ac2ebe46a7ff78c85625
---
M vdsm/storage/misc.py
1 file changed, 59 insertions(+), 36 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/58/8858/1
diff --git a/vdsm/storage/misc.py b/vdsm/storage/misc.py
index 426d181..f1a4581 100644
--- a/vdsm/storage/misc.py
+++ b/vdsm/storage/misc.py
@@ -1085,42 +1085,6 @@
return tuple(res)
-def tmap(func, iterable):
- resultsDict = {}
- error = [None]
-
- def wrapper(f, arg, index):
- try:
- resultsDict[index] = f(arg)
- except Exception, e:
- # We will throw the last error received
- # we can only throw one error, and the
- # last one is as good as any. This shouldn't
- # happen. Wrapped methods should not throw
- # exceptions, if this happens it's a bug
- log.error("tmap caught an unexpected error", exc_info=True)
- error[0] = e
- resultsDict[index] = None
-
- threads = []
- for i, arg in enumerate(iterable):
- t = threading.Thread(target=wrapper, args=(func, arg, i))
- threads.append(t)
- t.start()
-
- for t in threads:
- t.join()
-
- results = [None] * len(resultsDict)
- for i, result in resultsDict.iteritems():
- results[i] = result
-
- if error[0] is not None:
- raise error[0]
-
- return tuple(results)
-
-
def getfds():
return [int(fd) for fd in os.listdir("/proc/self/fd")]
@@ -1251,6 +1215,65 @@
raise exception
+def tmap(func, iterable, maxthreads=UNLIMITED_THREADS):
+ """
+ Make an iterator that computes the function using arguments from the
+ iterable by running each operation in a different thread in specific
+ order.
+ maxthreads stands for maximum threads that we can initiate simultaneosly.
+ If we reached to max threads the function waits for thread to
+ finish before initiate the next one.
+ """
+ if maxthreads < 1 and maxthreads != UNLIMITED_THREADS:
+ raise ValueError("Wrong input passed to function tmap: %s", maxthreads)
+
+ resultsDict = {}
+ error = [None]
+
+ def wrapper(f, arg, index):
+ try:
+ resultsDict[index] = f(arg)
+ except Exception, e:
+ # We will throw the last error received
+ # we can only throw one error, and the
+ # last one is as good as any. This shouldn't
+ # happen. Wrapped methods should not throw
+ # exceptions, if this happens it's a bug
+ log.error("tmap caught an unexpected error", exc_info=True)
+ error[0] = e
+ resultsDict[index] = None
+
+ if maxthreads != UNLIMITED_THREADS:
+ threadsQueue = Queue.Queue(maxthreads)
+ else:
+ threadsQueue = Queue.Queue()
+
+ for i, arg in enumerate(iterable):
+ if not threadsQueue.full():
+ t = threading.Thread(target=wrapper, args=(func, arg, i))
+ threadsQueue.put_nowait(t)
+ t.start()
+ else:
+ # waits for the first unfinished thread in list to finish if we
+ # have already initiate all possible thread's slots (maxthreads)
+ if threadsQueue.empty():
+ raise RuntimeError("No thread initieated")
+ else:
+ threadsQueue.get_nowait().join()
+
+ while not threadsQueue.empty():
+ threadsQueue.get(False).join()
+
+ results = [None] * len(resultsDict)
+ for i, result in resultsDict.iteritems():
+ results[i] = result
+
+ if error[0] is not None:
+ raise error[0]
+
+ return tuple(results)
+
+
def itmap(func, iterable, maxthreads=UNLIMITED_THREADS):
"""
Make an iterator that computes the function using
--
To view, visit http://gerrit.ovirt.org/8858
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I07845bfd78b9215e8994ac2ebe46a7ff78c85625
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Yaniv Bronhaim <ybronhei(a)redhat.com>
11 years, 4 months
Change in vdsm[master]: BZ#841555 A migration failure with an "AttributeError" excep...
by ghammer@redhat.com
Gal Hammer has uploaded a new change for review.
Change subject: BZ#841555 A migration failure with an "AttributeError" exception.
......................................................................
BZ#841555 A migration failure with an "AttributeError" exception.
Libvirt sometimes send the SUSPENDED/SUSPENDED_PAUSED event
after RESUMED/RESUMED_MIGRATED (when VM status is PAUSED
when migration completes, see qemuMigrationFinish function).
In this case self._dom is None because the function
_waitForIncomingMigrationFinish didn't update it yet.
Change-Id: I3b7ed13c6dc8d1d590449118cf167290f4630070
Signed-off-by: Gal Hammer <ghammer(a)redhat.com>
---
M vdsm/libvirtvm.py
1 file changed, 7 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/01/6901/1
--
To view, visit http://gerrit.ovirt.org/6901
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3b7ed13c6dc8d1d590449118cf167290f4630070
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Gal Hammer <ghammer(a)redhat.com>
11 years, 4 months
Change in vdsm[master]: BZ#840407 - Create a fake template when moving to backup SD.
by ewarszaw@redhat.com
Eduardo has uploaded a new change for review.
Change subject: BZ#840407 - Create a fake template when moving to backup SD.
......................................................................
BZ#840407 - Create a fake template when moving to backup SD.
This code is repeated twice because the copy in deprecated
moveMultipleImages() will be removed when this image will be
removed in the next version.
All the related fake template code should be removed.
Change-Id: Ibbeef2480e03cc075b80880485739139e496d0b6
Signed-off-by: Eduardo <ewarszaw(a)redhat.com>
---
M vdsm/storage/hsm.py
1 file changed, 26 insertions(+), 3 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/19/6519/1
--
To view, visit http://gerrit.ovirt.org/6519
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibbeef2480e03cc075b80880485739139e496d0b6
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Eduardo <ewarszaw(a)redhat.com>
11 years, 4 months
Change in vdsm[master]: migrateStatus() progress report
by peet@redhat.com
Peter V. Saveliev has uploaded a new change for review.
Change subject: migrateStatus() progress report
......................................................................
migrateStatus() progress report
The percentage is based on libvirt dataTotal and dataProcessed
fields of the virDomainJobInfo struct
Signed-off-by: Peter V. Saveliev <peet(a)redhat.com>
Change-Id: I3ff00e85c88e865cd81697d427d6bd5473e0f79e
---
M vdsm/vm.py
1 file changed, 11 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/24/6824/1
--
To view, visit http://gerrit.ovirt.org/6824
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3ff00e85c88e865cd81697d427d6bd5473e0f79e
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Peter V. Saveliev <peet(a)redhat.com>
11 years, 4 months
Change in vdsm[master]: Rename parent volume in blockSD.getAllVolumes.
by ewarszaw@redhat.com
Eduardo has uploaded a new change for review.
Change subject: Rename parent volume in blockSD.getAllVolumes.
......................................................................
Rename parent volume in blockSD.getAllVolumes.
Change-Id: I62f1385e4af90a923c5d97a71571bea8780aa339
Signed-off-by: Eduardo <ewarszaw(a)redhat.com>
---
M vdsm/storage/blockSD.py
1 file changed, 5 insertions(+), 5 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/08/8608/1
diff --git a/vdsm/storage/blockSD.py b/vdsm/storage/blockSD.py
index e596fb6..d8f7824 100644
--- a/vdsm/storage/blockSD.py
+++ b/vdsm/storage/blockSD.py
@@ -159,14 +159,14 @@
for vName in vols.iterkeys():
res[vName] = {'imgs': [], 'parent': None}
- for vName, vImg, vPar in vols.itervalues():
- res[vName]['parent'] = vPar
+ for vName, vImg, parentVol in vols.itervalues():
+ res[vName]['parent'] = parentVol
if vImg not in res[vName]['imgs']:
res[vName]['imgs'].insert(0, vImg)
- if vPar != sd.BLANK_UUID and \
+ if parentVol != sd.BLANK_UUID and \
not vName.startswith(blockVolume.image.REMOVED_IMAGE_PREFIX) \
- and vImg not in res[vPar]['imgs']:
- res[vPar]['imgs'].append(vImg)
+ and vImg not in res[parentVol]['imgs']:
+ res[parentVol]['imgs'].append(vImg)
return dict((k, sd.ImgsPar(tuple(v['imgs']), v['parent']))
for k, v in res.iteritems())
--
To view, visit http://gerrit.ovirt.org/8608
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I62f1385e4af90a923c5d97a71571bea8780aa339
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Eduardo <ewarszaw(a)redhat.com>
11 years, 4 months
Change in vdsm[master]: BZ#829110 Remove a "Domain not found" error from stats threa...
by ghammer@redhat.com
Gal Hammer has uploaded a new change for review.
Change subject: BZ#829110 Remove a "Domain not found" error from stats thread.
......................................................................
BZ#829110 Remove a "Domain not found" error from stats thread.
Removed redundant code which changed VM status if error occured on
the stats thead.
Change-Id: I1f648b9e3a70dca66cbf056c1f143bc6f0455e4a
Signed-off-by: Gal Hammer <ghammer(a)redhat.com>
---
M vdsm/libvirtvm.py
1 file changed, 0 insertions(+), 11 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/46/7746/1
diff --git a/vdsm/libvirtvm.py b/vdsm/libvirtvm.py
index 6323d0c..2f6e544 100644
--- a/vdsm/libvirtvm.py
+++ b/vdsm/libvirtvm.py
@@ -291,17 +291,6 @@
if ex.get_error_code() != libvirt.VIR_ERR_NO_DOMAIN:
return False
- # If a VM is down, hibernating, migrating, destroyed or in the
- # process of being shutdown we were expecting it to disappear
- if ((self._vm.lastStatus in ('Down',
- 'Saving State', 'Migration Source'))
- or self._vm.destroyed
- or self._vm._guestEvent == 'Powering down'):
- return True
-
- self._log.debug("VM not found, moving to Down", exc_info=True)
- self._vm.setDownStatus(ERROR, str(ex))
-
return True
--
To view, visit http://gerrit.ovirt.org/7746
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1f648b9e3a70dca66cbf056c1f143bc6f0455e4a
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Gal Hammer <ghammer(a)redhat.com>
11 years, 4 months