Change in vdsm[master]: Remove innecessary netinfo instance creation.
asegurap at redhat.com
asegurap at redhat.com
Wed Jan 16 10:16:55 UTC 2013
Antoni Segura Puimedon has uploaded a new change for review.
Change subject: Remove innecessary netinfo instance creation.
......................................................................
Remove innecessary netinfo instance creation.
This patch adds more fine-grained resources to undate the
information of a NetInfo instance and uses it avoid complete netinfo
gathering when not necessary.
Change-Id: I0cef02dc89d927799bf92d36b790598707583195
Signed-off-by: Antoni S. Puimedon <asegurap at redhat.com>
---
M vdsm/configNetwork.py
M vdsm/netinfo.py
2 files changed, 32 insertions(+), 15 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/82/11082/1
diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index 6785493..068edb3 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -1134,9 +1134,13 @@
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:
+ # We need to refresh _netifo information. The deleted bridge should never
+ # be up at this stage.
+ try:
+ _netinfo.updateNetwork(network)
+ except KeyError:
+ pass # If the network does not exist continue.
+ else:
raise ConfigNetworkError(ne.ERR_USED_BRIDGE, 'delNetwork: bridge %s '
'still exists' % network)
@@ -1389,8 +1393,8 @@
# Check whether bonds should be resized
_editBondings(bondings, configWriter)
- # We need to use the newest host info
- _ni = netinfo.NetInfo()
+ # We need to use the newest bonding info.
+ _netinfo.updateBonds()
for network, networkAttrs in networks.iteritems():
d = dict(networkAttrs)
if 'bonding' in d:
@@ -1405,11 +1409,11 @@
# we create a new bond
if network in networksAdded:
netsWithNewBonds.add(network)
- elif d['bonding'] in _ni.bondings:
+ elif d['bonding'] in _netinfo.bondings:
logger.debug("Updating bond %r info", d['bonding'])
- d['nics'] = _ni.bondings[d['bonding']]['slaves']
+ d['nics'] = _netinfo.bondings[d['bonding']]['slaves']
d['bondingOptions'] = \
- _ni.bondings[d['bonding']]['cfg'].get(
+ _netinfo.bondings[d['bonding']]['cfg'].get(
'BONDING_OPTS', None)
else:
d['nics'] = [d.pop('nic')]
diff --git a/vdsm/netinfo.py b/vdsm/netinfo.py
index 8015e08..5262647 100644
--- a/vdsm/netinfo.py
+++ b/vdsm/netinfo.py
@@ -294,6 +294,12 @@
raise
+def getBondData(bond):
+ return {'slaves': slaves(bond), 'addr': getaddr(bond),
+ 'netmask': getnetmask(bond), 'hwaddr': gethwaddr(bond),
+ 'cfg': getIfaceCfg(bond), 'mtu': getMtu(bond)}
+
+
def get():
d = {}
routes = getRoutes()
@@ -328,13 +334,8 @@
for nic, nd in d['nics'].iteritems():
if paddr.get(nic):
nd['permhwaddr'] = paddr[nic]
- d['bondings'] = dict([(bond, {'slaves': slaves(bond),
- 'addr': getaddr(bond),
- 'netmask': getnetmask(bond),
- 'hwaddr': gethwaddr(bond),
- 'cfg': getIfaceCfg(bond),
- 'mtu': getMtu(bond)})
- for bond in bondings()])
+
+ d['bondings'] = dict([(bond, getBondData(bond)) for bond in bondings()])
d['vlans'] = dict([(vlan, {'iface': vlan.split('.')[0],
'addr': getaddr(vlan),
'netmask': getnetmask(vlan),
@@ -481,3 +482,15 @@
lnics.append(port)
return lnics, vlan, bonding
+
+ def updateNetwork(self, network):
+ try:
+ self.networks[network] = getNetData(
+ network, self.networks[network]['bridged'], getRoutes())
+ except KeyError:
+ del self.networks[network]
+ raise
+
+ def updateBonds(self):
+ self.bondings = dict([(bond,
+ getBondData(bond)) for bond in bondings()])
--
To view, visit http://gerrit.ovirt.org/11082
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0cef02dc89d927799bf92d36b790598707583195
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap at redhat.com>
More information about the vdsm-patches
mailing list