Mark Wu has uploaded a new change for review. Change subject: netmodels: Improve getIpConfig using namedtuple ......................................................................
netmodels: Improve getIpConfig using namedtuple Change-Id: I53eb3c4b00f33285a1b299ca0adc6611eb99a989 Signed-off-by: Mark Wu <[email protected]> --- M vdsm/netconf/__init__.py M vdsm/netconf/ifcfg.py M vdsm/netmodels.py M vdsm/sourceRoute.py 4 files changed, 17 insertions(+), 13 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/67/18167/1 diff --git a/vdsm/netconf/__init__.py b/vdsm/netconf/__init__.py index 97a311b..4936fda 100644 --- a/vdsm/netconf/__init__.py +++ b/vdsm/netconf/__init__.py @@ -85,8 +85,7 @@ DynamicSourceRoute.addInterfaceTracking(netEnt) def _removeSourceRoute(self, netEnt): - _, _, _, bootproto, _, _ = netEnt.getIpConfig() - if bootproto != 'dhcp' and netEnt.master is None: + if netEnt.ipConfig.bootproto != 'dhcp' and netEnt.master is None: logging.debug("Removing source route for device %s" % netEnt.name) StaticSourceRoute(netEnt.name, self).remove() diff --git a/vdsm/netconf/ifcfg.py b/vdsm/netconf/ifcfg.py index b3db008..eb47255 100644 --- a/vdsm/netconf/ifcfg.py +++ b/vdsm/netconf/ifcfg.py @@ -60,7 +60,7 @@ self._libvirtAdded = set() def configureBridge(self, bridge, **opts): - ipaddr, netmask, gateway, bootproto, async, _ = bridge.getIpConfig() + ipaddr, netmask, gateway, bootproto, async, _ = bridge.ipConfig self.configApplier.addBridge(bridge, **opts) ifdown(bridge.name) if bridge.port: @@ -69,14 +69,14 @@ ifup(bridge.name, async) def configureVlan(self, vlan, **opts): - ipaddr, netmask, gateway, bootproto, async, _ = vlan.getIpConfig() + ipaddr, netmask, gateway, bootproto, async, _ = vlan.ipConfig self.configApplier.addVlan(vlan, **opts) vlan.device.configure(**opts) self._addSourceRoute(vlan, ipaddr, netmask, gateway, bootproto) ifup(vlan.name, async) def configureBond(self, bond, **opts): - ipaddr, netmask, gateway, bootproto, async, _ = bond.getIpConfig() + ipaddr, netmask, gateway, bootproto, async, _ = bond.ipConfig self.configApplier.addBonding(bond, **opts) if not netinfo.isVlanned(bond.name): for slave in bond.slaves: @@ -96,7 +96,7 @@ self.configureBond(bond) def configureNic(self, nic, **opts): - ipaddr, netmask, gateway, bootproto, async, _ = nic.getIpConfig() + ipaddr, netmask, gateway, bootproto, async, _ = nic.ipConfig self.configApplier.addNic(nic, **opts) self._addSourceRoute(nic, ipaddr, netmask, gateway, bootproto) if nic.bond is None: @@ -490,7 +490,7 @@ def addBridge(self, bridge, **opts): """ Create ifcfg-* file with proper fields for bridge """ ipaddr, netmask, gateway, bootproto, _, defaultRoute = \ - bridge.getIpConfig() + bridge.ipConfig conf = 'TYPE=Bridge\nDELAY=%s\n' % bridge.forwardDelay self._createConfFile(conf, bridge.name, ipaddr, netmask, gateway, bootproto, bridge.mtu, @@ -499,7 +499,7 @@ def addVlan(self, vlan, **opts): """ Create ifcfg-* file with proper fields for VLAN """ ipaddr, netmask, gateway, bootproto, _, defaultRoute = \ - vlan.getIpConfig() + vlan.ipConfig conf = 'VLAN=yes\n' if vlan.bridge: conf += 'BRIDGE=%s\n' % pipes.quote(vlan.bridge.name) @@ -543,7 +543,7 @@ @staticmethod def _getIfaceConfValues(iface, _netinfo): ipaddr, netmask, gateway, bootproto, _, defaultRoute = \ - iface.getIpConfig() + iface.ipConfig defaultRoute = ConfigWriter._toIfcfgFormat(defaultRoute) mtu = iface.mtu if _netinfo.ifaceUsers(iface.name): diff --git a/vdsm/netmodels.py b/vdsm/netmodels.py index fffba2a..95e87f1 100644 --- a/vdsm/netmodels.py +++ b/vdsm/netmodels.py @@ -16,6 +16,7 @@ # # Refer to the README and COPYING files for full details of the license # +from collections import namedtuple from contextlib import contextmanager import logging import os @@ -29,6 +30,9 @@ class NetDevice(object): + _ipConfig = namedtuple('ipConfig', 'ipaddr netmask gateway bootproto \ + async defaultRoute') + def __init__(self, name, configurator, ipconfig=None, mtu=None): self.name = name self.ip = ipconfig @@ -42,14 +46,16 @@ def configure(self, **opts): raise NotImplementedError - def getIpConfig(self): + @property + def ipConfig(self): try: ipaddr, netmask, gateway, bootproto, async, defaultRoute = \ self.ip.getConfig() except AttributeError: ipaddr = netmask = gateway = bootproto = async = defaultRoute = \ None - return ipaddr, netmask, gateway, bootproto, async, defaultRoute + return self._ipConfig(ipaddr, netmask, gateway, bootproto, async, + defaultRoute) @property def bridge(self): diff --git a/vdsm/sourceRoute.py b/vdsm/sourceRoute.py index c05d066..73fe075 100644 --- a/vdsm/sourceRoute.py +++ b/vdsm/sourceRoute.py @@ -101,8 +101,7 @@ @staticmethod def addInterfaceTracking(device): - _, _, _, bootproto, _, _ = device.getIpConfig() - if bootproto == 'dhcp': + if device.ipConfig.bootproto == 'dhcp': open(DynamicSourceRoute.getTrackingFilePath(device.name), 'a').\ close() -- To view, visit http://gerrit.ovirt.org/18167 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I53eb3c4b00f33285a1b299ca0adc6611eb99a989 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Mark Wu <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
