Noam Slomianko has uploaded a new change for review.

Change subject: Rework plugin structure
......................................................................

Rework plugin structure

- Change dummy to the new format
- Rework the loader to the new structure

Signed-off-by: Noam Slomianko <[email protected]>
Change-Id: I74f9ff426b3c07ad68e5feb91bc4845426de42fc
---
M plugins/dummy.py
M src/ovirtscheduler/loader.py
M src/ovirtscheduler/utils.py
3 files changed, 36 insertions(+), 47 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-scheduler-proxy 
refs/changes/73/18173/1

diff --git a/plugins/dummy.py b/plugins/dummy.py
index af770e4..1c6a108 100755
--- a/plugins/dummy.py
+++ b/plugins/dummy.py
@@ -59,6 +59,7 @@
 # Notice: plugin filters are going to run in process that will be created and 
destroyed
 #  per request, you cannot save state in memory
 def filterFunction(hosts, vm, args):
+    '''This is a simple filter that returns all given host ID'''
     try:
         filterClassInstance = SampleFilter()
         #as this will run as a process, communications will be through stdout
@@ -67,12 +68,7 @@
     except Exception as ex:
         print >> sys.stderr, ex
 
-
-def describeFilter():
-    description = "This is a simple filter that returns all given host ID"
-    #this filter requires no regex
-    custom_properties_regex = ""
-    return description, custom_properties_regex
+regex_filter = ""
 
 
 #Files can hold all three supported functions 
(filterFucntion,scoreFunction,balanceFunction)
@@ -101,18 +97,14 @@
 
 
 def scoreFunction(hosts, vm, args):
+    '''This is a simple score function that returns all given host ID with 
score 50'''
     try:
         scoreClassInstance = SampleScore()
         print scoreClassInstance.score(hosts, vm, args)
     except Exception as ex:
         print >> sys.stderr, ex
 
-
-def describeScore():
-    description = "This is a simple score function that returns all given host 
ID with score 50"
-    #this score function requires no regex
-    custom_properties_regex = ""
-    return description, custom_properties_regex
+regex_score = ""
 
 
 class SampleBalance():
@@ -126,16 +118,11 @@
 
 
 def balanceFunction(hosts, args):
+    '''This is a fake balance function that always return the guid 
33333333-3333-3333-3333-333333333333'''
     try:
         balanceInstance = SampleBalance()
         print balanceInstance.balance(hosts, args)
     except Exception as ex:
         print >> sys.stderr, ex
 
-
-def describeBalance():
-    description = "This is a fake balance function that always return the " \
-                  "guid 33333333-3333-3333-3333-333333333333"
-    #this score function requires no regex
-    custom_properties_regex = ""
-    return description, custom_properties_regex
\ No newline at end of file
+regex_balance = ""
\ No newline at end of file
diff --git a/src/ovirtscheduler/loader.py b/src/ovirtscheduler/loader.py
index dfedd29..eebdaf3 100644
--- a/src/ovirtscheduler/loader.py
+++ b/src/ovirtscheduler/loader.py
@@ -16,33 +16,32 @@
     try:
         os.chdir(path)
         mod = __import__(name)
-        if hasattr(mod, _utils.FILTER):
-            if hasattr(mod, _utils.FILTER_DESCRIPTION):
-                description, custom_properties_map\
-                    = getattr(mod, _utils.FILTER_DESCRIPTION)()
-                retValue +=\
-                    ((_utils.FILTER, description, custom_properties_map),)
-            else:
-                retValue += ((_utils.FILTER, "", ""),)
 
-        if hasattr(mod, _utils.SCORE):
-            if hasattr(mod, _utils.SCORE_DESCRIPTION):
-                description, custom_properties_map\
-                    = getattr(mod, _utils.SCORE_DESCRIPTION)()
-                retValue +=\
-                    ((_utils.SCORE, description, custom_properties_map),)
-            else:
-                retValue += ((_utils.SCORE, "", ""),)
-
-        if hasattr(mod, _utils.BALANCE):
-            if hasattr(mod, _utils.BALANCE_DESCRIPTION):
-                description, custom_properties_map\
-                    = getattr(mod, _utils.BALANCE_DESCRIPTION)()
-                retValue +=\
-                    ((_utils.BALANCE, description, custom_properties_map),)
-            else:
-                retValue += ((_utils.BALANCE, "", ""),)
+        retValue += \
+            getAttributes(mod,
+                          _utils.FILTER,
+                          _utils.FILTER_REGEX)
+        retValue += \
+            getAttributes(mod,
+                          _utils.SCORE,
+                          _utils.SCORE_REGEX)
+        retValue += \
+            getAttributes(mod,
+                          _utils.BALANCE,
+                          _utils.BALANCE_REGEX)
     except Exception as ex:
         print >> sys.stderr, ex
 
     print retValue
+
+
+def getAttributes(mod, function_name, regex_name):
+    description = ""
+    regex_map = ""
+    if hasattr(mod, function_name):
+            description = getattr(mod, function_name).__doc__
+            if hasattr(mod, regex_name):
+                regex_map = getattr(mod, regex_name)
+            return ((function_name, description, regex_map),)
+    else:
+        return ()
diff --git a/src/ovirtscheduler/utils.py b/src/ovirtscheduler/utils.py
index f9adde7..9ba203f 100644
--- a/src/ovirtscheduler/utils.py
+++ b/src/ovirtscheduler/utils.py
@@ -26,11 +26,14 @@
         pass
 
     FILTER = 'filterFunction'
-    FILTER_DESCRIPTION = 'describeFilter'
+    FILTER_DESCRIPTION = 'desc_filter'
+    FILTER_REGEX = 'regex_filter'
     SCORE = 'scoreFunction'
-    SCORE_DESCRIPTION = 'describeScore'
+    SCORE_DESCRIPTION = 'desc_score'
+    SCORE_REGEX = 'regex_score'
     BALANCE = 'balanceFunction'
-    BALANCE_DESCRIPTION = 'describeBalance'
+    BALANCE_DESCRIPTION = 'desc_balance'
+    BALANCE_REGEX = 'regex_balance'
     LOADER_MODULE = 'loader'
     LOADER_FUNC = 'analyze'
 


-- 
To view, visit http://gerrit.ovirt.org/18173
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I74f9ff426b3c07ad68e5feb91bc4845426de42fc
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-scheduler-proxy
Gerrit-Branch: master
Gerrit-Owner: Noam Slomianko <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to