source: fedd/Makefile/federation/protogeni_proxy.py @ 88e7f2f

version-3.01version-3.02
Last change on this file since 88e7f2f was 88e7f2f, checked in by Ted Faber <faber@…>, 14 years ago

version bump

  • Property mode set to 100644
File size: 2.3 KB
Line 
1#!/usr/local/bin/python
2
3import os,sys
4import logging
5
6from service_error import service_error
7from remote_service import xmlrpc_handler, soap_handler, service_caller
8
9from proxy_segment import proxy_segment
10
11
12class protogeni_proxy(proxy_segment):
13    class ProtoGENIError(Exception): 
14        def __init__(self, op, code, output):
15            Exception.__init__(self, output)
16            self.op = op
17            self.code = code
18            self.output = output
19
20    def __init__(self, log=None, keyfile=None, debug=False, 
21            ch_url=None, sa_url=None, cm_url=None):
22        proxy_segment.__init__(self, log=log, keyfile=keyfile, debug=debug)
23
24        self.ProtoGENIError = protogeni_proxy.ProtoGENIError
25        self.ch_url = ch_url
26        self.sa_url = sa_url
27        self.cm_url = cm_url
28
29        self.call_SetValue = service_caller('SetValue')
30
31        self.debug_fail = ['Resolve']
32        self.debug_response = {
33                'RedeemTicket': ("XML blob1", "XML blob2"),
34                'SliceStatus': { 'status': 'ready' },
35            }
36
37
38    def pg_call(self, url, method, params, context):
39        max_retries = 5
40        retries = 0
41
42        s = service_caller(method, request_body_name="", strict=False)
43        if self.log:
44            self.log.debug("Calling %s %s" % (url, method))
45        if not self.debug:
46            while retries < max_retries:
47                r = s.call_xmlrpc_service(url, params, context=context)
48                code = r.get('code', -1)
49                if code == 0:
50                    # Success leaves the loop here
51                    return r.get('value', None)
52                elif code == 14 and retries +1 < max_retries:
53                    # Busy resource
54                    retries+= 1
55                    self.log.info("Resource busy, retrying in 30 secs")
56                    time.sleep(30)
57                else:
58                    # NB: out of retries falls through to here
59                    raise self.ProtoGENIError(op=method, 
60                            code=r.get('code', 'unknown'), 
61                            output=r.get('output', 'No output'))
62        else:
63            if method in self.debug_fail:
64                raise self.ProtoGENIError(op=method, code='unknown',
65                        output='No output')
66            elif self.debug_response.has_key(method):
67                return self.debug_response[method]
68            else:
69                return "%s XML blob" % method
70
71    def clearinghouse_call(self, method, params, context):
72        return self.pg_call(self.ch_url, method, params, context)
73
74    def slice_authority_call(self, method, params, context):
75        return self.pg_call(self.sa_url, method, params, context)
76
77    def component_manager_call(self, method, params, context):
78        return self.pg_call(self.cm_url, method, params, context)
79
Note: See TracBrowser for help on using the repository browser.