Testing: IP allocation simulation - add general node group example.
authorMartin Schwenke <martin@meltin.net>
Mon, 2 Aug 2010 05:06:39 +0000 (15:06 +1000)
committerMartin Schwenke <martin@meltin.net>
Mon, 2 Aug 2010 05:06:39 +0000 (15:06 +1000)
This allows node pool configuration to be specifed on the
command-line.

Signed-off-by: Martin Schwenke <martin@meltin.net>
tests/takeover/node_group.py [new file with mode: 0755]

diff --git a/tests/takeover/node_group.py b/tests/takeover/node_group.py
new file mode 100755 (executable)
index 0000000..b0a5648
--- /dev/null
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+
+# This demonstrates a node group configurations.
+#
+# Node groups can be defined with the syntax "-g N@IP0,IP1-IP2,IP3".
+# This says to create a group of N nodes with IPs IP0, IP1, ..., IP2,
+# IP3.  Run it with deterministic IPs causes lots of gratuitous IP
+# reassignments.  Running with --nd fixes this.
+
+import ctdb_takeover
+from optparse import make_option
+import string
+
+ctdb_takeover.process_args([
+        make_option("-g", "--group",
+                    action="append", type="string", dest="groups"),
+        ])
+
+def expand_range(r):
+    sr = r.split("-", 1)
+    if len(sr) == 2:
+        all = string.ascii_uppercase + string.ascii_lowercase
+        sr = list(all[all.index(sr[0]):all.index(sr[1])+1])
+    return sr
+            
+def add_node_group(s):
+    (count, ips_str) = s.split("@", 1)
+    ips = [i for r in ips_str.split(",") \
+               for i in expand_range(r) if r != ""]
+    for i in range(int(count)):
+        c.add_node(ctdb_takeover.Node(ips))
+
+c = ctdb_takeover.Cluster()
+
+for g in ctdb_takeover.options.groups:
+    add_node_group(g)
+
+c.recover()
+
+c.random_iterations()