From 99374374f38fb62e54a6c284eec6b06c1c53dff7 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Tue, 22 Nov 2011 14:57:08 -0500 Subject: [PATCH] support geni am api v2 return values --- config/default_config.xml | 24 ++++++++++++-------- sfa/client/sfi.py | 16 ++++++------- sfa/server/sfaapi.py | 47 ++++++++++++++++++++++++++++++++++++++- sfa/util/genicode.py | 1 - 4 files changed, 68 insertions(+), 20 deletions(-) diff --git a/config/default_config.xml b/config/default_config.xml index e633a60b..6d052fc9 100644 --- a/config/default_config.xml +++ b/config/default_config.xml @@ -18,12 +18,27 @@ Thierry Parmentelat Basic system variables. + + Generic Flavour + pl + 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. + + + Human readable name plc The human readable name for this interface. + + Aggregate Manager API Version + 1 + The Aggregate API version + + Credential Schema /etc/sfa/credential.xsd @@ -53,15 +68,6 @@ Thierry Parmentelat - - Generic Flavour - pl - 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. - - - diff --git a/sfa/client/sfi.py b/sfa/client/sfi.py index b937febb..9ed3c848 100755 --- a/sfa/client/sfi.py +++ b/sfa/client/sfi.py @@ -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) diff --git a/sfa/server/sfaapi.py b/sfa/server/sfaapi.py index 70850379..26957c00 100644 --- a/sfa/server/sfaapi.py +++ b/sfa/server/sfaapi.py @@ -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) + diff --git a/sfa/util/genicode.py b/sfa/util/genicode.py index b6b3353f..855d440a 100644 --- a/sfa/util/genicode.py +++ b/sfa/util/genicode.py @@ -20,4 +20,3 @@ GENICODE = Enum( INPORGRESS=16, ALREADYEXISTS=17 ) - -- 2.43.0