Change in vdsm[master]: [1/3] Fix getVlanID() and getVlanDevice()
apahim at redhat.com
apahim at redhat.com
Thu Aug 15 14:59:57 UTC 2013
Amador Pahim has uploaded a new change for review.
Change subject: [1/3] Fix getVlanID() and getVlanDevice()
......................................................................
[1/3] Fix getVlanID() and getVlanDevice()
Previous implementations work only under root privileges.
This patch reimplements both functions to use "ip" tool.
Change-Id: Ieab0f44cf4c4f6f16f81435cb732ccacf57b0767
Signed-off-by: Amador Pahim <apahim at redhat.com>
---
M lib/vdsm/constants.py.in
M lib/vdsm/netinfo.py
2 files changed, 18 insertions(+), 12 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/80/18180/1
diff --git a/lib/vdsm/constants.py.in b/lib/vdsm/constants.py.in
index cfea347..4767304 100644
--- a/lib/vdsm/constants.py.in
+++ b/lib/vdsm/constants.py.in
@@ -98,6 +98,7 @@
EXT_IFDOWN = '@IFDOWN_PATH@'
EXT_IFUP = '@IFUP_PATH@'
EXT_IONICE = '@IONICE_PATH@'
+EXT_IP = '@IP_PATH@'
EXT_ISCSIADM = '@ISCSIADM_PATH@'
EXT_TC = '@TC_PATH@'
diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py
index 1081ec9..ae0f9bb 100644
--- a/lib/vdsm/netinfo.py
+++ b/lib/vdsm/netinfo.py
@@ -37,6 +37,7 @@
from ipwrapper import Route
from ipwrapper import routeShowAllDefaultGateways
import libvirtconnection
+import utils
NET_CONF_DIR = '/etc/sysconfig/network-scripts/'
NET_CONF_BACK_DIR = constants.P_VDSM_LIB + 'netconfback/'
@@ -535,26 +536,30 @@
def getVlanDevice(vlan):
""" Return the device of the given VLAN. """
- dev = None
+ cmd = [constants.EXT_IP, '-o', 'link', 'show', 'dev', vlan]
+ rc, out, err = utils.execCmd(cmd)
- if os.path.exists(PROC_NET_VLAN + vlan):
- for line in file(PROC_NET_VLAN + vlan).readlines():
- if "Device:" in line:
- dummy, dev = line.split()
- break
+ if rc != 0:
+ raise Exception(err)
- return dev
+ # out example:
+ # 6: eth0.10 at eth0: <BROADCAST,MULTICAST> mtu 1500...
+ return str(out).split(':')[1].strip().split('@')[1]
def getVlanID(vlan):
""" Return the ID of the given VLAN. """
vlanId = None
+ cmd = [constants.EXT_IP, '-d', 'link', 'show', 'dev', vlan]
+ rc, out, err = utils.execCmd(cmd)
- if os.path.exists(PROC_NET_VLAN):
- for line in file(PROC_NET_VLAN + vlan).readlines():
- if "VID" in line:
- vlanId = line.split()[2]
- break
+ if rc != 0:
+ raise Exception(err)
+
+ for item in out:
+ if "vlan id" in item:
+ vlanId = item.split()[2]
+ break
return vlanId
--
To view, visit http://gerrit.ovirt.org/18180
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieab0f44cf4c4f6f16f81435cb732ccacf57b0767
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Amador Pahim <apahim at redhat.com>
More information about the vdsm-patches
mailing list