Changeset 208797c for fedd


Ignore:
Timestamp:
Aug 25, 2010 9:35:02 AM (14 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
64e774d
Parents:
88dbe63
Message:

Split out the protogeni and GANIAPI proxies into separate files. Support
GENIAPI

Location:
fedd/federation
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/protogeni_access.py

    r88dbe63 r208797c  
    1515
    1616from threading import Thread, Timer, Lock
    17 from M2Crypto.SSL import SSLError
    1817
    1918from util import *
     
    2928
    3029from access import access_base
    31 from proxy_segment import proxy_segment
     30from protogeni_proxy import protogeni_proxy
     31from geniapi_proxy import geniapi_proxy
    3232
    3333import topdl
     
    4141fl = logging.getLogger("fedd.access")
    4242fl.addHandler(nullHandler())
    43 
    44 class protogeni_proxy(proxy_segment):
    45     class ProtoGENIError(Exception):
    46         def __init__(self, op, code, output):
    47             Exception.__init__(self, output)
    48             self.op = op
    49             self.code = code
    50             self.output = output
    51 
    52     def __init__(self, log=None, keyfile=None, debug=False,
    53             ch_url=None, sa_url=None, cm_url=None):
    54         proxy_segment.__init__(self, log=log, keyfile=keyfile, debug=debug)
    55 
    56         self.ProtoGENIError = protogeni_proxy.ProtoGENIError
    57         self.ch_url = ch_url
    58         self.sa_url = sa_url
    59         self.cm_url = cm_url
    60 
    61         self.call_SetValue = service_caller('SetValue')
    62 
    63         self.debug_fail = ['Resolve']
    64         self.debug_response = {
    65                 'RedeemTicket': ("XML blob1", "XML blob2"),
    66                 'SliceStatus': { 'status': 'ready' },
    67             }
    68 
    69 
    70     def pg_call(self, url, method, params, context):
    71         max_retries = 5
    72         retries = 0
    73 
    74         s = service_caller(method, request_body_name="", strict=False)
    75         self.log.debug("Calling %s %s" % (url, method))
    76         if not self.debug:
    77             while retries < max_retries:
    78                 r = s.call_xmlrpc_service(url, params, context=context)
    79                 code = r.get('code', -1)
    80                 if code == 0:
    81                     # Success leaves the loop here
    82                     return r.get('value', None)
    83                 elif code == 14 and retries +1 < max_retries:
    84                     # Busy resource
    85                     retries+= 1
    86                     self.log.info("Resource busy, retrying in 30 secs")
    87                     time.sleep(30)
    88                 else:
    89                     # NB: out of retries falls through to here
    90                     raise self.ProtoGENIError(op=method,
    91                             code=r.get('code', 'unknown'),
    92                             output=r.get('output', 'No output'))
    93         else:
    94             if method in self.debug_fail:
    95                 raise self.ProtoGENIError(op=method, code='unknown',
    96                         output='No output')
    97             elif self.debug_response.has_key(method):
    98                 return self.debug_response[method]
    99             else:
    100                 return "%s XML blob" % method
    101 
    102     def clearinghouse_call(self, method, params, context):
    103         return self.pg_call(self.ch_url, method, params, context)
    104 
    105     def slice_authority_call(self, method, params, context):
    106         return self.pg_call(self.sa_url, method, params, context)
    107 
    108     def component_manager_call(self, method, params, context):
    109         return self.pg_call(self.cm_url, method, params, context)
    110 
    111 
    112 
    113 
    11443
    11544class access(access_base):
     
    198127
    199128        self.lookup_access = self.lookup_access_base
     129
     130        api = config.get("access", "api") or "protogeni"
     131        if api == "protogeni":
     132            self.api_proxy = protogeni_proxy
     133        elif api == "geniapi":
     134            self.api_proxy = geniapi_proxy
     135        else:
     136            self.log.debug("Unknown interface, using protogeni")
     137            self.api_proxy = protogeni_proxy
    200138
    201139        self.call_SetValue = service_caller('SetValue')
     
    978916                    'slice_urn': slice_urn,
    979917                    }
    980             sliver_cred, manifest = segment_commands.component_manager_call(
     918            rv = segment_commands.component_manager_call(
    981919                    'CreateSliver', param, ctxt)
     920
     921            # the GENIAPI AM just hands back the manifest, bit the ProtoGENI
     922            # API hands back a sliver credential.  This just finds the format
     923            # of choice.
     924            if isinstance(rv, tuple):
     925                manifest = rv[1]
     926            else:
     927                manifest = rv
    982928        except segment_commands.ProtoGENIError, e:
    983929            raise service_error(service_error.federant,
     
    1004950                r = segment_commands.component_manager_call(
    1005951                        'SliverStatus', param, ctxt)
    1006                 status = r.get('status', 'changing')
     952                # GENIAPI uses geni_status as the key, so check for both
     953                status = r.get('status', r.get('geni_status','changing'))
    1007954                if status not in completed_states:
    1008955                    if timeout is not None and time.time() > end:
     
    13421289                    % (self.staging_dir, ename), connInfo)
    13431290
    1344             segment_commands = protogeni_proxy(keyfile=ssh_key,
     1291            segment_commands = self.api_proxy(keyfile=ssh_key,
    13451292                    debug=self.create_debug, log=alloc_log,
    13461293                    ch_url = self.ch_url, sa_url=self.sa_url,
     
    14231370            staging = None
    14241371
    1425         segment_commands = protogeni_proxy(keyfile=ssh_key,
     1372        segment_commands = self.api_proxy(keyfile=ssh_key,
    14261373                debug=self.create_debug, ch_url = self.ch_url,
    14271374                sa_url=self.sa_url, cm_url=self.cm_url)
     
    15091456            # There's a ProtoGENI slice associated with the segment; renew it.
    15101457            if name and scred and slice_urn:
    1511                 segment_commands = protogeni_proxy(log=self.log,
     1458                segment_commands = self.api_proxy(log=self.log,
    15121459                        debug=self.create_debug, keyfile=ssh_key,
    15131460                        cm_url = self.cm_url, sa_url = self.sa_url,
Note: See TracChangeset for help on using the changeset viewer.