Changeset 623a2c9


Ignore:
Timestamp:
May 28, 2010 10:11:49 AM (14 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
3551ae1
Parents:
a20a20f
Message:

Moving stuff around

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/access.py

    ra20a20f r623a2c9  
    6868        self.state_lock = Lock()
    6969        self.state = { }
     70        # subclasses fill with what and how they export.
     71        self.exports = { }
    7072        # XXX: Configurable
    71         self.exports = set(('SMB', 'seer', 'tmcd', 'userconfig',
    72             'project_export', 'local_seer_control', 'seer_master',
    73             'hide_hosts'))
    7473        self.imports = set(('SMB', 'seer', 'userconfig', 'seer_master',
    7574            'hide_hosts'))
     
    361360
    362361    def export_SMB(self, id, state, project, user, attrs):
    363         return {
    364                 'id': id,
    365                 'name': 'SMB',
    366                 'visibility': 'export',
    367                 'server': 'http://fs:139',
    368                 'fedAttr': [
    369                         { 'attribute': 'SMBSHARE', 'value': 'USERS' },
    370                         { 'attribute': 'SMBUSER', 'value': user },
    371                         { 'attribute': 'SMBPROJ', 'value': project },
    372                     ]
    373                 }
     362        if project and user:
     363            return [{
     364                    'id': id,
     365                    'name': 'SMB',
     366                    'visibility': 'export',
     367                    'server': 'http://fs:139',
     368                    'fedAttr': [
     369                            { 'attribute': 'SMBSHARE', 'value': 'USERS' },
     370                            { 'attribute': 'SMBUSER', 'value': user },
     371                            { 'attribute': 'SMBPROJ', 'value': project },
     372                        ]
     373                    }]
     374        else:
     375            self.log.warn("Cannot export SMB w/o user and project")
     376            return [ ]
    374377
    375378    def export_seer(self, id, state, project, user, attrs):
    376         return {
     379        return [{
    377380                'id': id,
    378381                'name': 'seer',
    379382                'visibility': 'export',
    380383                'server': 'http://control:16606',
    381                 }
     384                }]
    382385
    383386    def export_local_seer(self, id, state, project, user, attrs):
    384         return {
     387        return [{
    385388                'id': id,
    386389                'name': 'local_seer_control',
    387390                'visibility': 'export',
    388391                'server': 'http://control:16606',
    389                 }
     392                }]
    390393
    391394    def export_seer_master(self, id, state, project, user, attrs):
    392         return {
     395        return [{
    393396                'id': id,
    394397                'name': 'seer_master',
    395398                'visibility': 'export',
    396399                'server': 'http://seer-master:17707',
    397                 }
     400                }]
    398401
    399402    def export_tmcd(self, id, state, project, user, attrs):
    400         return {
     403        return [{
    401404                'id': id,
    402405                'name': 'seer',
    403406                'visibility': 'export',
    404407                'server': 'http://boss:7777',
    405                 }
     408                }]
    406409
    407410    def export_userconfig(self, id, state, project, user, attrs):
     
    410413            cid, cert = self.export_userconf(project)
    411414            state['userconfig'] = unicode(cid)
    412             return {
     415            return [{
    413416                    'id': id,
    414417                    'name': 'userconfig',
     
    418421                        { 'attribute': 'cert', 'value': cert },
    419422                    ]
    420                     }
     423                    }]
    421424        else:
    422             return None
     425            return [ ]
    423426
    424427    def export_hide_hosts(self, id, state, project, user, attrs):
    425         return {
     428        return [{
    426429                'id': id,
    427430                'name': 'hide_hosts',
     
    429432                'fedAttr': [ x for x in attrs \
    430433                        if x.get('attribute', "") == 'hosts'],
    431                 }
    432 
    433     def export_services(self, sreq, project, user):
     434                }]
     435
     436    def export_project_export(self, id, state, project, user, attrs):
     437        rv = [ ]
     438        rv.extend(self.export_SMB(id, state, project, user, attrs))
     439        rv.extend(self.export_userconfig(id, state, project, user, attrs))
     440        return rv
     441
     442    def export_services(self, sreq, project=None, user=None):
    434443        exp = [ ]
    435444        state = { }
    436         # XXX: Filthy shortcut here using http: so urlparse will give the right
    437         # answers.
    438445        for s in sreq:
    439446            sname = s.get('name', '')
     
    443450                if sname in self.exports:
    444451                    id = s.get('id', 'no_id')
    445                     if sname == 'SMB':
    446                         exp.append(self.export_SMB(id, state, project, user,
     452                    exp.extend(self.exports[sname](id, state, project, user,
    447453                            sattrs))
    448                     elif sname == 'seer':
    449                         exp.append(self.export_seer(id, state, project, user,
    450                             sattrs))
    451                     elif sname == 'tmcd':
    452                         exp.append(self.export_tmcd(id, state, project, user,
    453                             sattrs))
    454                     elif sname == 'userconfig':
    455                         exp.append(self.export_userconfig(id, state,
    456                             project, user, sattrs))
    457                     elif sname == 'project_export':
    458                         exp.append(self.export_SMB(id, state, project, user,
    459                             sattrs))
    460                         #exp.append(self.export_seer(id, state, project, user,
    461                         #sattrs))
    462                         exp.append(self.export_userconfig(id, state,
    463                             project, user, sattrs))
    464                     elif sname == 'local_seer_control':
    465                         exp.append(self.export_local_seer(id, state, project,
    466                             user, sattrs))
    467                     elif sname == 'seer_master':
    468                         exp.append(self.export_seer_master(id, state, project,
    469                             user, sattrs))
    470                     elif sname == 'hide_hosts':
    471                         exp.append(self.export_hide_hosts(id, state, project,
    472                             user, sattrs))
     454
    473455        return (exp, state)
    474456
     
    497479                'value': self.dragon_endpoint})
    498480        if self.deter_internal:
    499             print 'adding internal'
    500481            msg['fedAttr'].append({'attribute': 'deter_internal',
    501482                'value': self.deter_internal})
    502         else: print "internal: %s" % self.deter_internal
    503483        #XXX: ??
    504484        if self.dragon_vlans:
     
    689669            raise service_error(service_error.internal,
    690670                    "Cannot write client.conf: %s" %s)
     671
     672    def configure_userconf(self, services, tmpdir):
     673        """
     674        If the userconf service was imported, collect the configuration data.
     675        """
     676        for s in services:
     677            s_name = s.get('name', '')
     678            s_vis = s.get('visibility','')
     679            if s_name  == 'userconfig' and s_vis == 'import':
     680                # Collect ther server and certificate info.
     681                u = s.get('server', None)
     682                for a in s.get('fedAttr', []):
     683                    if a.get('attribute',"") == 'cert':
     684                        cert = a.get('value', None)
     685                        break
     686                else:
     687                    cert = None
     688
     689                if cert:
     690                    # Make a temporary certificate file for get_url.  The
     691                    # finally clause removes it whether something goes
     692                    # wrong (including an exception from get_url) or not.
     693                    try:
     694                        tfos, tn = tempfile.mkstemp(suffix=".pem")
     695                        tf = os.fdopen(tfos, 'w')
     696                        print >>tf, cert
     697                        tf.close()
     698                        self.log.debug("Getting userconf info: %s" % u)
     699                        get_url(u, tn, tmpdir, "userconf")
     700                        self.log.debug("Got userconf info: %s" % u)
     701                    except EnvironmentError, e:
     702                        raise service_error(service.error.internal,
     703                                "Cannot create temp file for " +
     704                                "userconfig certificates: %s" % e)
     705                    except:
     706                        t, v, st = sys.exc_info()
     707                        raise service_error(service_error.internal,
     708                                "Error retrieving %s: %s" % (u, v))
     709                    finally:
     710                        if tn: os.remove(tn)
     711                else:
     712                    raise service_error(service_error.req,
     713                            "No certificate for retreiving userconfig")
     714                break
    691715
    692716    def import_store_info(self, cf, connInfo):
     
    737761                    raise service_error(service_error.internal,
    738762                        'Bad Services missing info for import %s' % c)
     763
     764    def remove_dirs(self, dir):
     765        """
     766        Remove the directory tree and all files rooted at dir.  Log any errors,
     767        but continue.
     768        """
     769        self.log.debug("[removedirs]: removing %s" % dir)
     770        try:
     771            for path, dirs, files in os.walk(dir, topdown=False):
     772                for f in files:
     773                    os.remove(os.path.join(path, f))
     774                for d in dirs:
     775                    os.rmdir(os.path.join(path, d))
     776            os.rmdir(dir)
     777        except EnvironmentError, e:
     778            self.log.error("Error deleting directory tree in %s" % e);
Note: See TracChangeset for help on using the changeset viewer.