Antoni Segura Puimedon has uploaded a new change for review. Change subject: mastapatch ......................................................................
mastapatch Change-Id: I8c53f64e2c1851adf5ed510728bf486340a34882 Signed-off-by: Antoni S. Puimedon <asegu...@redhat.com> --- M lib/vdsm/ipwrapper.py M lib/vdsm/netinfo.py 2 files changed, 64 insertions(+), 34 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/14/21614/1 diff --git a/lib/vdsm/ipwrapper.py b/lib/vdsm/ipwrapper.py index 5b7a549..e27f189 100644 --- a/lib/vdsm/ipwrapper.py +++ b/lib/vdsm/ipwrapper.py @@ -70,6 +70,15 @@ TEAM = 'team' VETH = 'veth' + def fakeNicTypes(cls): + return (cls.DUMMY, cls.VETH) + + def nicTypes(cls): + return (cls.NIC, cls.DUMMY, cls.VETH) + + def types(cls): + return [linkType for linkType in vars(cls) if not callable(linkType)] + @equals class Link(object): @@ -99,6 +108,17 @@ def __repr__(self): return '%s: %s(%s) %s' % (self.index, self.name, self.type, self.address) + + def __hash__(self): + return hash((self.index, self.name)) + + def __eq__(self, other): + for key in vars(self): + if callable(self.__dict__[key]): + continue + if self.__dict__[key] != getattr(other, key, None): + return False + return True @staticmethod def _parse(text): @@ -203,7 +223,7 @@ Returns True iff vdsm config marks the DUMMY or VETH dev to be reported as NIC. """ - if self.isDUMMY() or self.isVETH(): + if self.type in LinkType.fakeNicTypes(): return anyFnmatch(self.name, self._fakeNics) return False diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py index 1dc7455..bcca487 100644 --- a/lib/vdsm/netinfo.py +++ b/lib/vdsm/netinfo.py @@ -34,6 +34,7 @@ from .config import config from . import constants from .ipwrapper import getLink, getLinks +from .ipwrapper import LinkType from .ipwrapper import Route from .ipwrapper import routeShowAllDefaultGateways from . import libvirtconnection @@ -67,41 +68,52 @@ OPERSTATE_UP = 'up' +class DevicePool(object): + _hiddenFilter = lambda x: not x.isHidden() + + def __init__(self, *linkTypes): + self.devs = dict((linkType, set()) for linkType in linkTypes) + + def __iter__(self): + return self.devs.__iter__() + + def __getitem__(self, key): + return self.devs.__getitem__(key) + + def __setitem__(self, key, value): + self.devs.__setitem__(key, value) + + def iterDevices(self, hidden=False): + return self.iterLinkTypes(self.devs.keys(), hidden) + + def iterLinkTypes(self, linkTypes, hidden=False): + for dev in chain(*(self.devs[linkType] for linkType in linkTypes)): + if hidden or not dev.isHidden(): + yield dev + + +devicePool = DevicePool(*LinkType.types()) + + def nics(): """Returns a list of nics and fake nics devices available (not hidden) to be used by vdsm.""" - return [dev.name for dev in getLinks() if dev.isNICLike() and - not dev.isHidden()] + return [dev.name for dev in self.iterLinkTypes(LinkType.nicTypes())] def bondings(): """ Returns list of available bonds managed by vdsm. """ - - hidden_bonds = config.get('vars', 'hidden_bonds').split(',') - res = [] - try: - for bond in open(BONDING_MASTERS).readline().split(): - if not anyFnmatch(bond, hidden_bonds): - res.append(bond) - except IOError as e: - if e.errno == os.errno.ENOENT: - return res - else: - raise - - return res + return [dev.name for dev in devicePool.iterLinkTypes([LinkType.BOND])] def vlans(): - return [link.name for link in getLinks() if link.isVLAN() and - not link.isHidden()] + return [dev.name for dev in devicePool.iterLinkTypes([LinkType.VLAN])] def bridges(): - return [b.split('/')[-2] for b in iglob('/sys/class/net/*/bridge') - if b.split('/')[-2] != DUMMY_BRIDGE] + return [dev.name for dev in devicePool.iterLinkTypes([LinkType.BRIDGE])] def networks(): @@ -222,10 +234,6 @@ def isvirtio(dev): return 'virtio' in os.readlink('/sys/class/net/%s/device' % dev) - - -def isbonding(dev): - return os.path.exists('/sys/class/net/%s/bonding' % dev) def operstate(dev): @@ -542,12 +550,11 @@ except KeyError: continue # Do not report missing libvirt networks. - links = filter(lambda x: not x.isHidden(), getLinks()) - d['bridges'] = dict(_bridgeinfo(dev, gateways, ipv6routes) for dev - in links if dev.isBRIDGE()) - d['nics'] = dict(_nicinfo(dev, paddr) for dev in links if dev.isNICLike()) - d['bondings'] = dict(_bondinfo(dev) for dev in links if dev.isBOND()) - d['vlans'] = dict(_vlaninfo(dev) for dev in links if dev.isVLAN()) + d['bridges'] = dict(_bridgeinfo(dev, gateways, ipv6routes) for + dev in devicePool[LinkType.BRIDGE]) + d['bondings'] = dict(_bondinfo(dev) for dev in devicePool[LinkType.BOND]) + d['vlans'] = dict(_vlaninfo(dev) for dev in devicePool[LinkType.VLAN]) + d['nics'] = dict(_nicinfo(dev, paddr) for dev in devicePool[LinkType.NIC]) return d @@ -564,10 +571,13 @@ return str(out).split(':')[1].strip().split('@')[1] -def getVlanID(vlan): +def getVlanID(vlanName): """ Return the ID of the given VLAN. """ - vlanLink = getLink(vlan) - return int(vlanLink.vlanid) + with open(PROC_NET_VLAN + vlanName) as vlanProcFile: + tokens = vlanProcFile.readline().split(' ') + for index, token in enumerate(tokens): + if token == 'VID:': + return int(tokens[index+1]) def getIpAddresses(): -- To view, visit http://gerrit.ovirt.org/21614 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8c53f64e2c1851adf5ed510728bf486340a34882 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Antoni Segura Puimedon <asegu...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches