Ignore:
Timestamp:
Feb 12, 2010 11:30:56 AM (14 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
eeb0088
Parents:
8139a48
Message:

Big hunk of the move to services and connectivity descriptors.

Config files are now generated from those params rather than from attributes on topdl nodes (mostly).

This is still quick and dirty in places.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/emulab_access.py

    r8139a48 re02cd14  
    100100        set_log_level(config, "access", self.log)
    101101        self.state_lock = Lock()
     102        # XXX: Configurable
     103        self.exports = set(('SMB', 'seer', 'tmcd'))
     104        self.imports = set(('SMB', 'seer', 'tmcd'))
    102105
    103106        if auth: self.auth = auth
     
    485488                owners
    486489
    487     def build_response(self, alloc_id, ap):
     490    def export_services(self, sreq, project, user):
     491        exp = [ ]
     492        # XXX: Filthy shortcut here using http so urlparse will give the right
     493        # answers.
     494        for s in sreq:
     495            sname = s.get('name', '')
     496            svis = s.get('visibility', '')
     497            if svis == 'export':
     498                if sname in self.exports:
     499                    outs = s.copy()
     500                    if sname == 'SMB':
     501                        outs = s.copy()
     502                        outs['server'] = "http://fs:139"
     503                        outs['fedAttr'] = [
     504                                { 'attribute': 'SMBSHARE', 'value': 'USERS' },
     505                                { 'attribute': 'SMBUSER', 'value': user },
     506                                { 'attribute': 'SMBPROJ', 'value': project },
     507                            ]
     508                    elif sname == 'seer':
     509                        outs['server'] = "http://control:16606"
     510                    elif sname == 'tmcd':
     511                        outs['server'] = "http://boss:7777"
     512                    exp.append(outs)
     513        return exp
     514
     515    def build_response(self, alloc_id, ap, services):
    488516        """
    489517        Create the SOAP response.
     
    508536                [ { 'attribute': x, 'value' : y } \
    509537                        for x,y in self.attrs.iteritems()])
     538
     539        if services:
     540            msg['service'] = services
    510541        return msg
    511542
     
    676707                        "Misformed allocation response?")
    677708
    678 
    679709            self.allocation[aid]['owners'] = owners
    680710            self.write_state()
     
    689719                raise service_error(service_error.internal,
    690720                        "Can't open %s/%s : %s" % (self.certdir, aid, e))
    691             resp = self.build_response({ 'fedid': allocID } , ap)
     721            services = self.export_services(req.get('service',[]), pname, uname)
     722            resp = self.build_response({ 'fedid': allocID } , ap, services)
    692723            return resp
    693724        else:
     
    819850
    820851    def generate_portal_configs(self, topo, pubkey_base, secretkey_base,
    821             tmpdir, master):
     852            tmpdir, master, lproj, leid, connInfo, services):
     853
     854        def conninfo_to_dict(key, info):
     855            """
     856            Make a cpoy of the connection information about key, and flatten it
     857            into a single dict by parsing out any feddAttrs.
     858            """
     859
     860            rv = None
     861            for i in info:
     862                if i.get('portal', "") == key:
     863                    rv = i.copy()
     864                    break
     865            else:
     866                return rv
     867
     868            if 'fedAttr' in rv:
     869                for a in rv['fedAttr']:
     870                    attr = a.get('attribute', "")
     871                    val = a.get('value', "")
     872                    if attr and attr not in rv:
     873                        rv[attr] = val
     874                del rv['fedAttr']
     875            return rv
     876
     877        # XXX: un hardcode this
     878        def client_null(f, s): pass
     879
     880        def client_smb(f, s):
     881            smbshare = None
     882            smbuser = None
     883            smbproj = None
     884            for a in s.get('fedAttr', []):
     885                if a.get('attribute', '') == 'SMBSHARE':
     886                    smbshare = a.get('value', None)
     887                elif a.get('attribute', '') == 'SMBUSER':
     888                    smbuser = a.get('value', None)
     889                elif a.get('attribute', '') == 'SMBPROJ':
     890                    smbproj = a.get('value', None)
     891
     892            if all((smbshare, smbuser, smbproj)):
     893                print >>f, "SMBshare: %s" % smbshare
     894                print >>f, "ProjectUser: %s" % smbuser
     895                print >>f, "ProjectName: %s" % smbproj
     896
     897        client_service_out = {
     898                'SMB': client_smb,
     899                'tmcd': client_null,
     900                'seer': client_null,
     901                'userconfig': client_null,
     902            }
     903        # XXX: end un hardcode this
     904
    822905
    823906        seer_out = False
     
    826909                if isinstance(e, topdl.Computer) and e.get_attribute('portal')]:
    827910            myname = e.name[0]
    828             peer = e.get_attribute('peer')
    829             lexp = e.get_attribute('experiment')
    830             lproj, leid = lexp.split('/', 1)
    831             ldomain = e.get_attribute('domain')
    832             mexp = e.get_attribute('masterexperiment')
     911            type = e.get_attribute('portal_type')
     912
     913            info = conninfo_to_dict(myname, connInfo)
     914
     915            if not info:
     916                raise service_error(service_error.req,
     917                        "No connectivity info for %s" % myname)
     918
     919            peer = info.get('peer', "")
     920            ldomain = self.domain;
     921
     922            mexp = info.get('masterexperiment',"")
    833923            mproj, meid = mexp.split("/", 1)
    834             mdomain = e.get_attribute('masterdomain')
    835             muser = e.get_attribute('masteruser') or 'root'
    836             smbshare = e.get_attribute('smbshare') or 'USERS'
    837             scriptdir = e.get_attribute('scriptdir')
    838             active = e.get_attribute('active')
    839             type = e.get_attribute('portal_type')
    840             segid = fedid(hexstr=e.get_attribute('peer_segment'))
    841             for e in topo.elements:
    842                 if isinstance(e, topdl.Segment) and e.id.fedid == segid:
    843                     seg = e
    844                     break
    845             else:
    846                 raise service_error(service_error.req,
    847                         "Can't find segment for portal %s" % myname)
    848 
    849             is_ip = re.match('\d+\.\d+\.\d+\.\d+', peer)
    850 
    851             rexp = seg.get_attribute('experiment')
    852             rproj, reid = rexp.split("/", 1)
    853             rdomain = seg.get_attribute('domain')
     924            mdomain = info.get('masterdomain',"")
     925            muser = info.get('masteruser','root')
     926            smbshare = info.get('smbshare', 'USERS')
     927
     928            active = info.get('active', 'False')
     929
     930
    854931            cfn = "%s/%s.gw.conf" % (tmpdir, myname.lower())
    855932            tunnelconfig = self.attrs.has_key('TunnelCfg')
     
    857934                f = open(cfn, "w")
    858935                if active == 'True':
    859                     print >>f, "active: %s" % active
    860936                    if type in ('control', 'both'):
    861                         print >>f, 'port: remote:139:fs:139'
    862                         print >>f, 'port: remote:7777:boss:7777'
    863                         print >>f, 'port: remote:16606:control:16606'
     937                        for s in [s for s in services \
     938                                if s.get('name', "") in self.imports]:
     939                            p = urlparse(s.get('server', 'http://localhost'))
     940                            print >>f, 'port: remote:%s:%s:%s' % \
     941                                    (p.port, p.hostname, p.port)
    864942
    865943                if tunnelconfig:
    866944                    print >>f, "tunnelip: %s" % tunnelconfig
    867                 print >>f, "seercontrol: control.%s.%s%s" % \
    868                         (meid.lower(), mproj.lower(), mdomain)
    869                 if is_ip:
    870                     print >>f, "peer: %s" % peer
    871                 else:
    872                     print >>f, "peer: %s.%s.%s%s" % \
    873                             (peer.lower(), reid.lower(),
    874                                     rproj.lower(), rdomain)
     945                # XXX: send this an fedattr
     946                #print >>f, "seercontrol: control.%s.%s%s" % \
     947                        #(meid.lower(), mproj.lower(), mdomain)
     948                print >>f, "peer: %s" % peer.lower()
    875949                print >>f, "ssh_pubkey: /proj/%s/exp/%s/tmp/%s" % \
    876950                        (lproj, leid, pubkey_base)
     
    903977                        (myname.lower(), leid.lower(), lproj.lower(),
    904978                                ldomain.lower())
    905                     print >>f, "SMBshare: %s" % smbshare
    906                     print >>f, "ProjectUser: %s" % muser
    907                     print >>f, "ProjectName: %s" % mproj
    908                     print >>f, "ExperimentID: %s/%s" % (mproj, meid)
     979                    for s in services:
     980                        if s.get('name',"") in self.imports:
     981                            client_service_out[s['name']](f, s)
     982                    # Does seer need this?
     983                    # print >>f, "ExperimentID: %s/%s" % (mproj, meid)
    909984                    f.close()
    910985                except IOError, e:
     
    10511126            raise service_error(server_error.req, "Badly formed request")
    10521127
     1128        connInfo = req.get('connection', [])
     1129        services = req.get('service', [])
    10531130        auth_attr = req['allocID']['fedid']
    10541131        aid = "%s" % auth_attr
     
    10831160                os.mkdir(softdir)
    10841161            for s in sw:
    1085                 print "%s %s %s" % ( s, certfile, softdir)
     1162                self.log.debug("Retrieving %s" % s)
    10861163                get_url(s, certfile, softdir)
    10871164
     
    11311208
    11321209            self.generate_portal_configs(topo, pubkey_base,
    1133                     secretkey_base, tmpdir, master)
     1210                    secretkey_base, tmpdir, master, proj, ename, connInfo,
     1211                    services)
    11341212            self.generate_ns2(topo, expfile,
    11351213                    "/proj/%s/software/%s/" % (proj, ename), master)
     
    11401218        except service_error, e:
    11411219            err = e
     1220        except e:
     1221            err = service_error(service_error.internal, str(e))
    11421222
    11431223        # Walk up tmpdir, deleting as we go
Note: See TracChangeset for help on using the changeset viewer.