support geni am api v2 return values
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Tue, 22 Nov 2011 19:57:08 +0000 (14:57 -0500)
committerTony Mack <tmack@paris.CS.Princeton.EDU>
Tue, 22 Nov 2011 19:59:00 +0000 (14:59 -0500)
config/default_config.xml
sfa/client/sfi.py
sfa/server/sfaapi.py
sfa/util/genicode.py

index e633a60..6d052fc 100644 (file)
@@ -18,12 +18,27 @@ Thierry Parmentelat
       <description>Basic system variables.</description>
 
       <variablelist>
+        <variable id="generic_flavour" type="string">
+          <name>Generic Flavour</name>
+          <value>pl</value>
+          <description>This string refers to a class located in sfa.generic that describes 
+          which specific implementation needs to be used for api, manager and driver objects.
+          PlanetLab users do not need to change this setting.
+          </description>
+        </variable>
+
         <variable id="interface_hrn" type="string">
           <name>Human readable name</name>
           <value>plc</value>
           <description>The human readable name for this interface.</description>
         </variable>
 
+        <variable id="am_api_version" type="string">
+          <name>Aggregate Manager API Version</name>
+          <value>1</value>
+          <description>The Aggregate API version</description>
+        </variable>
+
         <variable id="credential_schema" type="string">
           <name>Credential Schema</name>
           <value>/etc/sfa/credential.xsd</value>
@@ -53,15 +68,6 @@ Thierry Parmentelat
             </description> 
         </variable>
 
-       <variable id="generic_flavour" type="string">
-         <name>Generic Flavour</name>
-         <value>pl</value>
-         <description>This string refers to a class located in sfa.generic that describes 
-         which specific implementation needs to be used for api, manager and driver objects.
-         PlanetLab users do not need to change this setting.
-         </description>
-       </variable>
-
       </variablelist>
     </category>
 
index b937feb..9ed3c84 100755 (executable)
@@ -942,14 +942,18 @@ class Sfi:
         user_cred = self.get_user_cred().save_to_string(save_parents=True)
         server = self.slicemgr
         server = self.server_proxy_from_opts(opts)
+   
+        options = {'call_id': unique_call_id()}
+        #panos add info options
+        if opts.info:
+            options['info'] = opts.info
         
         if args:
             cred = self.get_slice_cred(args[0]).save_to_string(save_parents=True)
             hrn = args[0]
-           options = {'geni_slice_urn': hrn_to_urn(hrn, 'slice')}
+            options['geni_slice_urn'] = hrn_to_urn(hrn, 'slice')
         else:
             cred = user_cred
-            hrn = None
      
         creds = [cred]
         if opts.delegate:
@@ -965,14 +969,8 @@ class Sfi:
                 # this must be a protogeni aggregate. We should request a v2 ad rspec
                 # regardless of what the client user requested 
                 options['rspec_version'] = version_manager.get_version('ProtoGENI 2').to_dict()     
-        #panos add info options
-        if opts.info:
-            options['info'] = opts.info 
 
-        call_args = [creds]
-        if self.server_supports_options_arg(server):
-            options = {'call_id': unique_call_id()}
-            call_args.append(options)
+        call_args = [creds, options]
         result = server.ListResources(*call_args)
         if opts.file is None:
             display_rspec(result, opts.format)
index 7085037..26957c0 100644 (file)
@@ -8,8 +8,8 @@ from sfa.trust.auth import Auth
 from sfa.trust.certificate import Keypair, Certificate
 from sfa.trust.credential import Credential
 from sfa.trust.rights import determine_rights
-
 from sfa.server.xmlrpcapi import XmlrpcApi
+from sfa.util.genicode import GENICODE
 
 # thgen xxx fixme this is wrong all right, but temporary, will use generic
 from sfa.util.table import SfaTable
@@ -205,3 +205,48 @@ class SfaApi (XmlrpcApi):
             # cache version for 24 hours
             self.cache.add(cache_key, server_version, ttl= 60*60*24)
         return server_version
+
+
+    def get_geni_code(self, result):
+        code = {
+            'geni_code': GENICODE.SUCCESS, 
+            'am_type': 'sfa',
+            'am_code': None,
+        }
+        if isinstnace(result, SfaFault):
+            code['geni_code'] = result.faultCode
+            code['am_code'] = result.faultCode                        
+                
+        return code
+
+    def get_geni_value(self, result):
+        value = result
+        if isinstance(result, SfaFault):
+            value = ""
+        return value
+
+    def get_geni_output(self, result):
+        output = ""
+        if isinstance(result, SFaFault):
+            output = result.faultString 
+        return output
+
+    def prepare_response_v2_am(self, result):
+        response = {
+            'code': self.get_geni_code(result),
+            'value': self.get_geni_value(result),
+            'output': self.get_geni_output(result),
+        }
+        return response
+    
+    def prepare_response(self, result, method=""):
+        """
+        Converts the specified result into a standard GENI compliant 
+        response  
+        """
+        if self.interface.lower() == 'aggregate': 
+            if hasattr(self.config, 'SFA_AM_API_VERSION') and \
+              self.config.SFA_AM_API_VERSION == "2":
+                result = self.prepare_response_v2_am(result)
+        return XmlrpcApi.prepare_response(result, method)
+
index b6b3353..855d440 100644 (file)
@@ -20,4 +20,3 @@ GENICODE = Enum(
     INPORGRESS=16,
     ALREADYEXISTS=17       
 )   
-