[asterisk-scf-commits] asterisk-scf/release/configurator.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue May 24 10:58:35 CDT 2011


branch "master" has been updated
       via  31ffb84646d9608f6ed38c088335be459244b7d3 (commit)
      from  3af0760b0e3d33267a7eaaf02c8e63a17bacc729 (commit)

Summary of changes:
 Configurator.py |   30 ++++++++++++++++++++++++++++--
 1 files changed, 28 insertions(+), 2 deletions(-)


- Log -----------------------------------------------------------------
commit 31ffb84646d9608f6ed38c088335be459244b7d3
Author: Joshua Colp <jcolp at digium.com>
Date:   Tue May 17 09:00:35 2011 -0300

    Add support for using the service locator to find a configuration service.

diff --git a/Configurator.py b/Configurator.py
index 718f16a..2b3f9a5 100755
--- a/Configurator.py
+++ b/Configurator.py
@@ -22,7 +22,9 @@ import ConfigParser, os, Ice, getopt, sys
 
 # Load and make the configuration interface available, we require it
 Ice.loadSlice('-I. --all ConfigurationIf.ice')
+Ice.loadSlice('-I. -I/opt/Ice-3.4.1/slice --all ServiceLocatorIf.ice')
 import AsteriskSCF.System.Configuration.V1
+import AsteriskSCF.Core.Discovery.V1
 
 # Exception class used within the configurator application
 class ConfiguratorError(Exception):
@@ -102,7 +104,7 @@ class OptionMapper():
 
 # Common configurator application logic
 class ConfiguratorApp(Ice.Application):
-    def __init__(self, defaultConfigFile, visitor, configurationService = None):
+    def __init__(self, defaultConfigFile, visitor, configurationService = None, serviceLocatorParams = None):
         """Common configuration utility class"""
 
         if defaultConfigFile == '':
@@ -111,6 +113,7 @@ class ConfiguratorApp(Ice.Application):
         self.defaultConfigFile = defaultConfigFile
         self.visitor = visitor
         self.configurationService = configurationService
+        self.serviceLocatorParams = serviceLocatorParams
 
     def usage(self):
         """Print usage information for the configuration utility"""
@@ -122,13 +125,15 @@ class ConfiguratorApp(Ice.Application):
         print "-h, --help              display help information"
         print "-c, --config=FILENAME   use specified configuration file instead of " + self.defaultConfigFile
         print "-p, --proxy=PROXY       use specified proxy instead of locating component"
+        print "-l, --locator=PROXY     use specified proxy for service locator"
+        print "-n, --name=NAME         use name when finding configuration service"
         print "-w, --wipe              remove existing configuration before applying new one"
 
     def run(self, args):
         """Parse options, read configuration file, produce configuration data, and submit it"""
 
         try:
-            opts, arguments = getopt.getopt(args[1:], "hc:p:w", ["help", "config=", "proxy=", "wipe"])
+            opts, arguments = getopt.getopt(args[1:], "hc:p:l:n:w", ["help", "config=", "proxy=", "locator=", "name=", "wipe"])
         except getopt.GetoptError, err:
             print str(err)
             self.usage()
@@ -137,6 +142,9 @@ class ConfiguratorApp(Ice.Application):
         configFile = self.defaultConfigFile
         configurationService = self.configurationService
         configurationWipe = False
+        configurationServiceName = ""
+        serviceLocator = None
+        serviceLocatorParams = self.serviceLocatorParams
 
         for o, a in opts:
             if o in ("-h", "--help"):
@@ -149,9 +157,27 @@ class ConfiguratorApp(Ice.Application):
             elif o in ("-p", "--proxy"):
                 configurationService = AsteriskSCF.System.Configuration.V1.ConfigurationServicePrx.checkedCast(self.communicator().stringToProxy(a))
 
+            elif o in ("-l", "--locator"):
+                serviceLocator = AsteriskSCF.Core.Discovery.V1.ServiceLocatorPrx.checkedCast(self.communicator().stringToProxy(a))
+
+            elif o in ("-n", "--name"):
+                configurationServiceName = a
+
             elif o in ("-w", "--wipe"):
                 configurationWipe = True
 
+        if serviceLocator:
+            # Populate params with the name
+            setattr(serviceLocatorParams, "name", configurationServiceName)
+
+            try:
+                service = serviceLocator.locate(serviceLocatorParams)
+            except AsteriskSCF.Core.Discovery.V1.ServiceNotFound:
+                print >> sys.stderr, "Configuration service could not be found in service locator."
+                return -1
+
+            configurationService = AsteriskSCF.System.Configuration.V1.ConfigurationServicePrx.uncheckedCast(service)
+
         if configurationService == None:
             print >> sys.stderr, "No configuration service to configure. For usage details please run " + __file__ + " --help"
             return -1

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


-- 
asterisk-scf/release/configurator.git



More information about the asterisk-scf-commits mailing list