extend GetVersion to expose:
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 22 Oct 2010 10:38:52 +0000 (12:38 +0200)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 22 Oct 2010 10:38:52 +0000 (12:38 +0200)
* interface :
    registry | slicemgr | aggregate | component
* peers (registry and slicemgr only)
    dictionary of (hrn => URL)
    for supporting introspection
* hrn : well, the hrn associated with this server (registry and slicemgr only)
* tag : the git tag
* hostname :

Example:
~/.sfi-vplc $  sfi.py -d . version -R
peers               : {'plc': 128.112.139.90:12345'}
hostname            : vplc10.pl.sophia.inria.fr
tag                 : sfa-1.0-6
hrn                 : ple
interface           : registry
geni_api            : 1
sfa                 : 1

Makefile
sfa.spec
sfa/client/sfi.py
sfa/managers/aggregate_manager_pl.py
sfa/managers/aggregate_manager_vini.py
sfa/managers/component_manager_pl.py
sfa/managers/registry_manager_pl.py
sfa/managers/slice_manager_pl.py
sfa/methods/GetVersion.py
sfa/util/version.py.in [new file with mode: 0644]

index 2446adc..40c89ca 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -15,8 +15,14 @@ uninstall: python-uninstall tests-uninstall
 
 .PHONY: all install clean uninstall
 
+VERSIONTAG=should-be-redefined-by-specfile
+
 ##########
-python: 
+python: version
+
+version: sfa/util/version.py
+sfa/util/version.py: sfa/util/version.py.in
+       sed -e "s,@VERSIONTAG@,$(VERSIONTAG),g" sfa/util/version.py.in > $@
 
 xmlbuilder-install:
        cd xmlbuilder-0.9 && python setup.py install --root=$(DESTDIR) && cd -
@@ -25,11 +31,14 @@ python-install:
        python setup.py install --root=$(DESTDIR)       
        chmod 444 $(DESTDIR)/etc/sfa/default_config.xml
 
-python-clean:
+python-clean: version-clean
        python setup.py clean
-       rm $(init)
+#      rm $(init)
 
-.PHONY: python python-install python-clean xmlbuilder-install
+version-clean:
+       rm -f sfa/util/version.py
+
+.PHONY: python version python-install python-clean version-clean xmlbuilder-install 
 ##########
 wsdl: 
        $(MAKE) -C wsdl 
@@ -43,7 +52,6 @@ wsdl-clean:
 
 .PHONY: wsdl wsdl-install wsdl-clean
 
-
 ##########
 tests-install:
        mkdir -p $(DESTDIR)/usr/share/sfa/tests
index 33ccdea..6b75b9f 100644 (file)
--- a/sfa.spec
+++ b/sfa.spec
@@ -105,11 +105,11 @@ Provides some binary unit tests in /usr/share/sfa/tests
 %setup -q
 
 %build
-make
+make VERSION=%{version}-%{taglevel}
 
 %install
 rm -rf $RPM_BUILD_ROOT
-make install DESTDIR="$RPM_BUILD_ROOT"
+make install VERSION=%{version}-%{taglevel} DESTDIR="$RPM_BUILD_ROOT"
 
 %clean
 rm -rf $RPM_BUILD_ROOT
index 8190203..1c49dc9 100755 (executable)
@@ -211,6 +211,11 @@ class Sfi:
            parser.add_option("-s", "--slice", dest="delegate_slice",
                             help="delegate slice credential", metavar="HRN", default=None)
         
+        if command in ("version"):
+            parser.add_option("-R","--registry-version",
+                              action="store_true", dest="probe_registry", default=False,
+                              help="probe registry version instead of slicemgr")
+
         return parser
 
         
@@ -750,9 +755,12 @@ class Sfi:
     
 
     def version(self, opts, args):
-        server = self.get_server_from_opts(opts)
-        
-        print server.GetVersion()
+        if opts.probe_registry:
+            server=self.registry
+        else:
+            server = self.get_server_from_opts(opts)
+        for (k,v) in server.GetVersion().items():
+            print "%-20s: %s"%(k,v)
 
     # list instantiated slices
     def slices(self, opts, args):
index 0c70dda..2ebcc5a 100644 (file)
@@ -21,7 +21,11 @@ import sfa.plc.peers as peers
 from sfa.plc.network import *
 from sfa.plc.api import SfaAPI
 from sfa.plc.slices import *
+from sfa.util.version import version_core
 
+def GetVersion(api):
+    return version_core({'interface':'aggregate',
+                         'testbed':'myplc'})
 
 def __get_registry_objects(slice_xrn, creds, users):
     """
@@ -83,12 +87,6 @@ def __get_hostnames(nodes):
         hostnames.append(node.hostname)
     return hostnames
 
-def get_version():
-    version = {}
-    version['geni_api'] = 1
-    version['sfa'] = 1
-    return version
-
 def slice_status(api, slice_xrn, creds):
     hrn, type = urn_to_hrn(slice_xrn)
     # find out where this slice is currently running
index 74a07e2..e79dcf4 100644 (file)
@@ -20,19 +20,17 @@ from sfa.managers.vini.vini_network import *
 from sfa.plc.api import SfaAPI
 from sfa.plc.slices import *
 from sfa.managers.aggregate_manager_pl import __get_registry_objects, __get_hostnames
+from sfa.util.version import version_core
 
 # VINI aggregate is almost identical to PLC aggregate for many operations, 
 # so lets just import the methods form the PLC manager
-
 from sfa.managers.aggregate_manager_pl import (
 start_slice, stop_slice, renew_slice, reset_slice, get_slices, get_ticket)
 
 
-def get_version():
-    version = {}
-    version['geni_api'] = 1
-    version['sfa'] = 1
-    return version
+def GetVersion(api):
+    return version_core({'interface':'aggregate',
+                         'testbed':'myplc.vini'})
 
 def slice_status(api, slice_xrn, creds):
     result = {}
index 6c36809..6b784cd 100644 (file)
@@ -5,6 +5,11 @@ from sfa.util.faults import *
 from sfa.util.xrn import urn_to_hrn
 from sfa.util.plxrn import hrn_to_pl_slicename
 from sfa.util.sfaticket import SfaTicket
+from sfa.util.version import version_core
+
+def GetVersion(api):
+    return version_core({'interface':'component',
+                         'testbed':'myplc'})
 
 def init_server():
     from sfa.server import sfa_component_setup
@@ -17,11 +22,6 @@ def init_server():
         sfa_component_setup.get_credential(force=True)
         sfa_component_setup.get_trusted_certs()
 
-def get_version():
-    version = {}
-    version['geni_api'] = 1
-    return version
-
 def slice_status(api, slice_xrn, creds):
     result = {}
     result['geni_urn'] = slice_xrn
index 28f9198..033f762 100644 (file)
@@ -12,12 +12,15 @@ from sfa.util.plxrn import hrn_to_pl_login_base
 from sfa.trust.credential import Credential
 from sfa.trust.certificate import Certificate, Keypair
 from sfa.trust.gid import create_uuid
+from sfa.util.version import version_core
 
-def get_version(api):
-    version = {}
-    version['geni_api'] = 1
-    version['sfa'] = 1
-    return version
+# The GENI GetVersion call
+def GetVersion(api):
+    peers =dict ([ (peername,v._ServerProxy__host) for (peername,v) in api.registries.items() 
+                   if peername != api.hrn])
+    return version_core({'interface':'registry',
+                         'hrn':api.hrn,
+                         'peers':peers})
 
 def get_credential(api, xrn, type, is_self=False):
     # convert xrn to hrn     
@@ -79,12 +82,6 @@ def get_credential(api, xrn, type, is_self=False):
     return new_cred.save_to_string(save_parents=True)
 
 
-# The GENI GetVersion call
-def GetVersion():
-    version = {}
-    version['geni_api'] = 1
-    return version
-
 def resolve(api, xrns, type=None, full=True):
 
     # load all know registry names into a prefix tree and attempt to find
index 4aca6fa..d26979b 100644 (file)
@@ -1,6 +1,4 @@
-### $Id: slices.py 15842 2009-11-22 09:56:13Z anil $
-### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/plc/slices.py $
-
+# 
 import sys
 import time,datetime
 from StringIO import StringIO
@@ -23,12 +21,15 @@ from sfa.trust.credential import Credential
 from sfa.util.threadmanager import ThreadManager
 import sfa.util.xmlrpcprotocol as xmlrpcprotocol     
 import sfa.plc.peers as peers
-
-def get_version():
-    version = {}
-    version['geni_api'] = 1
-    version['sfa'] = 1
-    return version
+from sfa.util.version import version_core
+
+def GetVersion(api):
+    peers =dict ([ (peername,v._ServerProxy__host) for (peername,v) in api.aggregates.items() 
+                   if peername != api.hrn])
+    return version_core({'interface':'slicemgr',
+                         'hrn' : api.hrn,
+                         'peers': peers,
+                         })
 
 def slice_status(api, slice_xrn, creds ):
     hrn, type = urn_to_hrn(slice_xrn)
index fef8790..2a8f6b2 100644 (file)
@@ -15,6 +15,4 @@ class GetVersion(Method):
     def call(self):
         self.api.logger.info("interface: %s\tmethod-name: %s" % (self.api.interface, self.name))
         manager = self.api.get_interface_manager()
-    
-        return manager.get_version()
-    
+        return manager.GetVersion(self.api)
diff --git a/sfa/util/version.py.in b/sfa/util/version.py.in
new file mode 100644 (file)
index 0000000..a4edc93
--- /dev/null
@@ -0,0 +1,12 @@
+### updated by the toplevel Makefile
+version_tag="@VERSIONTAG@"
+import socket
+
+def version_core (more):
+    core = { 'geni_api':1,
+             'sfa' : 1,
+             'tag' : version_tag,
+             'hostname' : socket.gethostname(),
+             }
+    core.update(more)
+    return core