Change in vdsm[master]: linkmonitor: fix reported device name of vlans and macvlans
asegurap at redhat.com
asegurap at redhat.com
Thu Dec 5 00:52:28 UTC 2013
Antoni Segura Puimedon has uploaded a new change for review.
Change subject: linkmonitor: fix reported device name of vlans and macvlans
......................................................................
linkmonitor: fix reported device name of vlans and macvlans
Previously, vlans and macvlans would get the event name reported as:
- 'foo at bar', where bar is the device the foo macvlan sits on.
- 'bond777.555 at bond777', where bond777 is the device the 555 vlan
sits on.
After this fix, both devices would be properly reported as:
- foo
- bond777.555
Change-Id: Ieaeab6adc30a80b70e9e967768c10b3fea65aa16
Signed-off-by: Antoni S. Puimedon <asegurap at redhat.com>
---
M lib/vdsm/ipwrapper.py
1 file changed, 24 insertions(+), 3 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/61/22061/1
diff --git a/lib/vdsm/ipwrapper.py b/lib/vdsm/ipwrapper.py
index 9deb5f7..870b90b 100644
--- a/lib/vdsm/ipwrapper.py
+++ b/lib/vdsm/ipwrapper.py
@@ -18,6 +18,8 @@
#
from collections import namedtuple
+from glob import iglob
+import errno
import os
from netaddr.core import AddrFormatError
@@ -545,7 +547,8 @@
_execCmd(command)
-MonitorEvent = namedtuple('MonitorEvent', ['device', 'flags', 'state'])
+MonitorEvent = namedtuple('MonitorEvent', ['index', 'device', 'flags',
+ 'state'])
class Monitor(object):
@@ -572,7 +575,17 @@
state = cls.LINK_STATE_DELETED
line = line[len(cls._DELETED_TEXT):]
- _, device, data = [el.strip() for el in line.split(':', 2)]
+ ifindex, devName, data = [el.strip() for el in line.split(':', 2)]
+ # We can't get the type of a device no longer in the system
+ if (state != cls.LINK_STATE_DELETED and
+ not os.path.exists('/sys/class/net/' + devName)):
+ try:
+ devName = _dev_get_by_index(ifindex)
+ except OSError as ose:
+ if ose.errno == errno.ENOENT:
+ continue # Skip the device
+ else:
+ raise
flagVal, _ = data.split('\\', 1) # We don't parse link/ether
flags, values = data.split('>')
@@ -585,7 +598,7 @@
state = value
break
- changes.append(MonitorEvent(device, flags, state))
+ changes.append(MonitorEvent(ifindex, devName, flags, state))
return changes
@@ -593,3 +606,11 @@
out, _ = self.proc.communicate()
return self._parse(out)
+
+
+def _dev_get_by_index(ifindex):
+ for filepath in iglob('/sys/class/net/*/ifindex'):
+ with open(filepath) as ifFile:
+ if ifFile.read().strip() == ifindex:
+ return filepath.split('/')[-2]
+ raise OSError(errno.ENOENT, 'No device found for index ' + ifindex)
--
To view, visit http://gerrit.ovirt.org/22061
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieaeab6adc30a80b70e9e967768c10b3fea65aa16
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