Dima Kuznetsov has uploaded a new change for review.

Change subject: supervdsm: Decorators for supervdsm proxy calls.
......................................................................

supervdsm: Decorators for supervdsm proxy calls.

These decorators allow automatic dispatch to supervdsm process, in this
way:

@supervdsm.proxied_call
def some_func():
        this_requires_root()

Calling the above function from root context (such as supervdsm) will
just execute it as regular code, but when calling from non-root context,
it will try and dispatch it to supervdsm.

Change-Id: Ibea2b07b91a7faffda16c71c6b5831f96d116c15
Signed-off-by: Dima Kuznetsov <dkuzn...@redhat.com>
---
M lib/vdsm/supervdsm.py
1 file changed, 20 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/98/44598/1

diff --git a/lib/vdsm/supervdsm.py b/lib/vdsm/supervdsm.py
index 8e42af2..a552a82 100644
--- a/lib/vdsm/supervdsm.py
+++ b/lib/vdsm/supervdsm.py
@@ -19,6 +19,7 @@
 # Refer to the README and COPYING files for full details of the license
 #
 
+import functools
 import os
 from multiprocessing.managers import BaseManager, RemoteError
 import logging
@@ -85,6 +86,9 @@
     def __getattr__(self, name):
         return ProxyCaller(self, name)
 
+    def call(self, name, *args, **kwargs):
+        return getattr(self, name)(*args, **kwargs)
+
 
 def getProxy():
     global _g_singletonSupervdsmInstance
@@ -93,3 +97,19 @@
             if _g_singletonSupervdsmInstance is None:
                 _g_singletonSupervdsmInstance = SuperVdsmProxy()
     return _g_singletonSupervdsmInstance
+
+
+def named_proxied_call(name):
+    def decorator(func):
+        @functools.wraps(func)
+        def wrapper(*args, **kwargs):
+            if os.geteuid() == 0:
+                return func(*args, **kwargs)
+            else:
+                return getProxy().call(name, *args, **kwargs)
+        return wrapper
+    return decorator
+
+
+def proxied_call(func):
+    return named_proxied_call(func.func_name)


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibea2b07b91a7faffda16c71c6b5831f96d116c15
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Dima Kuznetsov <dkuzn...@redhat.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to