Ignore:
Timestamp:
Aug 1, 2008 11:41:39 AM (16 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-1.30, version-2.00, version-3.01, version-3.02
Children:
808889e
Parents:
7da9da6
Message:

split out project creation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/fedd_allocate_project.py

    r7da9da6 ref36c1e  
    2121from fedd_util import *
    2222import parse_detail
     23from service_error import *
    2324
    2425class fedd_allocate_project_local:
    25     def __init__(self, dp=False, url=None):
     26    def __init__(self, dp=False, url=None, certs=None):
    2627        """
    2728        Initializer.  Parses a configuration if one is given.
     
    5859
    5960
    60     def dynamic_project(self, req):
     61    def dynamic_project(self, req, fedid=None):
    6162        """
    6263        Create a dynamic project with ssh access
     
    7071                dir="/tmp")
    7172
    72         print userfile
    73         proj = req['project']
     73        if req.has_key('AllocateProjectRequestBody') and \
     74                req['AllocateProjectRequestBody'].has_key('project'):
     75            proj = req['AllocateProjectRequestBody']['project']
     76        else:
     77            raise service_error(service_error.req,
     78                    "Badly formed allocation request")
    7479        # Take the first user and ssh key
    7580        name = proj.get('name', None) or self.random_string("proj",4)
     
    9196            access = user.get('access', None)
    9297            if access != None:
    93                 ssh = access.get('sshPubkey', None)
     98                ssh = access[0].get('sshPubkey', None)
    9499                if ssh == None:
    95100                    raise fedd_proj.service_error(fedd_proj.service_error.req,
     
    177182        }
    178183        return rv
     184
     185
     186class fedd_allocate_project_remote:
     187    def __init__(self, dp=False, url=None, certs=None):
     188        """
     189        Initializer.  Parses a configuration if one is given.
     190        """
     191
     192        self.dynamic_projects = dp
     193        self.url = url
     194
     195        if certs != None and isinstance(certs, type(tuple())):
     196            self.cert_file, self.trusted_certs, self.cert_pwd = certs
     197            # self.cert_file = certs[0]
     198            # self.trusted_certs = certs[1]
     199            # self.cert_pwd = certs[2]
     200        else:
     201            self.cert_file = None
     202            self.trusted_certs = None
     203            self.cert_pwd = None
     204
     205    def dynamic_project(self, req, fedid=None):
     206        """
     207        Send req on to a remote project instantiator.
     208
     209        Req is just the projectAllocType object.  This function re-wraps it.
     210        It also rethrows any faults.
     211        """
     212        # No retry loop here.  Proxy servers must correctly authenticate
     213        # themselves without help
     214        try:
     215            ctx = fedd_ssl_context(self.cert_file, self.trusted_certs,
     216                    password=self.cert_pwd)
     217        except SSL.SSLError:
     218            raise service_error(service_error.server_config,
     219                    "Server certificates misconfigured")
     220
     221        loc = feddServiceLocator();
     222        port = loc.getfeddPortType(self.url,
     223                transport=M2Crypto.httpslib.HTTPSConnection,
     224                transdict={ 'ssl_context' : ctx })
     225
     226        if req.has_key('AllocateProjectRequestBody'):
     227            req = req['AllocateProjectRequestBody']
     228        else:
     229            raise service_error(service_error.req, "Bad formated request");
     230
     231        # Reconstruct the full request message
     232        msg = AllocateProjectRequestMessage()
     233        msg.set_element_AllocateProjectRequestBody(
     234                pack_soap(msg, "AllocateProjectRequestBody", req))
     235        try:
     236            resp = port.AllocateProject(msg)
     237        except ZSI.ParseException, e:
     238            raise service_error(service_error.proxy,
     239                    "Bad format message (XMLRPC??): %s" % str(e))
     240        r = unpack_soap(resp)
     241
     242        if r.has_key('AllocateProjectResponseBody'):
     243            return r['AllocateProjectResponseBody']
     244        else:
     245            raise service_error(service_error.proxy, "Bad proxy response")
     246
Note: See TracChangeset for help on using the changeset viewer.