Changeset eeb0088


Ignore:
Timestamp:
Feb 13, 2010 9:56:23 AM (15 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
dac2316
Parents:
e02cd14
Message:

Beginnings of userconf

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/emulab_access.py

    re02cd14 reeb0088  
    22
    33import os,sys
     4import stat # for chmod constants
    45import re
    56import string
     
    78import pickle
    89import logging
     10import subprocess
    911
    1012from threading import *
     
    6769        self.eventserver = config.get("access", "eventserver")
    6870        self.certdir = config.get("access","certdir")
     71        self.userconfdir = config.get("access","userconfdir")
     72        self.userconfcmd = config.get("access","userconfcmd")
    6973        self.ssh_privkey_file = config.get("access","ssh_privkey_file")
    7074        self.ssh_pubkey_file = config.get("access","ssh_pubkey_file")
     
    101105        self.state_lock = Lock()
    102106        # XXX: Configurable
    103         self.exports = set(('SMB', 'seer', 'tmcd'))
     107        self.exports = set(('SMB', 'seer', 'tmcd', 'userconfig'))
    104108        self.imports = set(('SMB', 'seer', 'tmcd'))
    105109
     
    321325                for o in self.allocation[k].get('owners', []):
    322326                    self.auth.set_attribute(o, fedid(hexstr=k))
     327                if self.allocation[k].has_key('userconfig'):
     328                    sfid = hexstr=self.allocation[k]['userconfig']
     329                    fid = fedid(hexstr=sfid)
     330                    self.auth.set_attribute(fid, sfid)
    323331
    324332
     
    488496                owners
    489497
     498    def get_handler(self, path, fid):
     499        self.log.info("Get handler %s %s" % (path, fid))
     500        if self.auth.check_attribute(fid, path) and self.userconfdir:
     501            return ("%s/%s" % (self.userconfdir, path), "application/binary")
     502        else:
     503            return (None, None)
     504
     505    def export_userconf(self, project):
     506        dev_null = None
     507        confid, confcert = generate_fedid("test", dir=self.userconfdir,
     508                log=self.log)
     509        conffilename = "%s/%s" % (self.userconfdir, str(confid))
     510        cf = None
     511        try:
     512            cf = open(conffilename, "w")
     513            os.chmod(conffilename, stat.S_IRUSR | stat.S_IWUSR)
     514        except IOError, e:
     515            raise service_error(service_error.internal,
     516                    "Cannot create user configuration data")
     517
     518        try:
     519            dev_null = open("/dev/null", "a")
     520        except IOError, e:
     521            self.log.error("export_userconf: can't open /dev/null: %s" % e)
     522
     523        cmd = "%s %s" % (self.userconfcmd, project)
     524        conf = subprocess.call(cmd.split(" "),
     525                stdout=cf, stderr=dev_null, close_fds=True)
     526
     527        self.auth.set_attribute(confid, str(confid))
     528
     529        return confid, confcert
     530
     531
    490532    def export_services(self, sreq, project, user):
    491533        exp = [ ]
    492         # XXX: Filthy shortcut here using http so urlparse will give the right
     534        state = { }
     535        # XXX: Filthy shortcut here using http: so urlparse will give the right
    493536        # answers.
    494537        for s in sreq:
     
    510553                    elif sname == 'tmcd':
    511554                        outs['server'] = "http://boss:7777"
     555                    elif sname == 'userconfig':
     556                        if self.userconfdir and self.userconfcmd:
     557                            cid, cert = self.export_userconf(project)
     558                            outs['server'] = "%s/%s" %(self.testbed, str(cid))
     559                            outs['fedAttr'] = [
     560                                    { 'attribute': 'cert', 'value': cert },
     561                                ]
     562                            state['userconfig'] = unicode(cid)
    512563                    exp.append(outs)
    513         return exp
     564        return (exp, state)
    514565
    515566    def build_response(self, alloc_id, ap, services):
     
    708759
    709760            self.allocation[aid]['owners'] = owners
     761            services, svc_state = self.export_services(req.get('service',[]),
     762                    pname, uname)
     763            # Store services state in global state
     764            for k, v in svc_state.items():
     765                self.allocation[aid][k] = v
    710766            self.write_state()
    711767            self.state_lock.release()
     
    719775                raise service_error(service_error.internal,
    720776                        "Can't open %s/%s : %s" % (self.certdir, aid, e))
    721             services = self.export_services(req.get('service',[]), pname, uname)
    722777            resp = self.build_response({ 'fedid': allocID } , ap, services)
    723778            return resp
Note: See TracChangeset for help on using the changeset viewer.