[asterisk-scf-commits] asterisk-scf/integration/configurator.git branch "retry_deux" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Apr 25 12:35:08 CDT 2012


branch "retry_deux" has been updated
       via  d7e61b03d974083ba546172435c1e7029cda8a95 (commit)
      from  eff76ee56f9293bbe39fde295afa55093bc66d4f (commit)

Summary of changes:
 Activator.py |  102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 102 insertions(+), 0 deletions(-)
 create mode 100644 Activator.py


- Log -----------------------------------------------------------------
commit d7e61b03d974083ba546172435c1e7029cda8a95
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Wed Apr 25 12:34:35 2012 -0500

    Added the component activator script.

diff --git a/Activator.py b/Activator.py
new file mode 100644
index 0000000..2f50e90
--- /dev/null
+++ b/Activator.py
@@ -0,0 +1,102 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import argparse
+
+sys.path.append('/opt/Ice-3.4.2/python')
+
+import Ice, AsteriskSCF
+
+slice = os.environ["ASTSCF_HOME"] + "/slice/slice"
+AstSCFslice = slice + "/AsteriskSCF/"
+
+Ice.loadSlice("-I\"" + slice + "\" -I\"" + Ice.getSliceDir() + "\" --all \"" + AstSCFslice + "System/Component/ReplicaIf.ice\"")
+Ice.loadSlice("-I\"" + slice + "\" -I\"" + Ice.getSliceDir() + "\" --all \"" + AstSCFslice + "Core/Discovery/ServiceLocatorIf.ice\"")
+
+import AsteriskSCF.Core.Discovery.V1
+import AsteriskSCF.System.Component.V1 
+
+class ComponentActivator(Ice.Application):
+    def run(self, args):
+        serviceLocatorReplicaString = 'ServiceLocatorReplica:tcp -p 4410'
+        serviceLocatorString = 'LocatorService:tcp -p 4411'
+
+        argParser = argparse.ArgumentParser(description = 'Place a replica in the \'active\' state.')
+        argParser.add_argument('-c', '--category', required=True, 
+            help='Discovery category for the component\'s replica interface. Typically: ' \
+	    'BridgeService.Replica, RoutingService.Replica, SipSessionManager.Replica, ' \
+            'MediaRTPService.Replica, MediaOperationsCoreComponentService.Replica, MediaFormatGeneric.Replica')
+        argParser.add_argument('-s', '--service_name', required=True,
+            help='The service name property is used when registering a component\'s services with the ServiceLocator, ' \
+                 'and can be located in the component\'s IceBox configuration file. For small or test deployments' \
+	        'the service name is commonly set to \'default\' (i.e. <instance_name>.ServiceName=default)')
+        argParser.add_argument('-i', '--instance_name', required=True,
+            help='In general, configuration properties derive from the IceBox service name of the component in the ' \
+                 'IceBox configuration file. An IceBox service name can be recognized by looking for a string simular ' \
+                 'to this: \'IceBox.Service.<instance name>=<shared lib name>:<shared lib operation>\'.')
+        argParser.add_argument('-sh', '--service_locator_host', 
+            help='(OPTIONAL) Hostname or IP address of the Service Locator. If not specified, localhost is assumed.')
+
+        try:
+            args = argParser.parse_args()
+        except:
+            print ''
+            return 2
+
+        # First we get a reference to the Service Locator's own Replica interface. 
+        # We need the Service Locator active in order to locate the Replica interface 
+	# of the component we're trying activate.
+        if not args.service_locator_host == None:
+            serviceLocatorReplicaString = serviceLocatorReplicaString + ' -h ' + args.service_locator_host
+
+        serviceLocatorReplica = AsteriskSCF.System.Component.V1.ReplicaPrx.checkedCast(self.communicator().stringToProxy(serviceLocatorReplicaString))
+
+        if serviceLocatorReplica == None:
+            print >> sys.stderr, "Invalid Replica proxy specified for Service Locator. For usage details please run " + sys.argv[0] + " --help"
+            return -1
+
+	# Now make sure the Service Locator is active. 
+        try:
+	    if not serviceLocatorReplica.isActive():
+	        print "Activating Service Locator."
+                serviceLocatorReplica.activate(AsteriskSCF.createContext())
+	    
+        except Ice.Exception as ex:
+            print >> sys.stderr, "Exception trying to activate a Service Locator component: " + ex.what()
+            return -1
+
+        # We have an active Service Locator component. Get a proxy to the Service Locator interface so that
+        # we can lookup registered interfaces.
+        if not args.service_locator_host == None:
+            serviceLocatorString = serviceLocatorString + ' -h ' + args.service_locator_host
+
+        serviceLocator = AsteriskSCF.Core.Discovery.V1.ServiceLocatorPrx.checkedCast(self.communicator().stringToProxy(serviceLocatorString))
+
+        if serviceLocator == None:
+            print >> sys.stderr, "Invalid Service Locator proxy specified. For usage details please run " + sys.argv[0] + " --help"
+            return -1
+
+        # Activate the component
+        componentLocatorParams = AsteriskSCF.Core.Discovery.V1.ServiceLocatorParams()
+        componentLocatorParams.category = args.category
+        componentLocatorParams.service = args.service_name
+        componentLocatorParams.id = args.instance_name
+
+        try:
+            componentReplicaObjPrx = serviceLocator.locate(componentLocatorParams)
+        except AsteriskSCF.Core.Discovery.V1.ServiceNotFound:
+            print >> sys.stderr, 'The \'%s\' replica interface was not found by the specified service locator.\n\n %s\n' % (args.category, sys.exc_info())
+            return -1
+
+        componentReplica = AsteriskSCF.System.Component.V1.ReplicaPrx.checkedCast(componentReplicaObjPrx)
+
+	if componentReplica == None:
+	    print >> sys.stderr, "Can't cast object to replica." 
+	    return -1;
+
+        result = componentReplica.activate(AsteriskSCF.createContext())
+
+if __name__ == '__main__':
+    print '' 
+    sys.exit(ComponentActivator().main(sys.argv))

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


-- 
asterisk-scf/integration/configurator.git



More information about the asterisk-scf-commits mailing list