[asterisk-scf-commits] asterisk-scf/integration/replica_tool.git branch "master" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Sep 22 19:56:15 CDT 2010


branch "master" has been created
        at  4b3b0c563adcc2634220996561838d6c2beff9d4 (commit)

- Log -----------------------------------------------------------------
commit 4b3b0c563adcc2634220996561838d6c2beff9d4
Author: Brent Eagles <beagles at digium.com>
Date:   Wed Sep 22 22:23:30 2010 -0230

    Initial commit of a first kick at a "replica" interface manipulator
    in python. Also has a test server to play with.

diff --git a/replica_tool.py b/replica_tool.py
new file mode 100644
index 0000000..38b1153
--- /dev/null
+++ b/replica_tool.py
@@ -0,0 +1,124 @@
+#!/usr/bin/env python
+#
+# Asterisk Scalable Communications Framework
+#
+# Copyright (C) 2010 -- Digium, Inc.
+#
+# All rights reserved.
+#
+import Ice, sys, getopt, os, os.path
+
+def usage():
+    print """
+replica_tool.py is a command line python script for querying the
+status of replicas, making a standby replica active and putting an
+active replica on standby.
+
+Usage:
+   replica_tool.py [-f=proxy_list_file] command property_name [command property_anme ...]
+
+The command line format is options followed by command/property name pairs.
+
+Where command is one of:
+   activate - activate the replica
+   standby  - tell the replica to enter standby mode
+   status   - query the status of the replica
+
+Each command is followed by a string that specifies a property name
+contained in either the file specified by the proxy_list_file option
+or in the properties configured in the Ice communicator for this
+process via Ice configuration.
+"""
+
+if len(sys.argv) == 1:
+    usage()
+    sys.exit(1)
+
+opts = []
+args = []
+global propertyFile
+propertyFile = ""
+
+try:
+    opts, args = getopt.getopt(sys.argv[1:], "-f:")
+except getopt.GetoptError:
+    usage()
+
+for o, a in opts:
+    if o == "-f":
+        propertyFile = a
+
+if len(propertyFile) > 0 and not os.path.exists(propertyFile):
+    print "Property file provided through -f option does not exist"
+    sys.exit(1)
+
+slicepath = os.environ["ASTERISKSCF_SLICE"]
+if len(slicepath) == 0:
+    slicepath = "."
+
+if not os.path.exists(slicepath):
+    print "Slice path does not exist."
+    sys.exit(1)
+
+replicaSlice = os.path.join(slicepath, "System", "Component", "ReplicaIf.ice")
+if not os.path.exists(replicaSlice):
+    print "Unable to locate replica slice."
+    sys.exit(1)
+
+Ice.loadSlice("--all -I" + slicepath + " " + replicaSlice)
+import AsteriskSCF
+
+class ReplicaTool(Ice.Application):
+    def __init__(self, pairs, propertyFile):
+        self.mPairs = pairs
+        self.mPropertyFile = propertyFile
+        
+    def run(self, args):
+        if len(self.mPropertyFile) > 0:
+            self.mProperties = Ice.createProperties()
+            self.mProperties.load(self.mPropertyFile)
+        else:
+            self.mProperties = self.communicator().getProperties()
+        
+        for cmd, prop in pairs:
+            objref = self.mProperties.getProperty(prop)
+            if len(objref) == 0:
+                print "unknown object"
+                return 1
+            obj = AsteriskSCF.System.Component.V1.ReplicaPrx.checkedCast(self.communicator().stringToProxy(objref))
+            if not obj:
+                print "unable to access object " + objref
+                return 1
+            if cmd == "activate":
+                obj.activate()
+            elif cmd == "standby":
+                obj.standby()
+
+            if obj.active() == True:
+                print prop, "is active"
+            else:
+                print prop, "is on standby"
+                
+        return 0
+
+    
+
+if len(args) < 2:
+    print "Not enough arguments: no commands/proxies indicated"
+    usage()
+
+if len(args) % 2 <> 0:
+    print "command/property mismatch. Odd number of arguments"
+
+pairs = []
+    
+while len(args) > 0:
+    prop = args.pop()
+    cmd = args.pop()
+    if not cmd in ["standby", "activate", "status"]:
+        print "Invalid command ", cmd
+        sys.exit(1)
+    pairs.append([cmd, prop])
+    
+app = ReplicaTool(pairs, propertyFile)
+sys.exit(app.main(sys.argv))
diff --git a/test/TestServer.py b/test/TestServer.py
new file mode 100644
index 0000000..d185b04
--- /dev/null
+++ b/test/TestServer.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+#
+# Asterisk Scalable Communications Framework
+#
+# Copyright (C) 2010 -- Digium, Inc.
+#
+# All rights reserved.
+#
+import Ice, sys, getopt, os, os.path
+
+slicepath = os.environ["ASTERISKSCF_SLICE"]
+if len(slicepath) == 0:
+    slicepath = "."
+
+if not os.path.exists(slicepath):
+    print "Slice path does not exist."
+    sys.exit(1)
+
+replicaSlice = os.path.join(slicepath, "System", "Component", "ReplicaIf.ice")
+if not os.path.exists(replicaSlice):
+    print "Unable to locate replica slice."
+    sys.exit(1)
+
+Ice.loadSlice("--all -I" + slicepath + " " + replicaSlice)
+import AsteriskSCF
+
+class TestReplica(AsteriskSCF.System.Component.V1.Replica):
+    def __init__(self):
+        self.mStatus = False
+        
+    def active(self, current=None):
+        return self.mStatus
+
+    def activate(self, current=None):
+        self.mStatus = True
+
+    def standby(self, current=None):
+        self.mStatus = False
+
+    def addListener(self, listener, current=None):
+        pass
+
+    def removeListener(self, listener, current=None):
+        pass
+    
+class Server(Ice.Application):
+    def run(self, args):
+        adapter = self.communicator().createObjectAdapter("JustATest")
+        adapter.add(TestReplica(), self.communicator().stringToIdentity("someobj"))
+        adapter.activate()
+        self.communicator().waitForShutdown()
+        return 0
+
+app = Server()
+sys.exit(app.main(sys.argv, "config.server"))
+        
diff --git a/test/config.server b/test/config.server
new file mode 100644
index 0000000..6bb6dcd
--- /dev/null
+++ b/test/config.server
@@ -0,0 +1 @@
+JustATest.Endpoints=default -p 23332
\ No newline at end of file
diff --git a/test/testfile.txt b/test/testfile.txt
new file mode 100644
index 0000000..ec341e3
--- /dev/null
+++ b/test/testfile.txt
@@ -0,0 +1 @@
+TestObject.Proxy=someobj:default -p 23332 -t 10000

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/replica_tool.git



More information about the asterisk-scf-commits mailing list