Merge branch 'master' of ssh://git.onelab.eu/git/sfa
authorSandrine Avakian <sandrine.avakian@inria.fr>
Wed, 13 Feb 2013 13:12:14 +0000 (14:12 +0100)
committerSandrine Avakian <sandrine.avakian@inria.fr>
Wed, 13 Feb 2013 13:12:14 +0000 (14:12 +0100)
config/api_versions.xml [new file with mode: 0644]
setup.py
sfa.spec
sfa/client/sfi.py
sfa/managers/aggregate_manager.py
sfa/server/api_versions.py [new file with mode: 0644]

diff --git a/config/api_versions.xml b/config/api_versions.xml
new file mode 100644 (file)
index 0000000..6b30f4e
--- /dev/null
@@ -0,0 +1,3 @@
+<api_versions>
+    <api_version version="" url=""/>   
+</api_versions>
index 75a1e71..28f7ec9 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -55,6 +55,7 @@ if not os.path.isfile('/etc/redhat-release'): initscripts.append('functions.sfa'
 data_files = [ ('/etc/sfa/', [ 'config/aggregates.xml',
                               'config/registries.xml',
                               'config/default_config.xml',
+                              'config/api_versions.xml',
                               'config/sfi_config',
                               'config/topology',
                               'sfa/managers/pl/pl.rng',
index 0d1ee59..e5786e4 100644 (file)
--- a/sfa.spec
+++ b/sfa.spec
@@ -171,6 +171,7 @@ rm -rf $RPM_BUILD_ROOT
 %config /etc/sfa/default_config.xml
 %config (noreplace) /etc/sfa/aggregates.xml
 %config (noreplace) /etc/sfa/registries.xml
+%config (noreplace) /etc/sfa/api_versions.xml
 /usr/share/sfa/migrations
 /usr/share/sfa/examples
 /var/www/html/wsdl/*.wsdl
index 8f9682f..3203624 100644 (file)
@@ -936,10 +936,17 @@ or version information about sfi itself
         if options.show_credential:
             show_credentials(auth_cred)
         record_dict = {}
-        if len(args) > 0:
-            record_filepath = args[0]
-            rec_file = self.get_record_file(record_filepath)
-            record_dict.update(load_record_from_file(rec_file).todict())
+        if len(args) > 1:
+            self.print_help()
+            sys.exit(1)
+        if len(args)==1:
+            try:
+                record_filepath = args[0]
+                rec_file = self.get_record_file(record_filepath)
+                record_dict.update(load_record_from_file(rec_file).todict())
+            except:
+                print "Cannot load record file %s"%record_filepath
+                sys.exit(1)
         if options:
             record_dict.update(load_record_from_opts(options).todict())
         # we should have a type by now
index 1d8b420..fe6b07b 100644 (file)
@@ -1,6 +1,8 @@
+import socket
 from sfa.util.version import version_core
 from sfa.util.xrn import Xrn
 from sfa.util.callids import Callids
+from sfa.server.api_versions import ApiVersions
 
 class AggregateManager:
 
@@ -11,11 +13,13 @@ class AggregateManager:
     def GetVersion(self, api, options):
         xrn=Xrn(api.hrn)
         version = version_core()
+        geni_api_versions = ApiVersions().get_versions()
+        geni_api_versions['2'] = 'http://%s:%s' % (api.config.SFA_AGGREGATE_HOST, api.config.SFA_AGGREGATE_PORT)
         version_generic = {
             'interface':'aggregate',
             'sfa': 2,
             'geni_api': 2,
-            'geni_api_versions': {'2': 'http://%s:%s' % (api.config.SFA_AGGREGATE_HOST, api.config.SFA_AGGREGATE_PORT)}
+            'geni_api_versions': geni_api_versions
             'hrn':xrn.get_hrn(),
             'urn':xrn.get_urn(),
             }
diff --git a/sfa/server/api_versions.py b/sfa/server/api_versions.py
new file mode 100644 (file)
index 0000000..9b05dbe
--- /dev/null
@@ -0,0 +1,46 @@
+import os
+from sfa.util.xml import XML
+from sfa.util.config import Config
+
+class ApiVersions:
+
+    required_fields = ['version', 'url']
+    
+    template = """<api_versions>
+<api_version name="" version="" url="" />
+</api_versions>""" 
+
+    def __init__(self, string=None, filename=None, create=False):
+        self.xml = None
+
+        if create:
+            self.create()
+        elif string:
+            self.load(string)
+        elif filename:
+            self.load(filename)
+        else:
+            # load the default file
+            c = Config()
+            api_versions_file = os.path.sep.join([c.config_path, 'api_versions.xml'])
+            self.load(api_versions_file)
+        
+    def create(self):
+        self.xml = XML(string=ApiVersions.template)
+
+    def load(self, source):
+        self.xml = XML(source)
+
+    def get_versions(self):
+        versions = {}
+        for value in self.xml.todict().values():
+            if not value:
+                continue
+            if isinstance(value, list):
+                for item in value:
+                    if isinstance(item, dict) and \
+                       set(ApiVersions.required_fields).issubset(item.keys()):
+                        versions[str(item['version'])] = item['url']
+        return versions  
+                
+