Change in vdsm[master]: Simplify netinfo get.
asegurap at redhat.com
asegurap at redhat.com
Wed Jan 16 09:40:13 UTC 2013
Antoni Segura Puimedon has uploaded a new change for review.
Change subject: Simplify netinfo get.
......................................................................
Simplify netinfo get.
This patch refactors netinfo to have the network data fetching on
a separate function. This reduces the get() complexity and will
allow the possibility of reusing the new method for more fine-
grained information retrieval, e.g., update just a network info
of a Netinfo instance.
Change-Id: I5c3e617d10308d0bfa4deaed329b2e10ef54077c
Signed-off-by: Antoni S. Puimedon <asegurap at redhat.com>
---
M vdsm/netinfo.py
1 file changed, 26 insertions(+), 45 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/80/11080/1
diff --git a/vdsm/netinfo.py b/vdsm/netinfo.py
index f6250c2..e1fd798 100644
--- a/vdsm/netinfo.py
+++ b/vdsm/netinfo.py
@@ -274,57 +274,38 @@
return paddr
+def getNetData(net, bridged, routes):
+ try:
+ if bridged:
+ return {'ports': ports(net), 'stp': bridge_stp_state(net),
+ 'cfg': getIfaceCfg(net)}
+ else:
+ # ovirt-engine-3.1 expects to see the "interface" attribute iff the
+ # network is bridgeless. Please remove the attribute and this
+ # comment when the version is no longer supported.
+ return {'interface': net, 'iface': net, 'bridged': False,
+ 'addr': getaddr(net), 'netmask': getnetmask(net),
+ 'gateway': routes.get(net, '0.0.0.0'), 'mtu': getMtu(net)}
+ except OSError as e:
+ if e.errno == errno.ENOENT:
+ logging.info('Obtaining info for net %s.', net, exc_info=True)
+ raise KeyError('Network %s was not found')
+ else:
+ raise
+
+
def get():
d = {}
routes = getRoutes()
d['networks'] = {}
- nets = networks()
- for netname in nets.iterkeys():
- if nets[netname]['bridged']:
- devname = netname
- try:
- d['networks'][netname] = {'ports': ports(devname),
- 'stp': bridge_stp_state(devname),
- 'cfg': getIfaceCfg(devname), }
- except OSError as e:
- # If the bridge reported by libvirt does not exist anymore, do
- # not report it, as this already assures that the bridge is not
- # added to d['networks']
- if e.errno == errno.ENOENT:
- logging.info('Obtaining info for net %s.', devname,
- exc_info=True)
- continue
- else:
- raise
- else:
- devname = nets[netname]['iface']
- d['networks'][netname] = {}
-
- # ovirt-engine-3.1 expects to see "interface" iff the network is
- # bridgeless. Please remove this line when that Engine version is
- # no longer supported
- d['networks'][netname]['interface'] = devname
-
+ for net, netAttr in networks().iteritems():
try:
- d['networks'][netname].update(
- {'iface': devname,
- 'bridged': nets[netname]['bridged'],
- 'addr': getaddr(devname),
- 'netmask': getnetmask(devname),
- 'gateway': routes.get(devname, '0.0.0.0'),
- 'mtu': getMtu(devname), })
- except OSError as e:
- if e.errno == errno.ENOENT:
- logging.info('Obtaining info for net %s.', devname,
- exc_info=True)
- # When a net is not bridged it will have left an entry in
- # d['networks']
- if netname in d['networks']:
- del d['networks'][netname]
- continue
- else:
- raise
+ d['networks'][net] = getNetData(net, netAttr['bridged'], routes)
+ except KeyError:
+ continue
+ except OSError:
+ raise
d['bridges'] = dict([(bridge, {'ports': ports(bridge),
'stp': bridge_stp_state(bridge),
--
To view, visit http://gerrit.ovirt.org/11080
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5c3e617d10308d0bfa4deaed329b2e10ef54077c
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