Edward Haas has uploaded a new change for review.

Change subject: net: Expose owned_device method through the configurator
......................................................................

net: Expose owned_device method through the configurator

Provide means to check if a device is owned by VDSM specific driver.
In this case, by the ifcfg configurator.

It will be used by a following patch to determine if the device is being
used by the Linux switch.

Change-Id: Ie1febd494c5a01ceecd894e8542c1adb3cda704a
Signed-off-by: Edward Haas <edwa...@redhat.com>
Reviewed-on: https://gerrit.ovirt.org/63442
Reviewed-by: Petr Horáček <phora...@redhat.com>
Continuous-Integration: Jenkins CI
Reviewed-by: Dan Kenigsberg <dan...@redhat.com>
(cherry picked from commit 8e72106a39f435471e591c465b5f49bd934868e7)
---
M lib/vdsm/network/configurators/__init__.py
M lib/vdsm/network/configurators/ifcfg.py
2 files changed, 21 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/95/64095/1

diff --git a/lib/vdsm/network/configurators/__init__.py 
b/lib/vdsm/network/configurators/__init__.py
index 43ddec9..525f3e6 100644
--- a/lib/vdsm/network/configurators/__init__.py
+++ b/lib/vdsm/network/configurators/__init__.py
@@ -97,6 +97,10 @@
     def removeSourceRoute(self, routes, rules, device):
         raise NotImplementedError
 
+    @staticmethod
+    def owned_device(device):
+        raise NotImplementedError
+
     def configureLibvirtNetwork(self, network, iface):
         self.configApplier.createLibvirtNetwork(network,
                                                 isinstance(iface, Bridge),
diff --git a/lib/vdsm/network/configurators/ifcfg.py 
b/lib/vdsm/network/configurators/ifcfg.py
index ea09dc3..33d2aae 100644
--- a/lib/vdsm/network/configurators/ifcfg.py
+++ b/lib/vdsm/network/configurators/ifcfg.py
@@ -67,6 +67,8 @@
 NET_CONF_PREF = NET_CONF_DIR + 'ifcfg-'
 NET_LOGICALNET_CONF_BACK_DIR = NET_CONF_BACK_DIR + 'logicalnetworks/'
 
+CONFFILE_HEADER_SIGNATURE = '# Generated by VDSM version'
+
 
 def is_available():
     return True
@@ -280,11 +282,23 @@
         self._removeSourceRouteFile('rule', device)
         self._removeSourceRouteFile('route', device)
 
+    @staticmethod
+    def owned_device(device):
+        try:
+            with open(misc.NET_CONF_PREF + device) as conf:
+                content = conf.read()
+        except IOError as ioe:
+            if ioe.errno == errno.ENOENT:
+                return False
+            else:
+                raise
+        else:
+            return content.startswith(CONFFILE_HEADER_SIGNATURE)
+
 
 class ConfigWriter(object):
-    CONFFILE_HEADER_BASE = '# Generated by VDSM version'
-    CONFFILE_HEADER = CONFFILE_HEADER_BASE + ' %s' % \
-        dsaversion.raw_version_revision
+    CONFFILE_HEADER = (CONFFILE_HEADER_SIGNATURE + ' ' +
+                       dsaversion.raw_version_revision)
     DELETED_HEADER = '# original file did not exist'
 
     def __init__(self, unifiedPersistence=False):


-- 
To view, visit https://gerrit.ovirt.org/64095
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie1febd494c5a01ceecd894e8542c1adb3cda704a
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-4.0
Gerrit-Owner: Edward Haas <edwa...@redhat.com>
_______________________________________________
vdsm-patches mailing list -- vdsm-patches@lists.fedorahosted.org
To unsubscribe send an email to vdsm-patches-le...@lists.fedorahosted.org

Reply via email to