Blame SOURCES/bz1179023-Added-support-for-resource-discovery-on-location-con-2.patch

337c54
From 07cd5b51fe4d9b23effc6d9122b0c9e59c6ae030 Mon Sep 17 00:00:00 2001
337c54
From: Chris Feist <cfeist@redhat.com>
337c54
Date: Wed, 7 Jan 2015 18:34:06 -0600
337c54
Subject: [PATCH] Allow configuring resource-discovery on advanced location
337c54
 constraints
337c54
337c54
---
337c54
 pcs/constraint.py            | 35 ++++++++++++++++++++++++++++++-----
337c54
 pcs/pcs.8                    |  2 +-
337c54
 pcs/test/test_constraints.py | 28 ++++++++++++++++++++++++++++
337c54
 pcs/test/test_resource.py    |  8 ++++----
337c54
 pcs/usage.py                 |  2 +-
337c54
 5 files changed, 64 insertions(+), 11 deletions(-)
337c54
337c54
diff --git a/pcs/constraint.py b/pcs/constraint.py
337c54
index ff5b583..c7950d8 100644
337c54
--- a/pcs/constraint.py
337c54
+++ b/pcs/constraint.py
337c54
@@ -788,6 +788,7 @@ def location_show(argv):
337c54
         lc_score = rsc_loc.getAttribute("score")
337c54
         lc_role = rsc_loc.getAttribute("role")
337c54
         lc_name = "Resource: " + lc_rsc
337c54
+        lc_resource_discovery = rsc_loc.getAttribute("resource-discovery")
337c54
 
337c54
         for child in rsc_loc.childNodes:
337c54
             if child.nodeType == child.ELEMENT_NODE and child.tagName == "rule":
337c54
@@ -815,14 +816,14 @@ def location_show(argv):
337c54
             rschash = rschashoff
337c54
 
337c54
         if lc_node in nodeshash:
337c54
-            nodeshash[lc_node].append((lc_id,lc_rsc,lc_score, lc_role))
337c54
+            nodeshash[lc_node].append((lc_id,lc_rsc,lc_score, lc_role, lc_resource_discovery))
337c54
         else:
337c54
-            nodeshash[lc_node] = [(lc_id, lc_rsc,lc_score, lc_role)]
337c54
+            nodeshash[lc_node] = [(lc_id, lc_rsc,lc_score, lc_role, lc_resource_discovery)]
337c54
 
337c54
         if lc_rsc in rschash:
337c54
-            rschash[lc_rsc].append((lc_id,lc_node,lc_score, lc_role))
337c54
+            rschash[lc_rsc].append((lc_id,lc_node,lc_score, lc_role, lc_resource_discovery))
337c54
         else:
337c54
-            rschash[lc_rsc] = [(lc_id,lc_node,lc_score, lc_role)]
337c54
+            rschash[lc_rsc] = [(lc_id,lc_node,lc_score, lc_role, lc_resource_discovery)]
337c54
 
337c54
     nodelist = list(set(nodehashon.keys() + nodehashoff.keys()))
337c54
     rsclist = list(set(rschashon.keys() + rschashoff.keys()))
337c54
@@ -840,6 +841,8 @@ def location_show(argv):
337c54
                     print "      " + options[1] +  " (" + options[0] + ")",
337c54
                     if (options[3] != ""):
337c54
                         print "(role: "+options[3]+")",
337c54
+                    if (options[4] != ""):
337c54
+                        print "(resource-discovery="+options[4]+")",
337c54
                     print "Score: "+ options[2]
337c54
 
337c54
             if (node in nodehashoff):
337c54
@@ -848,6 +851,8 @@ def location_show(argv):
337c54
                     print "      " + options[1] +  " (" + options[0] + ")",
337c54
                     if (options[3] != ""):
337c54
                         print "(role: "+options[3]+")",
337c54
+                    if (options[4] != ""):
337c54
+                        print "(resource-discovery="+options[4]+")",
337c54
                     print "Score: "+ options[2]
337c54
         show_location_rules(ruleshash,showDetail)
337c54
     else:
337c54
@@ -866,6 +871,8 @@ def location_show(argv):
337c54
                     print "(score:"+options[2]+")",
337c54
                     if (options[3] != ""):
337c54
                         print "(role: "+options[3]+")",
337c54
+                    if (options[4] != ""):
337c54
+                        print "(resource-discovery="+options[4]+")",
337c54
                     if showDetail:
337c54
                         print "(id:"+options[0]+")",
337c54
                     print
337c54
@@ -876,6 +883,8 @@ def location_show(argv):
337c54
                     print "(score:"+options[2]+")",
337c54
                     if (options[3] != ""):
337c54
                         print "(role: "+options[3]+")",
337c54
+                    if (options[4] != ""):
337c54
+                        print "(resource-discovery="+options[4]+")",
337c54
                     if showDetail:
337c54
                         print "(id:"+options[0]+")",
337c54
                     print 
337c54
@@ -943,7 +952,7 @@ def location_prefer(argv):
337c54
         
337c54
 
337c54
 def location_add(argv,rm=False):
337c54
-    if len(argv) != 4 and (rm == False or len(argv) < 1): 
337c54
+    if len(argv) < 4 and (rm == False or len(argv) < 1): 
337c54
         usage.constraint()
337c54
         sys.exit(1)
337c54
 
337c54
@@ -961,6 +970,20 @@ def location_add(argv,rm=False):
337c54
         resource_name = argv.pop(0)
337c54
         node = argv.pop(0)
337c54
         score = argv.pop(0)
337c54
+        options = []
337c54
+        # For now we only allow setting resource-discovery
337c54
+        if len(argv) > 0:
337c54
+            for arg in argv:
337c54
+                if '=' in arg:
337c54
+                    options.append(arg.split('=',1))
337c54
+                else:
337c54
+                    print "Error: bad option '%s'" % arg
337c54
+                    usage.constraint(["location add"])
337c54
+                    sys.exit(1)
337c54
+                if options[-1][0] != "resource-discovery" and "--force" not in utils.pcs_options:
337c54
+                    utils.err("bad option '%s', use --force to override" % options[-1][0])
337c54
+
337c54
+
337c54
         resource_valid, resource_error, correct_id \
337c54
             = utils.validate_constraint_resource(
337c54
                 utils.get_cib_dom(), resource_name
337c54
@@ -996,6 +1019,8 @@ def location_add(argv,rm=False):
337c54
         element.setAttribute("rsc",resource_name)
337c54
         element.setAttribute("node",node)
337c54
         element.setAttribute("score",score)
337c54
+        for option in options:
337c54
+            element.setAttribute(option[0], option[1])
337c54
         constraintsElement.appendChild(element)
337c54
 
337c54
     utils.replace_cib_configuration(dom)
337c54
diff --git a/pcs/pcs.8 b/pcs/pcs.8
337c54
index dccc3bb..00ac11b 100644
337c54
--- a/pcs/pcs.8
337c54
+++ b/pcs/pcs.8
337c54
@@ -393,7 +393,7 @@ where duration options and date spec options are: hours, monthdays, weekdays, ye
337c54
 location show [resources|nodes [node id|resource id]...] [\fB\-\-full\fR]
337c54
 List all the current location constraints, if 'resources' is specified location constraints are displayed per resource (default), if 'nodes' is specified location constraints are displayed per node.  If specific nodes or resources are specified then we only show information about them.  If \fB\-\-full\fR is specified show the internal constraint id's as well.
337c54
 .TP
337c54
-location add <id> <resource name> <node> <score>
337c54
+location add <id> <resource name> <node> <score> [resource-discovery=<option>]
337c54
 Add a location constraint with the appropriate id, resource name, node name and score. (For more advanced pacemaker usage)
337c54
 .TP
337c54
 location remove <id> [<resource name> <node> <score>]
337c54
diff --git a/pcs/usage.py b/pcs/usage.py
337c54
index c44efd7..7bd3368 100644
337c54
--- a/pcs/usage.py
337c54
+++ b/pcs/usage.py
337c54
@@ -870,7 +870,7 @@ Commands:
337c54
         nodes or resources are specified then we only show information about
337c54
         them
337c54
 
337c54
-    location add <id> <resource name> <node> <score>
337c54
+    location add <id> <resource name> <node> <score> [resource-discovery=<option>]
337c54
         Add a location constraint with the appropriate id, resource name,
337c54
         node name and score. (For more advanced pacemaker usage)
337c54
 
337c54
-- 
337c54
2.1.0
337c54